From f5857c728693937578e8a54dbc12a645958399b8 Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Mon, 19 Oct 2015 14:37:59 +0200 Subject: [PATCH] rgw: no need to store or update zonegroupmap Structure and command will be kept for backward compatability Signed-off-by: Orit Wasserman --- src/rgw/rgw_admin.cc | 297 ++-------------------------------------- src/rgw/rgw_json_enc.cc | 46 ++----- src/rgw/rgw_rados.cc | 286 +++++--------------------------------- src/rgw/rgw_rados.h | 62 ++------- 4 files changed, 63 insertions(+), 628 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 42ec0400548be..8f9b5ad7b9c65 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1956,28 +1956,6 @@ int main(int argc, char **argv) cerr << "Error setting current period " << period_id << ":" << cpp_strerror(-ret) << std::endl; return ret; } - RGWZoneGroupMap zonegroup_map; - ret = zonegroup_map.read(g_ceph_context, store); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - ret = zonegroup_map.update(realm); - if (ret < 0) { - cerr << "ERROR: couldn't update realm " << realm_name << ": " << cpp_strerror(-ret) << std::endl; - return ret; - } - ret = zonegroup_map.update(g_ceph_context, store, realm.get_current_period(), realm.get_id()); - if (ret < 0) { - cerr << "ERROR: couldn't update " << realm_name << " current period: " << cpp_strerror(-ret) - << std::endl; - return ret; - } - ret = zonegroup_map.store(g_ceph_context, store); - if (ret < 0) { - cerr << "ERROR: couldn't store zonegroup map info: " << cpp_strerror(-ret) << std::endl; - return 1; - } } break; case OPT_PERIOD_LIST: @@ -2032,32 +2010,6 @@ int main(int argc, char **argv) return ret; } - RGWZoneGroupMap zonegroup_map; - ret = zonegroup_map.read(g_ceph_context, store); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - - ret = zonegroup_map.update(realm); - if (ret < 0) { - cerr << "ERROR: couldn't update realm " << realm_name << ": " << cpp_strerror(-ret) << std::endl; - return ret; - } - - ret = zonegroup_map.update(g_ceph_context, store, realm.get_current_period(), realm.get_id()); - if (ret < 0) { - cerr << "ERROR: couldn't update " << realm_name << " current period: " << cpp_strerror(-ret) - << std::endl; - return ret; - } - - ret = zonegroup_map.store(g_ceph_context, store); - if (ret < 0) { - cerr << "ERROR: couldn't store zonegroup map info: " << cpp_strerror(-ret) << std::endl; - return 1; - } - encode_json("realm", realm, formatter); formatter->flush(cout); cout << std::endl; @@ -2210,32 +2162,6 @@ int main(int argc, char **argv) return 1; } - RGWZoneGroupMap zonegroup_map; - ret = zonegroup_map.read(g_ceph_context, store); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - - ret = zonegroup_map.update(realm); - if (ret < 0) { - cerr << "ERROR: couldn't update realm " << realm_name << ": " << cpp_strerror(-ret) << std::endl; - return ret; - } - - ret = zonegroup_map.update(g_ceph_context, store, realm.get_current_period(), realm.get_id()); - if (ret < 0) { - cerr << "ERROR: couldn't update " << realm_name << " current period: " << cpp_strerror(-ret) - << std::endl; - return ret; - } - - ret = zonegroup_map.store(g_ceph_context, store); - if (ret < 0) { - cerr << "ERROR: couldn't store zonegroup map info: " << cpp_strerror(-ret) << std::endl; - return 1; - } - encode_json("realm", realm, formatter); formatter->flush(cout); } @@ -2285,38 +2211,6 @@ int main(int argc, char **argv) << cpp_strerror(-ret) << std::endl; return ret; } - - if (realm_id.empty() && realm_name.empty()) { - if (zonegroup.realm_id.empty()) { - cerr << "no realm info provided" << std::endl; - return -EINVAL; - } - realm_id = zonegroup.realm_id; - } - - RGWRealm realm(realm_id, realm_name); - ret = realm.init(g_ceph_context, store); - if (ret < 0) { - cerr << "ERROR: couldn't init realm:" << cpp_strerror(-ret) << std::endl; - return ret; - } - - RGWZoneGroupMap zonegroup_map; - ret = zonegroup_map.read(g_ceph_context, store); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - ret = zonegroup_map.update(g_ceph_context, store, realm, zonegroup); - if (ret < 0) { - cerr << "failed to update zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - ret = zonegroup_map.store(g_ceph_context, store); - if (ret < 0) { - cerr << "failed to store zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } } break; case OPT_ZONEGROUP_CREATE: @@ -2340,24 +2234,6 @@ int main(int argc, char **argv) return -ret; } - RGWZoneGroupMap zonegroup_map; - ret = zonegroup_map.read(g_ceph_context, store); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - - ret = zonegroup_map.update(g_ceph_context, store, realm, zonegroup); - if (ret < 0) { - cerr << "failed to update zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - ret = zonegroup_map.store(g_ceph_context, store); - if (ret < 0) { - cerr << "failed to store zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - encode_json("zonegroup", zonegroup, formatter); formatter->flush(cout); cout << std::endl; @@ -2491,40 +2367,6 @@ int main(int argc, char **argv) return -ret; } } - - RGWZoneGroupMap zonegroup_map; - ret = zonegroup_map.read(g_ceph_context, store); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - - string master_zonegroup; - if (ret != -ENOENT) { - ret = zonegroup_map.get_master_zonegroup(realm.get_current_period(), master_zonegroup); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - } - - if (is_master) { - /* zonegroup already set as master zonegroup nothing to do*/ - if (master_zonegroup == zonegroup.get_id()) { - return 0; - } - } - - ret = zonegroup_map.update(g_ceph_context, store, realm, zonegroup); - if (ret < 0) { - cerr << "failed to update master zonegroup: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - ret = zonegroup_map.store(g_ceph_context, store); - if (ret < 0) { - cerr << "failed to store zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } } break; case OPT_ZONEGROUP_SET: @@ -2558,24 +2400,6 @@ int main(int argc, char **argv) } } - RGWZoneGroupMap zonegroup_map; - ret = zonegroup_map.read(g_ceph_context, store); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - - ret = zonegroup_map.update(g_ceph_context, store, realm, zonegroup); - if (ret < 0) { - cerr << "failed to update zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - ret = zonegroup_map.store(g_ceph_context, store); - if (ret < 0) { - cerr << "failed to store zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - encode_json("zonegroup", zonegroup, formatter); formatter->flush(cout); } @@ -2606,11 +2430,13 @@ int main(int argc, char **argv) case OPT_ZONEGROUPMAP_GET: { RGWZoneGroupMap zonegroupmap; + int ret = zonegroupmap.read(g_ceph_context, store); if (ret < 0) { - cerr << "failed to read zonegroup map: " << cpp_strerror(-ret) << std::endl; - return -ret; + cerr << "failed to read zonegroupmap info: " << cpp_strerror(ret); + return ret; } + encode_json("zonegroup-map", zonegroupmap, formatter); formatter->flush(cout); } @@ -2618,73 +2444,13 @@ int main(int argc, char **argv) case OPT_ZONEGROUPMAP_SET: { RGWZoneGroupMap zonegroupmap; - bufferlist bl; - int ret = read_input(infile, bl); - if (ret < 0) { - cerr << "ERROR: failed to read input: " << cpp_strerror(-ret) << std::endl; - return ret; - } - JSONParser p; - ret = p.parse(bl.c_str(), bl.length()); + int ret = read_decode_json(infile, zonegroupmap); if (ret < 0) { - cout << "failed to parse JSON" << std::endl; + cerr << "ERROR: failed to read map json: " << cpp_strerror(-ret) << std::endl; return ret; } - try { - decode_json_obj(zonegroupmap, &p); - } catch (JSONDecoder::err& e) { - cout << "failed to decode: " << e.message << std::endl; - RGWRegionMap region_map; - try { - decode_json_obj(region_map, &p); - RGWRealm realm(realm_id, realm_name); - ret = realm.init(g_ceph_context, store); - if (ret < 0) { - cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - - ret = zonegroupmap.update(realm); - if (ret < 0) { - cerr << "failed to update zonegroup_map: " << cpp_strerror(-ret) << std::endl; - } - - ret = zonegroupmap.update(g_ceph_context, store, realm.get_current_period(), realm.get_id()); - if (ret < 0) { - cerr << "ERROR: couldn't update current period: " << cpp_strerror(-ret) - << std::endl; - return ret; - } - - for(map::iterator iter = region_map.regions.begin(); - iter != region_map.regions.end(); iter++) { - iter->second.set_id(iter->second.get_name()); - ret = zonegroupmap.update(g_ceph_context, store, realm, iter->second); - if (ret < 0) { - cerr << "failed to update zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - } - ret = zonegroupmap.update_master_zonegroup(realm.get_current_period(), - region_map.master_region); - if (ret < 0) { - cerr << "ERROR: couldn't update master_zonegroup " << region_map.master_region << ": " - << cpp_strerror(-ret) << std::endl; - return ret; - } - zonegroupmap.bucket_quota = region_map.bucket_quota; - zonegroupmap.user_quota = region_map.user_quota; - } catch (JSONDecoder::err& e) { - cout << "failed to decode: " << e.message << std::endl; - return -EINVAL; - } - } - ret = zonegroupmap.store(g_ceph_context, store); - if (ret < 0) { - cerr << "ERROR: couldn't store zonegroup map info: " << cpp_strerror(-ret) << std::endl; - return 1; - } + #warning need to implement for backward compatabilty encode_json("zonegroup-map", zonegroupmap, formatter); formatter->flush(cout); @@ -2699,8 +2465,10 @@ int main(int argc, char **argv) return -ret; } - if (reset_regions) { - zonegroupmap.clear_zonegroups(); + #warning need to implement for backward compatabilty + + if (reset_regions) { + zonegroupmap.zonegroups.clear(); } list realms; @@ -2718,14 +2486,6 @@ int main(int argc, char **argv) cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl; return -ret; } - zonegroupmap.update(realm); - zonegroupmap.update(g_ceph_context, store, realm.get_current_period(), realm.get_id()); - } - - ret = zonegroupmap.store(g_ceph_context, store); - if (ret < 0) { - cerr << "ERROR: couldn't store zonegroup map info: " << cpp_strerror(-ret) << std::endl; - return 1; } encode_json("zonegroup-map", zonegroupmap, formatter); @@ -2784,23 +2544,6 @@ int main(int argc, char **argv) << ": " << cpp_strerror(-ret) << std::endl; return ret; } - - RGWZoneGroupMap zonegroup_map; - ret = zonegroup_map.read(g_ceph_context, store); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - ret = zonegroup_map.update(g_ceph_context, store, realm, zonegroup); - if (ret < 0) { - cerr << "failed to update zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - ret = zonegroup_map.store(g_ceph_context, store); - if (ret < 0) { - cerr << "failed to store zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } } encode_json("zone", zone, formatter); @@ -3019,24 +2762,6 @@ int main(int argc, char **argv) cerr << "failed to update zonegroup: " << cpp_strerror(-ret) << std::endl; return -ret; } - - RGWZoneGroupMap zonegroup_map; - ret = zonegroup_map.read(g_ceph_context, store); - if (ret < 0 && ret != -ENOENT) { - cerr << "ERROR: couldn't read zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return ret; - } - - ret = zonegroup_map.update(g_ceph_context, store, realm, zonegroup); - if (ret < 0) { - cerr << "failed to update master zonegroup: " << cpp_strerror(-ret) << std::endl; - return -ret; - } - ret = zonegroup_map.store(g_ceph_context, store); - if (ret < 0) { - cerr << "failed to store zonegroup_map: " << cpp_strerror(-ret) << std::endl; - return -ret; - } } break; case OPT_ZONE_RENAME: diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 2b9ab8d0db915..f743c2af30257 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -962,51 +962,27 @@ void RGWPeriodConfig::decode_json(JSONObj *obj) JSONDecoder::decode_json("user_quota", user_quota, obj); } -static void decode_realms(map& realms, JSONObj *o) -{ - RGWRealm r; - r.decode_json(o); - realms[r.get_id()] = r; -} - -static void decode_periods(map& periods, JSONObj *o) -{ - RGWPeriodMap p; - p.decode_json(o); - periods[p.id] = p; -} - void RGWZoneGroupMap::dump(Formatter *f) const { - encode_json_map("realms", realms, f); - encode_json_map("periods", periods, f); + encode_json("zonegroups", zonegroups, f); + encode_json("master_zonegroup", master_zonegroup, f); encode_json("bucket_quota", bucket_quota, f); encode_json("user_quota", user_quota, f); } void RGWZoneGroupMap::decode_json(JSONObj *obj) { - /* check for old format */ - if (!JSONDecoder::decode_json("realms", realms, decode_realms, obj) ) { - throw JSONDecoder::err("Old regionmap format"); + JSONDecoder::decode_json("zonegroups", zonegroups, obj); + /* backward compatability with region */ + if (zonegroups.empty()) { + JSONDecoder::decode_json("regions", zonegroups, obj); + } + JSONDecoder::decode_json("master_zonegroup", master_zonegroup, obj); + /* backward compatability with region */ + if (master_zonegroup.empty()) { + JSONDecoder::decode_json("master_region", master_zonegroup, obj); } - JSONDecoder::decode_json("periods", periods, decode_periods, obj); - JSONDecoder::decode_json("bucket_quota", bucket_quota, obj); - JSONDecoder::decode_json("user_quota", user_quota, obj); -} - -void RGWRegionMap::dump(Formatter *f) const -{ - encode_json("regions", regions, f); - encode_json("master_region", master_region, f); - encode_json("bucket_quota", bucket_quota, f); - encode_json("user_quota", user_quota, f); -} -void RGWRegionMap::decode_json(JSONObj *obj) -{ - JSONDecoder::decode_json("regions", regions, obj); - JSONDecoder::decode_json("master_region", master_region, obj); JSONDecoder::decode_json("bucket_quota", bucket_quota, obj); JSONDecoder::decode_json("user_quota", user_quota, obj); } diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index b19cd1a449f78..da300ee3c83bb 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1228,274 +1228,52 @@ int RGWPeriodMap::update(const RGWZoneGroup& zonegroup) return 0; } -void RGWRegionMap::encode(bufferlist& bl) const { - ENCODE_START(3, 1, bl); - ::encode(regions, bl); - ::encode(master_region, bl); - ::encode(bucket_quota, bl); - ::encode(user_quota, bl); - ENCODE_FINISH(bl); -} - -void RGWRegionMap::decode(bufferlist::iterator& bl) { - DECODE_START(3, bl); - ::decode(regions, bl); - ::decode(master_region, bl); - if (struct_v >= 2) - ::decode(bucket_quota, bl); - if (struct_v >= 3) - ::decode(user_quota, bl); - DECODE_FINISH(bl); +int RGWZoneGroupMap::read(CephContext *cct, RGWRados *store) { - regions_by_api.clear(); - for (map::iterator iter = regions.begin(); - iter != regions.end(); ++iter) { - RGWZoneGroup& region = iter->second; - regions_by_api[region.api_name] = region; - if (region.is_master) { - master_region = region.get_name(); - } + RGWPeriod period; + int ret = period.init(cct, store); + if (ret < 0) { + cerr << "failed to read current period info: " << cpp_strerror(ret); + return ret; } -} + + bucket_quota = period.get_config().bucket_quota; + user_quota = period.get_config().user_quota; + zonegroups = period.get_map().zonegroups; + zonegroups_by_api = period.get_map().zonegroups_by_api; + master_zonegroup = period.get_map().master_zonegroup; + return 0; +} + void RGWZoneGroupMap::encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - ::encode(realms, bl); - ::encode(periods, bl); + ENCODE_START( 3, 1, bl); + ::encode(zonegroups, bl); + ::encode(master_zonegroup, bl); ::encode(bucket_quota, bl); ::encode(user_quota, bl); ENCODE_FINISH(bl); } void RGWZoneGroupMap::decode(bufferlist::iterator& bl) { - DECODE_START(1, bl); - ::decode(realms, bl); - ::decode(periods, bl); - ::decode(bucket_quota, bl); - ::decode(user_quota, bl); + DECODE_START(3, bl); + ::decode(zonegroups, bl); + ::decode(master_zonegroup, bl); + if (struct_v >= 2) + ::decode(bucket_quota, bl); + if (struct_v >= 3) + ::decode(user_quota, bl); DECODE_FINISH(bl); -} -void RGWZoneGroupMap::get_params(CephContext *cct, string& pool_name, string& oid) -{ - pool_name = cct->_conf->rgw_zone_root_pool; - if (pool_name.empty()) { - pool_name = RGW_DEFAULT_ZONE_ROOT_POOL; - } - oid = region_map_oid; -} - -int RGWZoneGroupMap::read(CephContext *cct, RGWRados *store) -{ - Mutex::Locker l(lock); - - string pool_name, oid; - - get_params(cct, pool_name, oid); - - rgw_bucket pool(pool_name.c_str()); - - bufferlist bl; - RGWObjectCtx obj_ctx(store); - int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, NULL, NULL); - if (ret < 0) - return ret; - - - try { - bufferlist::iterator iter = bl.begin(); - ::decode(*this, iter); - } catch (buffer::error& err) { - ldout(cct, 0) << "ERROR: failed to decode zone group map info from " << pool << ":" << oid << dendl; - return -EIO; - } - - return 0; -} - -int RGWZoneGroupMap::store(CephContext *cct, RGWRados *store) -{ - string pool_name, oid; - - get_params(cct, pool_name, oid); - - rgw_bucket pool(pool_name.c_str()); - - bufferlist bl; - ::encode(*this, bl); - int ret = rgw_put_system_obj(store, pool, oid, bl.c_str(), bl.length(), false, NULL, 0, NULL); - - return ret; -} - -int RGWZoneGroupMap::update(CephContext *cct, RGWRados *store, - const RGWRealm& realm, const RGWZoneGroup& zonegroup) -{ - Mutex::Locker l(lock); - - map::iterator iter = periods.find(realm.get_current_period()); - if (iter == periods.end()) { - derr << "ERROR: cannot find period " << realm.get_current_period() << dendl; - return -EINVAL; - } - - int ret = iter->second.update(zonegroup); - if (ret < 0) { - derr << "ERROR: failed update period " << iter->first << ":" << cpp_strerror(-ret) << dendl; - return ret; - } - - /* update rest_master_conn if not already created*/ - if (zonegroup.is_master) { - if (!store->rest_master_conn) { - store->rest_master_conn = new RGWRESTConn(cct, store, zonegroup.endpoints); - derr << "creating rest_master_conn " << dendl; - } - } - - return 0; -} - -int RGWZoneGroupMap::update(RGWRealm& realm) -{ - Mutex::Locker l(lock); - realms[realm.get_id()] = realm; - return 0; -} - -int RGWZoneGroupMap::update(CephContext *cct, RGWRados *store, - const string& period_id, - const string& realm_id) -{ - Mutex::Locker l(lock); - RGWPeriod period(period_id); - - int ret = period.init(cct, store, realm_id); - if (ret < 0) { - derr << "failed to init period: " << cpp_strerror(-ret) << dendl; - return ret; - } - - periods[period_id] = period.get_map(); - - return 0; -} - - -int RGWZoneGroupMap::update_master_zonegroup(const string& period_id, - const string& master_zonegroup) -{ - map::iterator period_iter = periods.find(period_id); - if (period_iter == periods.end()) { - derr << "ERROR: period " << period_id << " not found" << dendl; - return -EINVAL; - } - - map::iterator iter = period_iter->second.zonegroups.find(master_zonegroup); - if (iter == period_iter->second.zonegroups.end()) { - derr << "ERROR: bad zonegroup map: inconsistent master zonegroup" << dendl; - return -EINVAL; - } - - period_iter->second.master_zonegroup = master_zonegroup; - - return 0; -} - -int RGWZoneGroupMap::get_master_zonegroup(const string& current_period, - string& master_zonegroup) -{ - map::iterator period_iter = periods.find(current_period); - if (period_iter == periods.end()) { - derr << "ERROR: period " << current_period << " not found" << dendl; - return -EINVAL; - } - - master_zonegroup = period_iter->second.master_zonegroup; - - return 0; -} - -int RGWZoneGroupMap::get_zonegroups(const string& current_period, - map& zonegroups) -{ - map::iterator period_iter = periods.find(current_period); - if (period_iter == periods.end()) { - derr << "ERROR: period " << current_period << " not found" << dendl; - return -EINVAL; - } - - zonegroups = period_iter->second.zonegroups; - - return 0; -} - -int RGWZoneGroupMap::get_zonegroup(CephContext *cct, RGWRados *store, - RGWZoneGroup& zonegroup, - const string& zonegroup_id, - const string& current_period) -{ - map::iterator period_iter; - if (!current_period.empty()) { - period_iter = periods.find(current_period); - } else { - RGWRealm realm; - int ret = realm.init(cct, store); - if (ret < 0) { - ldout(cct, 0) << "ERROR: period " << current_period << " not found" << dendl; - return ret; + zonegroups_by_api.clear(); + for (map::iterator iter = zonegroups.begin(); + iter != zonegroups.end(); ++iter) { + RGWZoneGroup& zonegroup = iter->second; + zonegroups_by_api[zonegroup.api_name] = zonegroup; + if (zonegroup.is_master) { + master_zonegroup = zonegroup.get_name(); } - period_iter = periods.find(realm.get_current_period()); - } - - if (period_iter == periods.end()) { - ldout(cct, 0) << "ERROR: period " << current_period << " not found" << dendl; - return -EINVAL; - } - - map::iterator iter = period_iter->second.zonegroups.find(zonegroup_id); - if (iter == period_iter->second.zonegroups.end()) { - ldout(cct, 0) << "ERROR: bad zonegroup map: inconsistent master zonegroup" << dendl; - return -EINVAL; - } - - zonegroup = iter->second; - - return 0; -} - -bool RGWZoneGroupMap::is_single_zonegroup(CephContext *cct, RGWRados *store) -{ - - if (periods.empty()) { - return true; - } - - map::iterator period_iter; - RGWRealm realm; - int ret = realm.init(cct, store); - if (ret < 0) { - ldout(cct, 0) << "ERROR: init realm" << dendl; - return false; - } - - period_iter = periods.find(realm.get_current_period()); - - if (period_iter == periods.end()) { - ldout(cct, 0) << "ERROR: current period " << realm.get_current_period() << " not found" << dendl; - return false; - } - - return (period_iter->second.zonegroups.size() == 1); -} - - -void RGWZoneGroupMap::clear_zonegroups() -{ - for (map::iterator period_iter = periods.begin(); period_iter != periods.end(); - period_iter++) { - period_iter->second.zonegroups.clear(); } } diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 3bc45ec4262fc..8f4124080ac48 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1197,74 +1197,30 @@ struct RGWPeriodConfig }; WRITE_CLASS_ENCODER(RGWPeriodConfig) -struct RGWRegionMap { - map regions; - map regions_by_api; - - string master_region; - - RGWQuotaInfo bucket_quota; - RGWQuotaInfo user_quota; - - void encode(bufferlist& bl) const; - void decode(bufferlist::iterator& bl); +/* for backward comaptability */ +struct RGWZoneGroupMap { - void dump(Formatter *f) const; - void decode_json(JSONObj *obj); -}; -WRITE_CLASS_ENCODER(RGWRegionMap) + map zonegroups; + map zonegroups_by_api; -class RGWRealm; -struct RGWZoneGroupMap { + string master_zonegroup; - Mutex lock; - map realms; - map periods; RGWQuotaInfo bucket_quota; RGWQuotaInfo user_quota; - RGWZoneGroupMap& operator=(const RGWZoneGroupMap& map) { - periods = map.periods; - bucket_quota = map.bucket_quota; - user_quota = map.user_quota; - return *this; - } - - RGWZoneGroupMap() : lock("RGWZoneGroupMap"){} + /* constract the map */ + int read(CephContext *cct, RGWRados *store); void encode(bufferlist& bl) const; void decode(bufferlist::iterator& bl); - void get_params(CephContext *cct, string& pool_name, string& oid); - int read(CephContext *cct, RGWRados *store); - int store(CephContext *cct, RGWRados *store); - - int update(CephContext *cct, RGWRados *store, - const RGWRealm& realm, const RGWZoneGroup& zonegroup); - int update(RGWRealm& realm); - int update(CephContext *cct, RGWRados *store, - const string& period_id, - const string& realm_id); - int update_master_zonegroup(const string& period_id, - const string& master_zonegroup); - int get_master_zonegroup(const string& current_period, - string& master_zonegroup); - - int get_zonegroups(const string& current_period, - map& zonegroups); - - int get_zonegroup(CephContext *cct, RGWRados *store, - RGWZoneGroup& zonegroup, - const string& zonegroup_id, - const string& current_period = ""); - - bool is_single_zonegroup(CephContext *cct, RGWRados *store); - void clear_zonegroups(); void dump(Formatter *f) const; void decode_json(JSONObj *obj); }; WRITE_CLASS_ENCODER(RGWZoneGroupMap) +class RGWRealm; + struct objexp_hint_entry { string tenant; string bucket_name; -- 2.39.5