First load all depending services, then initialize all.
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
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);
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;
}
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;
}
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)
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);
}
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;
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;
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);
*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;
}
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;
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);
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 = "{}" };
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>();