]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: services init fixes
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 7 Sep 2018 13:37:23 +0000 (06:37 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 8 Nov 2018 17:19:29 +0000 (09:19 -0800)
First load all depending services, then initialize all.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_rados.cc
src/rgw/rgw_service.cc
src/rgw/rgw_service.h
src/rgw/services/svc_zone.cc

index dfb5f9359c0747d4ef89779f979a28b322172703..451486b9efe6d7c455182dbbf50038764fca8ae4 100644 (file)
@@ -1708,7 +1708,7 @@ int RGWRados::initialize()
     cct->_conf.get_val<double>("rgw_inject_notify_timeout_probability");
   max_notify_retries = cct->_conf.get_val<uint64_t>("rgw_max_notify_retries");
 
-  svc_registry = std::make_unique<RGWServiceRegistry>(cct);
+  svc_registry = std::make_shared<RGWServiceRegistry>(cct);
 
   JSONFormattable zone_svc_conf;
   ret = svc_registry->get_instance("zone", zone_svc_conf, &_svc.zone);
@@ -1740,7 +1740,7 @@ int RGWRados::initialize()
 
   if (use_cache) {
     JSONFormattable cache_svc_conf;
-    ret = svc_registry->get_instance("sys_obj_cache", cache_svc_conf, &_svc.cache);
+    ret = svc_registry->get_instance("sysobj_cache", cache_svc_conf, &_svc.cache);
     if (ret < 0) {
       return ret;
     }
@@ -1754,7 +1754,7 @@ int RGWRados::initialize()
   if (!to_formattable(cct, f, &sysobj_svc_conf)) {
     assert(0);
   }
-  ret = svc_registry->get_instance("sys_obj", sysobj_svc_conf, &_svc.sysobj);
+  ret = svc_registry->get_instance("sysobj", sysobj_svc_conf, &_svc.sysobj);
   if (ret < 0) {
     return ret;
   }
index 393aa4534815a483afa0dd2ad8dbd577566f55fb..7a0260a8ebd9a23484b7d49a9f6870111316a5e9 100644 (file)
@@ -30,9 +30,9 @@ void RGWServiceRegistry::register_all(CephContext *cct)
   services["zone_utils"] = make_shared<RGWS_ZoneUtils>(cct);
   services["quota"] = make_shared<RGWS_Quota>(cct);
   services["sync_modules"] = make_shared<RGWS_SyncModules>(cct);
-  services["sys_obj"] = make_shared<RGWS_SysObj>(cct);
-  services["sys_obj_cache"] = make_shared<RGWS_SysObj_Cache>(cct);
-  services["sys_obj_core"] = make_shared<RGWS_SysObj_Core>(cct);
+  services["sysobj"] = make_shared<RGWS_SysObj>(cct);
+  services["sysobj_cache"] = make_shared<RGWS_SysObj_Cache>(cct);
+  services["sysobj_core"] = make_shared<RGWS_SysObj_Core>(cct);
 }
 
 bool RGWServiceRegistry::find(const string& name, RGWServiceRef *svc)
@@ -51,10 +51,11 @@ string RGWServiceRegistry::get_conf_id(const string& service_type, const string&
   return service_type + ":" + conf;
 }
 
-int RGWServiceRegistry::get_instance(RGWServiceRef& svc,
-                                     const string& conf,
-                                     RGWServiceInstanceRef *ref) {
-  auto self_ref = shared_from_this();
+int RGWServiceRegistry::do_get_instance(RGWServiceRef& svc,
+                                        const string& conf,
+                                        RGWServiceInstanceRef *ref,
+                                        vector<RGWServiceInstanceRef> *new_instances)
+{
   RGWServiceInstanceRef instance_ref;
 
   string conf_id = get_conf_id(svc->type(), conf);
@@ -66,6 +67,7 @@ int RGWServiceRegistry::get_instance(RGWServiceRef& svc,
   }
   int r = svc->create_instance(conf, &instance_ref);
   if (r < 0) {
+    ldout(cct, 0) << "ERROR: failed to create instance for service " << svc->type() << " conf=" << conf << " (r=" << r << ")" << dendl;
     return r;
   }
   instance_ref->svc = svc;
@@ -87,7 +89,7 @@ int RGWServiceRegistry::get_instance(RGWServiceRef& svc,
     auto& dep_id = iter.first;
     auto& dep = iter.second;
     RGWServiceInstanceRef dep_ref;
-    r = get_instance(dep.name, dep.conf, &dep_ref);
+    r = do_get_instance(dep.name, dep.conf, &dep_ref, new_instances);
     if (r < 0) {
       ldout(cct, 0) << "ERROR: cannot satisfy dependency for service " << svc->type() << ": " << dep.name << dendl;
       return r;
@@ -101,6 +103,8 @@ int RGWServiceRegistry::get_instance(RGWServiceRef& svc,
     return r;
   }
 
+  new_instances->push_back(instance_ref);
+
   if (instance_ref->svc_instance.empty()) {
     char buf[32];
     snprintf(buf, sizeof(buf), "%lld", (long long)instance_ref->svc_id);
@@ -109,12 +113,27 @@ int RGWServiceRegistry::get_instance(RGWServiceRef& svc,
 
   *ref = iinfo.ref;
 
-  r = instance_ref->init();
+  return 0;
+}
+
+int RGWServiceRegistry::get_instance(RGWServiceRef& svc,
+                                     const string& conf,
+                                     RGWServiceInstanceRef *ref)
+{
+  vector<RGWServiceInstanceRef> new_instances;
+
+  int r =  do_get_instance(svc, conf, ref, &new_instances);
   if (r < 0) {
-    ldout(cct, 0) << "ERROR: service instance init return error: service=" << svc->type() << " r=" << r << dendl;
-    return r;
+    ldout(cct, 0) << "ERROR: service instance load return error: service=" << svc->type() << " r=" << r << dendl;
   }
 
+  for (auto& instance_ref : new_instances) {
+    r = instance_ref->init();
+    if (r < 0) {
+      ldout(cct, 0) << "ERROR: service instance init return error: service=" << instance_ref->get_svc()->type() << " r=" << r << dendl;
+      return r;
+    }
+  }
   return 0;
 }
 
index 7149b47a34ce17b483167004708f645fedad344d..b9f70c7a7a4b434c4288a0f172f5c756d3533650 100644 (file)
@@ -75,9 +75,13 @@ public:
   string get_title() {
     return svc->type() + ":" + svc_instance;
   }
+
+  std::shared_ptr<RGWService>& get_svc() {
+    return svc;
+  }
 };
 
-class RGWServiceRegistry : std::enable_shared_from_this<RGWServiceRegistry> {
+class RGWServiceRegistry {
   CephContext *cct;
 
   map<string, RGWServiceRef> services;
@@ -96,6 +100,22 @@ class RGWServiceRegistry : std::enable_shared_from_this<RGWServiceRegistry> {
 
   string get_conf_id(const string& service_type, const string& conf);
   void register_all(CephContext *cct);
+
+  int do_get_instance(RGWServiceRef& svc,
+                      const string& conf,
+                      RGWServiceInstanceRef *ref,
+                      std::vector<RGWServiceInstanceRef> *new_instances);
+  template <class T>
+  int do_get_instance(const string& svc_name,
+                   const string& conf,
+                   T *ref,
+                   std::vector<RGWServiceInstanceRef> *new_instances) {
+    auto iter = services.find(svc_name);
+    if (iter == services.end()) {
+      return -ENOENT;
+    }
+    return do_get_instance(iter->second, conf, ref, new_instances);
+  }
 public:
   RGWServiceRegistry(CephContext *_cct) : cct(_cct) {
     register_all(cct);
index 4674181e68adc3888aa672bb180775b52c62cf5e..d5fc135aaa2a1a30c08c828937add995ef4aff3f 100644 (file)
@@ -22,9 +22,9 @@ int RGWS_Zone::create_instance(const string& conf, RGWServiceInstanceRef *instan
 std::map<string, RGWServiceInstance::dependency> RGWSI_Zone::get_deps()
 {
   map<string, RGWServiceInstance::dependency> deps;
-  deps["sys_obj_dep"] = { .name = "sys_obj",
+  deps["sysobj_dep"] = { .name = "sysobj",
                           .conf = "{}" };
-  deps["rados_dep"] = { .name = "rados_obj",
+  deps["rados_dep"] = { .name = "rados",
                         .conf = "{}" };
   deps["sync_modules_dep"] = { .name = "sync_modules",
                         .conf = "{}" };
@@ -33,7 +33,7 @@ std::map<string, RGWServiceInstance::dependency> RGWSI_Zone::get_deps()
 
 int RGWSI_Zone::load(const string& conf, std::map<std::string, RGWServiceInstanceRef>& dep_refs)
 {
-  sysobj_svc = static_pointer_cast<RGWSI_SysObj>(dep_refs["sys_obj_dep"]);
+  sysobj_svc = static_pointer_cast<RGWSI_SysObj>(dep_refs["sysobj_dep"]);
   assert(sysobj_svc);
 
   realm = make_shared<RGWRealm>();