]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: init REST connection by zone name
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 10 Nov 2015 01:02:03 +0000 (17:02 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:30 +0000 (16:13 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_data_sync.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index f5fa262aced9bed143659b74f7ce1f54037a47d5..d50eeb6dd31c509453686693826d0f87f0ea80ba 100644 (file)
@@ -1149,14 +1149,12 @@ int RGWRemoteDataLog::run_sync(int num_shards, rgw_data_sync_status& sync_status
 
 int RGWDataSyncStatusManager::init()
 {
-  map<string, RGWRESTConn *>::iterator iter = store->zone_conn_map.find(source_zone);
-  if (iter == store->zone_conn_map.end()) {
-    lderr(store->ctx()) << "no REST connection to master zone" << dendl;
-    return -EIO;
+  conn = store->get_zone_conn_by_name(source_zone);
+  if (!conn) {
+    ldout(store->ctx(), 0) << "connection object to zone " << source_zone << " does not exist" << dendl;
+    return -EINVAL;
   }
 
-  conn = iter->second;
-
   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);
@@ -2149,14 +2147,12 @@ RGWCoroutine *RGWRemoteBucketLog::run_sync_cr()
 
 int RGWBucketSyncStatusManager::init()
 {
-  map<string, RGWRESTConn *>::iterator iter = store->zone_conn_map.find(source_zone);
-  if (iter == store->zone_conn_map.end()) {
-    lderr(store->ctx()) << "no REST connection to master zone" << dendl;
-    return -EIO;
+  conn = store->get_zone_conn_by_name(source_zone);
+  if (!conn) {
+    ldout(store->ctx(), 0) << "connection object to zone " << source_zone << " does not exist" << dendl;
+    return -EINVAL;
   }
 
-  conn = iter->second;
-
   async_rados = new RGWAsyncRadosProcessor(store, store->ctx()->_conf->rgw_num_async_rados_threads);
   async_rados->start();
 
index 08dd21b87d064d909874f8de948fd8b9633115e7..f3cccf86abadb3d86de4b15fe5178801ba94cfac 100644 (file)
@@ -3279,10 +3279,12 @@ int RGWRados::init_complete()
   for (ziter = get_zonegroup().zones.begin(); ziter != get_zonegroup().zones.end(); ++ziter) {
     const string& id = ziter->first;
     RGWZone& z = ziter->second;
+    zone_id_by_name[z.name] = id;
     if (id != zone_id()) {
       if (!z.endpoints.empty()) {
         ldout(cct, 20) << "generating connection object for zone " << z.name << " id " << z.id << dendl;
-        zone_conn_map[id] = new RGWRESTConn(cct, this, z.endpoints);
+        RGWRESTConn *conn = new RGWRESTConn(cct, this, z.endpoints);
+        zone_conn_map[id] = conn;
       } else {
         ldout(cct, 0) << "WARNING: can't generate connection for zone " << z.id << " id " << z.name << ": no endpoints defined" << dendl;
       }
index b719bd7c4facecf00bb372595194a275de376315..4ba659093c8a9a8c848c799708b88ade28057fcb 100644 (file)
@@ -1827,6 +1827,26 @@ public:
   map<string, RGWRESTConn *> zone_conn_map;
   map<string, RGWRESTConn *> zonegroup_conn_map;
 
+  map<string, string> zone_id_by_name;
+
+  RGWRESTConn *get_zone_conn_by_id(const string& id) {
+    auto citer = zone_conn_map.find(id);
+    if (citer == zone_conn_map.end()) {
+      return NULL;
+    }
+
+    return citer->second;
+  }
+
+  RGWRESTConn *get_zone_conn_by_name(const string& name) {
+    auto i = zone_id_by_name.find(name);
+    if (i == zone_id_by_name.end()) {
+      return NULL;
+    }
+
+    return get_zone_conn_by_id(i->second);
+  }
+
   int get_zonegroup(const string& id, RGWZoneGroup& zonegroup) {
     int ret = 0;
     if (id == get_zonegroup().get_id()) {