From deccf50cd483aea9e0e4c7b3834c0c512bea0b73 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 7 Sep 2018 06:37:23 -0700 Subject: [PATCH] rgw: services init fixes First load all depending services, then initialize all. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_rados.cc | 6 +++--- src/rgw/rgw_service.cc | 41 ++++++++++++++++++++++++++---------- src/rgw/rgw_service.h | 22 ++++++++++++++++++- src/rgw/services/svc_zone.cc | 6 +++--- 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index dfb5f9359c074..451486b9efe6d 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1708,7 +1708,7 @@ int RGWRados::initialize() cct->_conf.get_val("rgw_inject_notify_timeout_probability"); max_notify_retries = cct->_conf.get_val("rgw_max_notify_retries"); - svc_registry = std::make_unique(cct); + svc_registry = std::make_shared(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; } diff --git a/src/rgw/rgw_service.cc b/src/rgw/rgw_service.cc index 393aa4534815a..7a0260a8ebd9a 100644 --- a/src/rgw/rgw_service.cc +++ b/src/rgw/rgw_service.cc @@ -30,9 +30,9 @@ void RGWServiceRegistry::register_all(CephContext *cct) services["zone_utils"] = make_shared(cct); services["quota"] = make_shared(cct); services["sync_modules"] = make_shared(cct); - services["sys_obj"] = make_shared(cct); - services["sys_obj_cache"] = make_shared(cct); - services["sys_obj_core"] = make_shared(cct); + services["sysobj"] = make_shared(cct); + services["sysobj_cache"] = make_shared(cct); + services["sysobj_core"] = make_shared(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 *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 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; } diff --git a/src/rgw/rgw_service.h b/src/rgw/rgw_service.h index 7149b47a34ce1..b9f70c7a7a4b4 100644 --- a/src/rgw/rgw_service.h +++ b/src/rgw/rgw_service.h @@ -75,9 +75,13 @@ public: string get_title() { return svc->type() + ":" + svc_instance; } + + std::shared_ptr& get_svc() { + return svc; + } }; -class RGWServiceRegistry : std::enable_shared_from_this { +class RGWServiceRegistry { CephContext *cct; map services; @@ -96,6 +100,22 @@ class RGWServiceRegistry : std::enable_shared_from_this { 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 *new_instances); + template + int do_get_instance(const string& svc_name, + const string& conf, + T *ref, + std::vector *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); diff --git a/src/rgw/services/svc_zone.cc b/src/rgw/services/svc_zone.cc index 4674181e68adc..d5fc135aaa2a1 100644 --- a/src/rgw/services/svc_zone.cc +++ b/src/rgw/services/svc_zone.cc @@ -22,9 +22,9 @@ int RGWS_Zone::create_instance(const string& conf, RGWServiceInstanceRef *instan std::map RGWSI_Zone::get_deps() { map 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 RGWSI_Zone::get_deps() int RGWSI_Zone::load(const string& conf, std::map& dep_refs) { - sysobj_svc = static_pointer_cast(dep_refs["sys_obj_dep"]); + sysobj_svc = static_pointer_cast(dep_refs["sysobj_dep"]); assert(sysobj_svc); realm = make_shared(); -- 2.39.5