From: Yehuda Sadeh Date: Tue, 2 Aug 2016 22:42:21 +0000 (-0700) Subject: rgw: define zone tier type, sync from appropriate tiers only X-Git-Tag: v11.1.0~681^2~31 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b184f8dfbecb9523b8c008522b085b2f2aaf55bf;p=ceph.git rgw: define zone tier type, sync from appropriate tiers only Can only sync from tiers that can export data. Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index a7a732f22f1..4dbac39ac1c 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1955,9 +1955,9 @@ static void sync_status(Formatter *formatter) string zone_name; string source_str = "source: "; string s = source_str + source_id; - auto siter = store->zone_name_by_id.find(source_id); - if (siter != store->zone_name_by_id.end()) { - s += string(" (") + siter->second + ")"; + auto siter = store->zone_by_id.find(source_id); + if (siter != store->zone_by_id.end()) { + s += string(" (") + siter->second.name + ")"; } data_status.push_back(s); get_data_sync_status(source_id, data_status, source_str.size()); diff --git a/src/rgw/rgw_data_sync.cc b/src/rgw/rgw_data_sync.cc index 97e3cc235b8..b23467a8951 100644 --- a/src/rgw/rgw_data_sync.cc +++ b/src/rgw/rgw_data_sync.cc @@ -1597,6 +1597,27 @@ int RGWRemoteDataLog::run_sync(int num_shards) int RGWDataSyncStatusManager::init() { + auto zone_def_iter = store->zone_by_id.find(source_zone); + if (zone_def_iter == store->zone_by_id.end()) { + ldout(store->ctx(), 0) << "ERROR: failed to find zone config info for zone=" << source_zone << dendl; + return -EIO; + } + + auto& zone_def = zone_def_iter->second; + + map sync_module_config; + + if (!store->get_sync_modules_manager()->supports_data_export(zone_def.tier_type)) { + return -ENOTSUP; + } + + int r = store->get_sync_modules_manager()->create_instance(zone_def.tier_type, sync_module_config, &sync_module); + if (r < 0) { + lderr(store->ctx()) << "ERROR: failed to init sync module instance, r=" << r << dendl; + finalize(); + return r; + } + conn = store->get_zone_conn_by_id(source_zone); if (!conn) { ldout(store->ctx(), 0) << "connection object to zone " << source_zone << " does not exist" << dendl; @@ -1605,7 +1626,7 @@ int RGWDataSyncStatusManager::init() const char *log_pool = store->get_zone_params().log_pool.name.c_str(); librados::Rados *rados = store->get_rados_handle(); - int r = rados->ioctx_create(log_pool, ioctx); + r = rados->ioctx_create(log_pool, ioctx); if (r < 0) { lderr(store->ctx()) << "ERROR: failed to open log pool (" << store->get_zone_params().log_pool.name << " ret=" << r << dendl; return r; @@ -1615,14 +1636,6 @@ int RGWDataSyncStatusManager::init() error_logger = new RGWSyncErrorLogger(store, RGW_SYNC_ERROR_LOG_SHARD_PREFIX, ERROR_LOGGER_SHARDS); - map sync_module_config; - r = store->get_sync_modules_manager()->create_instance("default", sync_module_config, &sync_module); - if (r < 0) { - lderr(store->ctx()) << "ERROR: failed to init sync module instance, r=" << r << dendl; - finalize(); - return r; - } - r = source_log.init(source_zone, conn, error_logger, sync_module); if (r < 0) { lderr(store->ctx()) << "ERROR: failed to init remote log, r=" << r << dendl; diff --git a/src/rgw/rgw_data_sync.h b/src/rgw/rgw_data_sync.h index 78201d8b559..d8c419511dc 100644 --- a/src/rgw/rgw_data_sync.h +++ b/src/rgw/rgw_data_sync.h @@ -524,6 +524,7 @@ public: class RGWDefaultSyncModule : public RGWSyncModule { public: RGWDefaultSyncModule() {} + bool supports_data_export() override { return true; } int create_instance(map& config, RGWSyncModuleInstanceRef *instance) override; }; diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 0d6af4cf062..b368e1562c8 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -916,6 +916,7 @@ void RGWZone::dump(Formatter *f) const encode_json("log_data", log_data, f); encode_json("bucket_index_max_shards", bucket_index_max_shards, f); encode_json("read_only", read_only, f); + encode_json("tier_type", tier_type, f); } void RGWZone::decode_json(JSONObj *obj) @@ -930,6 +931,7 @@ void RGWZone::decode_json(JSONObj *obj) JSONDecoder::decode_json("log_data", log_data, obj); JSONDecoder::decode_json("bucket_index_max_shards", bucket_index_max_shards, obj); JSONDecoder::decode_json("read_only", read_only, obj); + JSONDecoder::decode_json("tier_type", tier_type, obj); } void RGWZoneGroupPlacementTarget::dump(Formatter *f) const diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 4a04aeee31a..6c41f7d8ceb 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -3295,7 +3295,7 @@ int RGWRados::init_rados() sync_modules_manager = new RGWSyncModulesManager(); RGWSyncModuleRef default_module(new RGWDefaultSyncModule()); - sync_modules_manager->register_module("default", default_module); + sync_modules_manager->register_module("rgw", default_module, true); auto crs = std::unique_ptr{ new RGWCoroutinesManagerRegistry(cct)}; @@ -3810,7 +3810,7 @@ int RGWRados::init_complete() const string& id = ziter->first; RGWZone& z = ziter->second; zone_id_by_name[z.name] = id; - zone_name_by_id[id] = z.name; + zone_by_id[id] = z; if (id != zone_id()) { if (!z.endpoints.empty()) { ldout(cct, 20) << "generating connection object for zone " << z.name << " id " << z.id << dendl; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 4aa2976c823..024c22516b7 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1002,6 +1002,7 @@ struct RGWZone { bool log_meta; bool log_data; bool read_only; + string tier_type; /** * Represents the number of shards for the bucket index object, a value of zero @@ -1015,7 +1016,7 @@ struct RGWZone { RGWZone() : log_meta(false), log_data(false), read_only(false), bucket_index_max_shards(0) {} void encode(bufferlist& bl) const { - ENCODE_START(4, 1, bl); + ENCODE_START(5, 1, bl); ::encode(name, bl); ::encode(endpoints, bl); ::encode(log_meta, bl); @@ -1023,11 +1024,12 @@ struct RGWZone { ::encode(bucket_index_max_shards, bl); ::encode(id, bl); ::encode(read_only, bl); + ::encode(tier_type, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { - DECODE_START(4, bl); + DECODE_START(5, bl); ::decode(name, bl); if (struct_v < 4) { id = name; @@ -1044,6 +1046,9 @@ struct RGWZone { ::decode(id, bl); ::decode(read_only, bl); } + if (struct_v >= 5) { + ::decode(tier_type, bl); + } DECODE_FINISH(bl); } void dump(Formatter *f) const; @@ -1954,7 +1959,7 @@ public: map zonegroup_conn_map; map zone_id_by_name; - map zone_name_by_id; + map zone_by_id; RGWRESTConn *get_zone_conn_by_id(const string& id) { auto citer = zone_conn_map.find(id); diff --git a/src/rgw/rgw_sync_module.h b/src/rgw/rgw_sync_module.h index 06a9e8452fa..abf6eb1c270 100644 --- a/src/rgw/rgw_sync_module.h +++ b/src/rgw/rgw_sync_module.h @@ -37,6 +37,7 @@ public: RGWSyncModule() {} virtual ~RGWSyncModule() {} + virtual bool supports_data_export() = 0; virtual int create_instance(map& config, RGWSyncModuleInstanceRef *instance) = 0; }; @@ -50,9 +51,12 @@ class RGWSyncModulesManager { public: RGWSyncModulesManager() : lock("RGWSyncModulesManager") {} - void register_module(const string& name, RGWSyncModuleRef& module) { + void register_module(const string& name, RGWSyncModuleRef& module, bool is_default = false) { Mutex::Locker l(lock); modules[name] = module; + if (is_default) { + modules[string()] = module; + } } bool get_module(const string& name, RGWSyncModuleRef *module) { @@ -66,6 +70,15 @@ public: } + int supports_data_export(const string& name) { + RGWSyncModuleRef module; + if (!get_module(name, &module)) { + return -ENOENT; + } + + return module.get()->supports_data_export(); + } + int create_instance(const string& name, map& config, RGWSyncModuleInstanceRef *instance) { RGWSyncModuleRef module; if (!get_module(name, &module)) {