]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: create a short (32bit) zone id, keep it on the period map
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 23 Dec 2015 22:21:31 +0000 (14:21 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:48 +0000 (16:13 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_json_enc.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 874c670d5e5c85fde3e5377943f215425a4c4f12..7e0682ee6b20fe92472fef3de6cef1eb48cc8a5a 100644 (file)
@@ -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<string, RGWZoneGroup>& 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);
 }
 
 
index 145bbd588c808d97681eadfcb778164ba412cb9c..1b9d1fe52ef105406e78574c95f7f011e283cc87 100644 (file)
@@ -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);
index 2d38066b32065bc315f05cc4e3e08e9848c11c6a..05928cef58b1cf0772f0369b113c9316d7a9701f 100644 (file)
@@ -1163,6 +1163,7 @@ struct RGWPeriodMap
   string id;
   map<string, RGWZoneGroup> zonegroups;
   map<string, RGWZoneGroup> zonegroups_by_api;
+  map<string, uint32_t> 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;
   }