From: Yehuda Sadeh Date: Wed, 23 Dec 2015 22:21:31 +0000 (-0800) Subject: rgw: create a short (32bit) zone id, keep it on the period map X-Git-Tag: v10.1.0~354^2~100 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=de129aaa3e6aa33bff02ac4df03d4336635d8826;p=ceph.git rgw: create a short (32bit) zone id, keep it on the period map Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 874c670d5e5..7e0682ee6b2 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -926,6 +926,7 @@ void RGWPeriodMap::dump(Formatter *f) const { encode_json("id", id, f); encode_json_map("zonegroups", zonegroups, f); + encode_json("short_zone_ids", short_zone_ids, f); } static void decode_zonegroups(map& zonegroups, JSONObj *o) @@ -947,6 +948,7 @@ void RGWPeriodMap::decode_json(JSONObj *obj) if (master_zonegroup.empty()) { JSONDecoder::decode_json("master_region", master_zonegroup, obj); } + JSONDecoder::decode_json("short_zone_ids", short_zone_ids, obj); } diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 145bbd588c8..1b9d1fe52ef 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1582,18 +1582,22 @@ int RGWZoneParams::set_as_default() } void RGWPeriodMap::encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); + ENCODE_START(2, 1, bl); ::encode(id, bl); ::encode(zonegroups, bl); ::encode(master_zonegroup, bl); + ::encode(short_zone_ids, bl); ENCODE_FINISH(bl); } void RGWPeriodMap::decode(bufferlist::iterator& bl) { - DECODE_START(1, bl); + DECODE_START(2, bl); ::decode(id, bl); ::decode(zonegroups, bl); ::decode(master_zonegroup, bl); + if (struct_v >= 2) { + ::decode(short_zone_ids, bl); + } DECODE_FINISH(bl); zonegroups_by_api.clear(); @@ -1633,9 +1637,35 @@ int RGWPeriodMap::update(const RGWZoneGroup& zonegroup) master_zonegroup = ""; } + for (auto iter : zonegroups) { + for (auto i : iter.second.zones) { + string& zone_id = i.second.id; + if (short_zone_ids.find(zone_id) == short_zone_ids.end()) { + uint32_t short_id; + + unsigned char md5[CEPH_CRYPTO_MD5_DIGESTSIZE]; + MD5 hash; + hash.Update((const byte *)zone_id.c_str(), zone_id.size()); + hash.Final(md5); + memcpy((char *)&short_id, md5, sizeof(short_id)); + + short_zone_ids[i.second.id] = short_id; + } + } + } + return 0; } +uint32_t RGWPeriodMap::get_zone_short_id(const string& zone_id) const +{ + auto i = short_zone_ids.find(zone_id); + if (i == short_zone_ids.end()) { + return 0; + } + return i->second; +} + int RGWZoneGroupMap::read(CephContext *cct, RGWRados *store) { @@ -3540,6 +3570,8 @@ int RGWRados::init_complete() return -EINVAL; } + zone_short_id = current_period.get_map().get_zone_short_id(zone_params.get_id()); + init_unique_trans_id_deps(); finisher = new Finisher(cct); diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 2d38066b320..05928cef58b 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1163,6 +1163,7 @@ struct RGWPeriodMap string id; map zonegroups; map zonegroups_by_api; + map short_zone_ids; string master_zonegroup; @@ -1178,6 +1179,8 @@ struct RGWPeriodMap zonegroups.clear(); zonegroups_by_api.clear(); } + + uint32_t get_zone_short_id(const string& zone_id) const; }; WRITE_CLASS_ENCODER(RGWPeriodMap) @@ -1779,6 +1782,7 @@ protected: RGWZoneGroup zonegroup; RGWZone zone_public_config; /* external zone params, e.g., entrypoints, log flags, etc. */ RGWZoneParams zone_params; /* internal zone params, e.g., rados pools */ + uint32_t zone_short_id; RGWPeriod current_period; public: @@ -1798,6 +1802,7 @@ public: quota_handler(NULL), finisher(NULL), cr_registry(NULL), + zone_short_id(0), rest_master_conn(NULL), meta_mgr(NULL), data_log(NULL) {} @@ -1878,6 +1883,10 @@ public: return zone_public_config; } + uint32_t get_zone_short_id() const { + return zone_short_id; + } + const RGWQuotaInfo& get_bucket_quota() { return current_period.get_config().bucket_quota; }