]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw, radosgw-admin: explicit zone id type
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 14 Nov 2019 04:09:53 +0000 (20:09 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 28 Jan 2020 18:20:38 +0000 (10:20 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
25 files changed:
src/rgw/rgw_admin.cc
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_bucket_sync.cc
src/rgw/rgw_bucket_sync.h
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_cr_rados.h
src/rgw/rgw_cr_tools.h
src/rgw/rgw_data_sync.cc
src/rgw/rgw_data_sync.h
src/rgw/rgw_json_enc.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_sync_module_aws.cc
src/rgw/rgw_sync_policy.cc
src/rgw/rgw_sync_policy.h
src/rgw/rgw_trim_mdlog.cc
src/rgw/rgw_zone.cc
src/rgw/rgw_zone.h
src/rgw/services/svc_bucket_sync.h
src/rgw/services/svc_bucket_sync_sobj.cc
src/rgw/services/svc_bucket_sync_sobj.h
src/rgw/services/svc_zone.cc
src/rgw/services/svc_zone.h

index a78b6daf06a96f6fc910df3f6806dc1c20342c3b..43768e796867c873195f4778f25bf5b5559681cd 100644 (file)
@@ -1630,13 +1630,13 @@ static int commit_period(RGWRealm& realm, RGWPeriod& period,
                          const string& access, const string& secret,
                          bool force)
 {
-  const string& master_zone = period.get_master_zone();
+  auto& master_zone = period.get_master_zone();
   if (master_zone.empty()) {
     cerr << "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl;
     return -EINVAL;
   }
   // are we the period's master zone?
-  if (store->svc()->zone->get_zone_params().get_id() == master_zone) {
+  if (store->svc()->zone->zone_id() == master_zone) {
     // read the current period
     RGWPeriod current_period;
     int ret = current_period.init(g_ceph_context, store->svc()->sysobj, realm.get_id());
@@ -1655,7 +1655,7 @@ static int commit_period(RGWRealm& realm, RGWPeriod& period,
 
   if (remote.empty() && url.empty()) {
     // use the new master zone's connection
-    remote = master_zone;
+    remote = master_zone.id;
     cout << "Sending period to new master zone " << remote << std::endl;
   }
   boost::optional<RGWRESTConn> conn;
@@ -1671,7 +1671,7 @@ static int commit_period(RGWRealm& realm, RGWPeriod& period,
   }
 
   // push period to the master with an empty period id
-  period.set_id("");
+  period.set_id(string());
 
   RGWEnv env;
   req_info info(g_ceph_context, &env);
@@ -2007,13 +2007,13 @@ static void get_md_sync_status(list<string>& status)
   flush_ss(ss, status);
 }
 
-static void get_data_sync_status(const string& source_zone, list<string>& status, int tab)
+static void get_data_sync_status(const rgw_zone_id& source_zone, list<string>& status, int tab)
 {
   stringstream ss;
 
   RGWZone *sz;
 
-  if (!store->svc()->zone->find_zone_by_id(source_zone, &sz)) {
+  if (!store->svc()->zone->find_zone(source_zone, &sz)) {
     push_ss(ss, status, tab) << string("zone not found");
     flush_ss(ss, status);
     return;
@@ -2205,11 +2205,11 @@ static void sync_status(Formatter *formatter)
   auto& zone_conn_map = store->svc()->zone->get_zone_conn_map();
 
   for (auto iter : zone_conn_map) {
-    const string& source_id = iter.first;
+    const rgw_zone_id& source_id = iter.first;
     string source_str = "source: ";
-    string s = source_str + source_id;
+    string s = source_str + source_id.id;
     RGWZone *sz;
-    if (store->svc()->zone->find_zone_by_id(source_id, &sz)) {
+    if (store->svc()->zone->find_zone(source_id, &sz)) {
       s += string(" (") + sz->name + ")";
     }
     data_status.push_back(s);
@@ -2345,17 +2345,11 @@ static std::vector<string> convert_bucket_set_to_str_vec(const std::set<rgw_buck
   return std::move(result);
 }
 
-static void get_hint_entities(const std::set<string>& zone_names, const std::set<rgw_bucket>& buckets,
+static void get_hint_entities(const std::set<rgw_zone_id>& zones, const std::set<rgw_bucket>& buckets,
                              std::set<rgw_sync_bucket_entity> *hint_entities)
 {
-  for (auto& zone : zone_names) {
+  for (auto& zone_id : zones) {
     for (auto& b : buckets) {
-      string zid;
-      if (!store->svc()->zone->find_zone_id_by_name(zone, &zid)) {
-       cerr << "WARNING: cannot find zone id for zone=" << zone << ", skippping" << std::endl;
-       continue;
-      }
-
       RGWBucketInfo hint_bucket_info;
       rgw_bucket hint_bucket;
       int ret = init_bucket(b, hint_bucket_info, hint_bucket);
@@ -2364,27 +2358,33 @@ static void get_hint_entities(const std::set<string>& zone_names, const std::set
        continue;
       }
 
-      hint_entities->insert(rgw_sync_bucket_entity(zid, hint_bucket));
+      hint_entities->insert(rgw_sync_bucket_entity(zone_id, hint_bucket));
     }
   }
 }
 
-static int sync_info(std::optional<string> opt_target_zone, std::optional<rgw_bucket> opt_bucket, Formatter *formatter)
+static rgw_zone_id resolve_zone_id(const string& s)
 {
-  string zone_name;
-  std::optional<string> zone_id;
+  rgw_zone_id result;
 
-  if (opt_target_zone) {
-    string zid;
-    if (!store->svc()->zone->find_zone_id_by_name(*opt_target_zone, &zid)) {
-      cerr << "WARNING: cannot find zone id for zone=" << *opt_target_zone << std::endl;
-      return -ENOENT;
-    }
-    zone_name = *opt_target_zone;
-    zone_id = zid;
-  } else {
-    zone_name = store->svc ()->zone->zone_name();
+  RGWZone *zone;
+  if (store->svc()->zone->find_zone(s, &zone)) {
+    return rgw_zone_id(s);
+  }
+  if (store->svc()->zone->find_zone_id_by_name(s, &result)) {
+    return result;
   }
+  return rgw_zone_id(s);
+}
+
+rgw_zone_id validate_zone_id(const rgw_zone_id& zone_id)
+{
+  return resolve_zone_id(zone_id.id);
+}
+
+static int sync_info(std::optional<rgw_zone_id> opt_target_zone, std::optional<rgw_bucket> opt_bucket, Formatter *formatter)
+{
+  rgw_zone_id zone_id = opt_target_zone.value_or(store->svc()->zone->zone_id());
 
   auto zone_policy_handler = store->svc()->zone->get_sync_policy_handler(zone_id);
 
@@ -2431,10 +2431,10 @@ static int sync_info(std::optional<string> opt_target_zone, std::optional<rgw_bu
   std::set<rgw_sync_bucket_pipe> resolved_sources;
   std::set<rgw_sync_bucket_pipe> resolved_dests;
 
-  rgw_sync_bucket_entity self_entity(zone_name, opt_bucket);
+  rgw_sync_bucket_entity self_entity(zone_id, opt_bucket);
 
-  set<string> source_zones;
-  set<string> target_zones;
+  set<rgw_zone_id> source_zones;
+  set<rgw_zone_id> target_zones;
 
   zone_policy_handler->reflect(nullptr, nullptr,
                                nullptr, nullptr,
@@ -2453,7 +2453,7 @@ static int sync_info(std::optional<string> opt_target_zone, std::optional<rgw_bu
       continue; /* shouldn't really happen */
     }
 
-    auto& zid = *hint_entity.zone;
+    auto zid = validate_zone_id(*hint_entity.zone);
     auto& hint_bucket = *hint_entity.bucket;
 
     RGWBucketSyncPolicyHandlerRef hint_bucket_handler;
@@ -2464,9 +2464,9 @@ static int sync_info(std::optional<string> opt_target_zone, std::optional<rgw_bu
     }
 
     hint_bucket_handler->get_pipes(&resolved_dests,
-                                  &resolved_sources,
-                                  self_entity); /* flipping resolved dests and sources as these are
-                                                   relative to the remote entity */
+                                   &resolved_sources,
+                                   self_entity); /* flipping resolved dests and sources as these are
+                                                    relative to the remote entity */
   }
 
   {
@@ -2479,10 +2479,15 @@ static int sync_info(std::optional<string> opt_target_zone, std::optional<rgw_bu
       encode_json("dests", target_hints_vec, formatter);
     }
     {
-      Formatter::ObjectSection resolved_hints_section(*formatter, "resolved-hints");
+      Formatter::ObjectSection resolved_hints_section(*formatter, "resolved-hints-1");
       encode_json("sources", resolved_sources, formatter);
       encode_json("dests", resolved_dests, formatter);
     }
+    {
+      Formatter::ObjectSection resolved_hints_section(*formatter, "resolved-hints");
+      encode_json("sources", handler->get_resolved_source_hints(), formatter);
+      encode_json("dests", handler->get_resolved_dest_hints(), formatter);
+    }
   }
 
   formatter->flush(cout);
@@ -2530,7 +2535,7 @@ static int bucket_sync_info(rgw::sal::RGWRadosStore *store, const RGWBucketInfo&
 }
 
 static int bucket_sync_status(rgw::sal::RGWRadosStore *store, const RGWBucketInfo& info,
-                              const std::string& source_zone_id,
+                              const rgw_zone_id& source_zone_id,
                               std::ostream& out)
 {
   const RGWRealm& realm = store->svc()->zone->get_realm();
@@ -2559,7 +2564,7 @@ static int bucket_sync_status(rgw::sal::RGWRadosStore *store, const RGWBucketInf
   auto& sources = handler->get_sources();
 
   auto& zone_conn_map = store->svc()->zone->get_zone_conn_map();
-  set<string> zone_ids;
+  set<rgw_zone_id> zone_ids;
 
   if (!source_zone_id.empty()) {
     auto z = zonegroup.zones.find(source_zone_id);
@@ -2585,7 +2590,7 @@ static int bucket_sync_status(rgw::sal::RGWRadosStore *store, const RGWBucketInf
   }
 
   for (auto& zone_id : zone_ids) {
-    auto z = zonegroup.zones.find(zone_id);
+    auto z = zonegroup.zones.find(zone_id.id);
     if (z == zonegroup.zones.end()) { /* should't happen */
       continue;
     }
@@ -2597,7 +2602,7 @@ static int bucket_sync_status(rgw::sal::RGWRadosStore *store, const RGWBucketInf
     for (auto& m : sources) {
       for (auto& entry : m.second.pipe_map) {
         auto& pipe = entry.second;
-        if (pipe.source.zone.value_or("") == z->second.id) {
+        if (pipe.source.zone.value_or(rgw_zone_id()) == z->second.id) {
           bucket_source_sync_status(store, zone, z->second,
                                     c->second,
                                     info, pipe,
@@ -2918,6 +2923,43 @@ public:
 
 };
 
+void resolve_zone_id_opt(std::optional<string>& zone_name, std::optional<rgw_zone_id>& zone_id)
+{
+  if (!zone_name || zone_id) {
+    return;
+  }
+  zone_id.emplace();
+  if (!store->svc()->zone->find_zone_id_by_name(*zone_name, &(*zone_id))) {
+    cerr << "WARNING: cannot find source zone id for name=" << *zone_name << std::endl;
+    zone_id = rgw_zone_id(*zone_name);
+  }
+}
+void resolve_zone_ids_opt(std::optional<vector<string> >& names, std::optional<vector<rgw_zone_id> >& ids)
+{
+  if (!names || ids) {
+    return;
+  }
+  ids.emplace();
+  for (auto& name : *names) {
+    rgw_zone_id zid;
+    if (!store->svc()->zone->find_zone_id_by_name(name, &zid)) {
+      cerr << "WARNING: cannot find source zone id for name=" << name << std::endl;
+      zid = rgw_zone_id(name);
+    }
+    ids->push_back(zid);
+  }
+}
+
+static vector<rgw_zone_id> zone_ids_from_str(const string& val)
+{
+  vector<rgw_zone_id> result;
+  vector<string> v;
+  get_str_vec(val, v);
+  for (auto& z : v) {
+    result.push_back(rgw_zone_id(z));
+  }
+  return result;
+}
 
 int main(int argc, const char **argv)
 {
@@ -3066,7 +3108,7 @@ int main(int argc, const char **argv)
   string err;
 
   string source_zone_name;
-  string source_zone; /* zone id */
+  rgw_zone_id source_zone; /* zone id */
 
   string tier_type;
   bool tier_type_specified = false;
@@ -3100,12 +3142,15 @@ int main(int argc, const char **argv)
   std::optional<string> opt_group_id;
   std::optional<string> opt_status;
   std::optional<string> opt_flow_type;
-  std::optional<vector<string> > opt_zones;
+  std::optional<vector<string> > opt_zone_names;
+  std::optional<vector<rgw_zone_id> > opt_zone_ids;
   std::optional<string> opt_flow_id;
   std::optional<string> opt_source_zone;
   std::optional<string> opt_dest_zone;
-  std::optional<vector<string> > opt_source_zones;
-  std::optional<vector<string> > opt_dest_zones;
+  std::optional<vector<string> > opt_source_zone_names;
+  std::optional<vector<rgw_zone_id> > opt_source_zone_ids;
+  std::optional<vector<string> > opt_dest_zone_names;
+  std::optional<vector<rgw_zone_id> > opt_dest_zone_ids;
   std::optional<string> opt_pipe_id;
   std::optional<rgw_bucket> opt_bucket;
   std::optional<string> opt_tenant;
@@ -3119,7 +3164,8 @@ int main(int argc, const char **argv)
   std::optional<string> opt_dest_tenant;
   std::optional<string> opt_dest_bucket_name;
   std::optional<string> opt_dest_bucket_id;
-  std::optional<string> opt_effective_zone;
+  std::optional<string> opt_effective_zone_name;
+  std::optional<rgw_zone_id> opt_effective_zone_id;
 
   std::optional<string> opt_prefix;
   std::optional<string> opt_prefix_rm;
@@ -3488,18 +3534,24 @@ int main(int argc, const char **argv)
       opt_status = val;
     } else if (ceph_argparse_witharg(args, i, &val, "--flow-type", (char*)NULL)) {
       opt_flow_type = val;
-    } else if (ceph_argparse_witharg(args, i, &val, "--zones", (char*)NULL)) {
+    } else if (ceph_argparse_witharg(args, i, &val, "--zones", "--zone-names", (char*)NULL)) {
       vector<string> v;
       get_str_vec(val, v);
-      opt_zones = std::move(v);
-    } else if (ceph_argparse_witharg(args, i, &val, "--source-zones", (char*)NULL)) {
+      opt_zone_names = std::move(v);
+    } else if (ceph_argparse_witharg(args, i, &val, "--zone-ids", (char*)NULL)) {
+      opt_zone_ids = zone_ids_from_str(val);
+    } else if (ceph_argparse_witharg(args, i, &val, "--source-zones", "--source-zone-names", (char*)NULL)) {
       vector<string> v;
       get_str_vec(val, v);
-      opt_source_zones = std::move(v);
-    } else if (ceph_argparse_witharg(args, i, &val, "--dest-zones", (char*)NULL)) {
+      opt_source_zone_names = std::move(v);
+    } else if (ceph_argparse_witharg(args, i, &val, "--source-zone-ids", (char*)NULL)) {
+      opt_source_zone_ids = zone_ids_from_str(val);
+    } else if (ceph_argparse_witharg(args, i, &val, "--dest-zones", "--dest-zone-names", (char*)NULL)) {
       vector<string> v;
       get_str_vec(val, v);
-      opt_dest_zones = std::move(v);
+      opt_dest_zone_names = std::move(v);
+    } else if (ceph_argparse_witharg(args, i, &val, "--dest-zone-ids", (char*)NULL)) {
+      opt_dest_zone_ids = zone_ids_from_str(val);
     } else if (ceph_argparse_witharg(args, i, &val, "--flow-id", (char*)NULL)) {
       opt_flow_id = val;
     } else if (ceph_argparse_witharg(args, i, &val, "--pipe-id", (char*)NULL)) {
@@ -3516,8 +3568,10 @@ int main(int argc, const char **argv)
       opt_dest_bucket_name = val;
     } else if (ceph_argparse_witharg(args, i, &val, "--dest-bucket-id", (char*)NULL)) {
       opt_dest_bucket_id = val;
-    } else if (ceph_argparse_witharg(args, i, &val, "--effective-zone", (char*)NULL)) {
-      opt_effective_zone = val;
+    } else if (ceph_argparse_witharg(args, i, &val, "--effective-zone-name", "--effective-zone", (char*)NULL)) {
+      opt_effective_zone_name = val;
+    } else if (ceph_argparse_witharg(args, i, &val, "--effective-zone-id", (char*)NULL)) {
+      opt_effective_zone_id = rgw_zone_id(val);
     } else if (ceph_argparse_witharg(args, i, &val, "--prefix", (char*)NULL)) {
       opt_prefix = val;
     } else if (ceph_argparse_witharg(args, i, &val, "--prefix-rm", (char*)NULL)) {
@@ -3876,7 +3930,7 @@ int main(int argc, const char **argv)
           }
           if (remote.empty()) {
             // use realm master zone as remote
-            remote = current_period.get_master_zone();
+            remote = current_period.get_master_zone().id;
           }
           conn = get_remote_conn(store, current_period.get_map(), remote);
           if (!conn) {
@@ -5266,6 +5320,11 @@ int main(int argc, const char **argv)
     return 0;
   }
 
+  resolve_zone_id_opt(opt_effective_zone_name, opt_effective_zone_id);
+  resolve_zone_ids_opt(opt_zone_names, opt_zone_ids);
+  resolve_zone_ids_opt(opt_source_zone_names, opt_source_zone_ids);
+  resolve_zone_ids_opt(opt_dest_zone_names, opt_dest_zone_ids);
+
   bool non_master_cmd = (!store->svc()->zone->is_meta_master() && !yes_i_really_mean_it);
   std::set<OPT> non_master_ops_list = {OPT::USER_CREATE, OPT::USER_RM, 
                                         OPT::USER_MODIFY, OPT::USER_ENABLE,
@@ -7489,7 +7548,7 @@ next:
   }
 
   if (opt_cmd == OPT::SYNC_INFO) {
-    sync_info(opt_effective_zone, opt_bucket, formatter);
+    sync_info(opt_effective_zone_id, opt_bucket, formatter);
   }
 
   if (opt_cmd == OPT::SYNC_STATUS) {
@@ -8075,13 +8134,13 @@ next:
     auto& group = iter->second;
 
     if (symmetrical_flow_opt(*opt_flow_type)) {
-      CHECK_TRUE(require_non_empty_opt(opt_zones), "ERROR: --zones not provided for symmetrical flow, or is empty", EINVAL);
+      CHECK_TRUE(require_non_empty_opt(opt_zone_ids), "ERROR: --zones not provided for symmetrical flow, or is empty", EINVAL);
 
       rgw_sync_symmetric_group *flow_group;
 
       group.data_flow.find_symmetrical(*opt_flow_id, true, &flow_group);
 
-      for (auto& z : *opt_zones) {
+      for (auto& z : *opt_zone_ids) {
         flow_group->zones.insert(z);
       }
     } else { /* directional */
@@ -8125,7 +8184,7 @@ next:
     auto& group = iter->second;
 
     if (symmetrical_flow_opt(*opt_flow_type)) {
-      group.data_flow.remove_symmetrical(*opt_flow_id, opt_zones);
+      group.data_flow.remove_symmetrical(*opt_flow_id, opt_zone_ids);
     } else { /* directional */
       CHECK_TRUE(require_non_empty_opt(opt_source_zone), "ERROR: --source-zone not provided for directional flow rule, or is empty", EINVAL);
       CHECK_TRUE(require_non_empty_opt(opt_dest_zone), "ERROR: --dest-zone not provided for directional flow rule, or is empty", EINVAL);
@@ -8146,8 +8205,8 @@ next:
     CHECK_TRUE(require_opt(opt_group_id), "ERROR: --group-id not specified", EINVAL);
     CHECK_TRUE(require_opt(opt_pipe_id), "ERROR: --pipe-id not specified", EINVAL);
     if (opt_cmd == OPT::SYNC_GROUP_PIPE_CREATE) {
-      CHECK_TRUE(require_non_empty_opt(opt_source_zones), "ERROR: --source-zones not provided or is empty; should be list of zones or '*'", EINVAL);
-      CHECK_TRUE(require_non_empty_opt(opt_dest_zones), "ERROR: --dest-zones not provided or is empty; should be list of zones or '*'", EINVAL);
+      CHECK_TRUE(require_non_empty_opt(opt_source_zone_ids), "ERROR: --source-zones not provided or is empty; should be list of zones or '*'", EINVAL);
+      CHECK_TRUE(require_non_empty_opt(opt_dest_zone_ids), "ERROR: --dest-zones not provided or is empty; should be list of zones or '*'", EINVAL);
     }
 
     SyncPolicyContext sync_policy_ctx(zonegroup_id, zonegroup_name, opt_bucket);
@@ -8176,11 +8235,11 @@ next:
       }
     }
 
-    pipe->source.add_zones(*opt_source_zones);
+    pipe->source.add_zones(*opt_source_zone_ids);
     pipe->source.set_bucket(opt_source_tenant,
                             opt_source_bucket_name,
                             opt_source_bucket_id);
-    pipe->dest.add_zones(*opt_dest_zones);
+    pipe->dest.add_zones(*opt_dest_zone_ids);
     pipe->dest.set_bucket(opt_dest_tenant,
                             opt_dest_bucket_name,
                             opt_dest_bucket_id);
@@ -8225,25 +8284,25 @@ next:
       return ENOENT;
     }
 
-    if (opt_source_zones) {
-      pipe->source.remove_zones(*opt_source_zones);
+    if (opt_source_zone_ids) {
+      pipe->source.remove_zones(*opt_source_zone_ids);
     }
 
     pipe->source.remove_bucket(opt_source_tenant,
                                opt_source_bucket_name,
                                opt_source_bucket_id);
-    if (opt_dest_zones) {
-      pipe->dest.remove_zones(*opt_dest_zones);
+    if (opt_dest_zone_ids) {
+      pipe->dest.remove_zones(*opt_dest_zone_ids);
     }
     pipe->dest.remove_bucket(opt_dest_tenant,
                              opt_dest_bucket_name,
                              opt_dest_bucket_id);
 
-    if (!(opt_source_zones ||
+    if (!(opt_source_zone_ids ||
           opt_source_tenant ||
           opt_source_bucket ||
           opt_source_bucket_id ||
-          opt_dest_zones ||
+          opt_dest_zone_ids ||
           opt_dest_tenant ||
           opt_dest_bucket ||
           opt_dest_bucket_id)) {
index 4086f0c858b4ab67ed6ddeaef317b8c88ce37720..ac7aa7cf46c5cb028a510acaacd91f3303c77cd8 100644 (file)
@@ -3663,7 +3663,7 @@ int RGWBucketCtl::sync_user_stats(const rgw_user& user_id,
   return ctl.user->flush_bucket_stats(user_id, *pent);
 }
 
-int RGWBucketCtl::get_sync_policy_handler(std::optional<string> zone,
+int RGWBucketCtl::get_sync_policy_handler(std::optional<rgw_zone_id> zone,
                                           std::optional<rgw_bucket> bucket,
                                           RGWBucketSyncPolicyHandlerRef *phandler,
                                           optional_yield y)
index 50120cd6ebe5d258b7f2cf5b727af5b6c26c3d47..3190a56c4825cb41e3fec40b73457f11aa8c8422 100644 (file)
@@ -869,7 +869,7 @@ public:
                       RGWBucketEnt* pent = nullptr);
 
   /* bucket sync */
-  int get_sync_policy_handler(std::optional<string> zone,
+  int get_sync_policy_handler(std::optional<rgw_zone_id> zone,
                               std::optional<rgw_bucket> bucket,
                              RGWBucketSyncPolicyHandlerRef *phandler,
                              optional_yield y);
index 8ec6001bd03c0405ad1a58b7bd74a39b1ddc8873..fe0d5eb7e6f275b414b0555bcef3d5840d172faf 100644 (file)
@@ -12,7 +12,7 @@
 
 
 ostream& operator<<(ostream& os, const rgw_sync_bucket_entity& e) {
-  os << "{b=" << rgw_sync_bucket_entities::bucket_key(e.bucket) << ",z=" << e.zone.value_or("") << ",az=" << (int)e.all_zones << "}";
+  os << "{b=" << rgw_sync_bucket_entities::bucket_key(e.bucket) << ",z=" << e.zone.value_or(rgw_zone_id()) << ",az=" << (int)e.all_zones << "}";
   return os;
 }
 
@@ -22,7 +22,7 @@ ostream& operator<<(ostream& os, const rgw_sync_bucket_pipe& pipe) {
 }
 
 ostream& operator<<(ostream& os, const rgw_sync_bucket_entities& e) {
-  os << "{b=" << rgw_sync_bucket_entities::bucket_key(e.bucket) << ",z=" << e.zones.value_or(std::set<string>()) << "}";
+  os << "{b=" << rgw_sync_bucket_entities::bucket_key(e.bucket) << ",z=" << e.zones.value_or(std::set<rgw_zone_id>()) << "}";
   return os;
 }
 
@@ -32,8 +32,8 @@ ostream& operator<<(ostream& os, const rgw_sync_bucket_pipes& pipe) {
 }
 
 static std::vector<rgw_sync_bucket_pipe> filter_relevant_pipes(const std::vector<rgw_sync_bucket_pipes>& pipes,
-                                                               const string& source_zone,
-                                                               const string& dest_zone)
+                                                               const rgw_zone_id& source_zone,
+                                                               const rgw_zone_id& dest_zone)
 {
   std::vector<rgw_sync_bucket_pipe> relevant_pipes;
   for (auto& p : pipes) {
@@ -57,7 +57,7 @@ static bool is_wildcard_bucket(const rgw_bucket& bucket)
 
 void rgw_sync_group_pipe_map::dump(ceph::Formatter *f) const
 {
-  encode_json("zone", zone, f);
+  encode_json("zone", zone.id, f);
   encode_json("buckets", rgw_sync_bucket_entities::bucket_key(bucket), f);
   encode_json("sources", sources, f);
   encode_json("dests", dests, f);
@@ -65,8 +65,8 @@ void rgw_sync_group_pipe_map::dump(ceph::Formatter *f) const
 
 
 template <typename CB1, typename CB2>
-void rgw_sync_group_pipe_map::try_add_to_pipe_map(const string& source_zone,
-                                                  const string& dest_zone,
+void rgw_sync_group_pipe_map::try_add_to_pipe_map(const rgw_zone_id& source_zone,
+                                                  const rgw_zone_id& dest_zone,
                                                   const std::vector<rgw_sync_bucket_pipes>& pipes,
                                                   zb_pipe_map_t *pipe_map,
                                                   CB1 filter_cb,
@@ -87,8 +87,8 @@ void rgw_sync_group_pipe_map::try_add_to_pipe_map(const string& source_zone,
 }
           
 template <typename CB>
-void rgw_sync_group_pipe_map::try_add_source(const string& source_zone,
-                  const string& dest_zone,
+void rgw_sync_group_pipe_map::try_add_source(const rgw_zone_id& source_zone,
+                  const rgw_zone_id& dest_zone,
                   const std::vector<rgw_sync_bucket_pipes>& pipes,
                   CB filter_cb)
 {
@@ -102,8 +102,8 @@ void rgw_sync_group_pipe_map::try_add_source(const string& source_zone,
 }
 
 template <typename CB>
-void rgw_sync_group_pipe_map::try_add_dest(const string& source_zone,
-                                           const string& dest_zone,
+void rgw_sync_group_pipe_map::try_add_dest(const rgw_zone_id& source_zone,
+                                           const rgw_zone_id& dest_zone,
                                            const std::vector<rgw_sync_bucket_pipes>& pipes,
                                            CB filter_cb)
 {
@@ -119,7 +119,7 @@ void rgw_sync_group_pipe_map::try_add_dest(const string& source_zone,
 using zb_pipe_map_t = rgw_sync_group_pipe_map::zb_pipe_map_t;
 
 pair<zb_pipe_map_t::const_iterator, zb_pipe_map_t::const_iterator> rgw_sync_group_pipe_map::find_pipes(const zb_pipe_map_t& m,
-                                                                                                       const string& zone,
+                                                                                                       const rgw_zone_id& zone,
                                                                                                        std::optional<rgw_bucket> b) const
 {
   if (!b) {
@@ -141,11 +141,11 @@ pair<zb_pipe_map_t::const_iterator, zb_pipe_map_t::const_iterator> rgw_sync_grou
 
 
 template <typename CB>
-void rgw_sync_group_pipe_map::init(const string& _zone,
+void rgw_sync_group_pipe_map::init(const rgw_zone_id& _zone,
                                    std::optional<rgw_bucket> _bucket,
                                    const rgw_sync_policy_group& group,
                                    rgw_sync_data_flow_group *_default_flow,
-                                   std::set<std::string> *_pall_zones,
+                                   std::set<rgw_zone_id> *_pall_zones,
                                    CB filter_cb) {
   zone = _zone;
   bucket = _bucket;
@@ -212,7 +212,7 @@ void rgw_sync_group_pipe_map::init(const string& _zone,
 /*
  * find all relevant pipes in our zone that match {dest_bucket} <- {source_zone, source_bucket}
  */
-vector<rgw_sync_bucket_pipe> rgw_sync_group_pipe_map::find_source_pipes(const string& source_zone,
+vector<rgw_sync_bucket_pipe> rgw_sync_group_pipe_map::find_source_pipes(const rgw_zone_id& source_zone,
                                                                         std::optional<rgw_bucket> source_bucket,
                                                                         std::optional<rgw_bucket> dest_bucket) const {
   vector<rgw_sync_bucket_pipe> result;
@@ -233,7 +233,7 @@ vector<rgw_sync_bucket_pipe> rgw_sync_group_pipe_map::find_source_pipes(const st
  * source bucket in out zone {source_bucket} -> {dest_zone, dest_bucket}
  */
 vector<rgw_sync_bucket_pipe> rgw_sync_group_pipe_map::find_dest_pipes(std::optional<rgw_bucket> source_bucket,
-                                                                      const string& dest_zone,
+                                                                      const rgw_zone_id& dest_zone,
                                                                       std::optional<rgw_bucket> dest_bucket) const {
   vector<rgw_sync_bucket_pipe> result;
 
@@ -252,9 +252,9 @@ vector<rgw_sync_bucket_pipe> rgw_sync_group_pipe_map::find_dest_pipes(std::optio
 /*
  * find all relevant pipes from {source_zone, source_bucket} -> {dest_zone, dest_bucket}
  */
-vector<rgw_sync_bucket_pipe> rgw_sync_group_pipe_map::find_pipes(const string& source_zone,
+vector<rgw_sync_bucket_pipe> rgw_sync_group_pipe_map::find_pipes(const rgw_zone_id& source_zone,
                                                                  std::optional<rgw_bucket> source_bucket,
-                                                                 const string& dest_zone,
+                                                                 const rgw_zone_id& dest_zone,
                                                                  std::optional<rgw_bucket> dest_bucket) const {
   if (dest_zone == zone) {
     return find_source_pipes(source_zone, source_bucket, dest_bucket);
@@ -371,9 +371,9 @@ void RGWBucketSyncFlowManager::pipe_set::dump(ceph::Formatter *f) const
   encode_json("pipes", pipe_map, f);
 }
 
-bool RGWBucketSyncFlowManager::allowed_data_flow(const string& source_zone,
+bool RGWBucketSyncFlowManager::allowed_data_flow(const rgw_zone_id& source_zone,
                                                  std::optional<rgw_bucket> source_bucket,
-                                                 const string& dest_zone,
+                                                 const rgw_zone_id& dest_zone,
                                                  std::optional<rgw_bucket> dest_bucket,
                                                  bool check_activated) const
 {
@@ -422,12 +422,12 @@ void RGWBucketSyncFlowManager::init(const rgw_sync_policy_info& sync_policy) {
     auto& group = item.second;
     auto& flow_group_map = flow_groups[group.id];
 
-    flow_group_map.init(zone_name, bucket, group,
+    flow_group_map.init(zone_id, bucket, group,
                         (default_flow ? &(*default_flow) : nullptr),
                         &all_zones,
-                        [&](const string& source_zone,
+                        [&](const rgw_zone_id& source_zone,
                             std::optional<rgw_bucket> source_bucket,
-                            const string& dest_zone,
+                            const rgw_zone_id& dest_zone,
                             std::optional<rgw_bucket> dest_bucket) {
                         if (!parent) {
                           return true;
@@ -448,7 +448,7 @@ void RGWBucketSyncFlowManager::reflect(std::optional<rgw_bucket> effective_bucke
 
 {
   rgw_sync_bucket_entity entity;
-  entity.zone = zone_name;
+  entity.zone = zone_id;
   entity.bucket = effective_bucket.value_or(rgw_bucket());
 
   if (parent) {
@@ -492,9 +492,9 @@ void RGWBucketSyncFlowManager::reflect(std::optional<rgw_bucket> effective_bucke
 }
 
 
-RGWBucketSyncFlowManager::RGWBucketSyncFlowManager(const string& _zone_name,
+RGWBucketSyncFlowManager::RGWBucketSyncFlowManager(const rgw_zone_id& _zone_id,
                                                    std::optional<rgw_bucket> _bucket,
-                                                   const RGWBucketSyncFlowManager *_parent) : zone_name(_zone_name),
+                                                   const RGWBucketSyncFlowManager *_parent) : zone_id(_zone_id),
                                                                                               bucket(_bucket),
                                                                                               parent(_parent) {}
 
@@ -511,11 +511,11 @@ void RGWSyncPolicyCompat::convert_old_sync_config(RGWSI_Zone *zone_svc,
   auto& zonegroup = zone_svc->get_zonegroup();
 
   for (const auto& ziter1 : zonegroup.zones) {
-    const string& id1 = ziter1.first;
+    auto& id1 = ziter1.first;
     const RGWZone& z1 = ziter1.second;
 
     for (const auto& ziter2 : zonegroup.zones) {
-      const string& id2 = ziter2.first;
+      auto& id2 = ziter2.first;
       const RGWZone& z2 = ziter2.second;
 
       if (id1 == id2) {
@@ -525,7 +525,10 @@ void RGWSyncPolicyCompat::convert_old_sync_config(RGWSI_Zone *zone_svc,
       if (z1.syncs_from(z2.name)) {
         found = true;
         rgw_sync_directional_rule *rule;
-        group.data_flow.find_directional(z2.name, z1.name, true, &rule);
+        group.data_flow.find_directional(id2,
+                                         id1,
+                                         true,
+                                         &rule);
       }
     }
   }
@@ -550,10 +553,10 @@ void RGWSyncPolicyCompat::convert_old_sync_config(RGWSI_Zone *zone_svc,
 RGWBucketSyncPolicyHandler::RGWBucketSyncPolicyHandler(RGWSI_Zone *_zone_svc,
                                                        RGWSI_SyncModules *sync_modules_svc,
                                                       RGWSI_Bucket_Sync *_bucket_sync_svc,
-                                                       std::optional<string> effective_zone) : zone_svc(_zone_svc) ,
-                                                                                               bucket_sync_svc(_bucket_sync_svc) {
-  zone_name = effective_zone.value_or(zone_svc->zone_name());
-  flow_mgr.reset(new RGWBucketSyncFlowManager(zone_name,
+                                                       std::optional<rgw_zone_id> effective_zone) : zone_svc(_zone_svc) ,
+                                                                                                    bucket_sync_svc(_bucket_sync_svc) {
+  zone_id = effective_zone.value_or(zone_svc->zone_id());
+  flow_mgr.reset(new RGWBucketSyncFlowManager(zone_id,
                                               nullopt,
                                               nullptr));
   sync_policy = zone_svc->get_zonegroup().sync_policy;
@@ -572,7 +575,7 @@ RGWBucketSyncPolicyHandler::RGWBucketSyncPolicyHandler(const RGWBucketSyncPolicy
   bucket = _bucket_info.bucket;
   zone_svc = parent->zone_svc;
   bucket_sync_svc = parent->bucket_sync_svc;
-  flow_mgr.reset(new RGWBucketSyncFlowManager(parent->zone_name,
+  flow_mgr.reset(new RGWBucketSyncFlowManager(parent->zone_id,
                                               _bucket_info.bucket,
                                               parent->flow_mgr.get()));
 }
@@ -586,7 +589,7 @@ RGWBucketSyncPolicyHandler::RGWBucketSyncPolicyHandler(const RGWBucketSyncPolicy
   bucket = _bucket;
   zone_svc = parent->zone_svc;
   bucket_sync_svc = parent->bucket_sync_svc;
-  flow_mgr.reset(new RGWBucketSyncFlowManager(parent->zone_name,
+  flow_mgr.reset(new RGWBucketSyncFlowManager(parent->zone_id,
                                               _bucket,
                                               parent->flow_mgr.get()));
 }
@@ -616,8 +619,8 @@ int RGWBucketSyncPolicyHandler::init(optional_yield y)
 
   flow_mgr->init(sync_policy);
 
-  reflect(&sources_by_name,
-          &targets_by_name,
+  reflect(&source_pipes,
+          &target_pipes,
           &sources,
           &targets,
           &source_zones,
@@ -627,57 +630,46 @@ int RGWBucketSyncPolicyHandler::init(optional_yield y)
   return 0;
 }
 
-void RGWBucketSyncPolicyHandler::reflect(RGWBucketSyncFlowManager::pipe_set *psources_by_name,
-                                         RGWBucketSyncFlowManager::pipe_set *ptargets_by_name,
-                                         map<string, RGWBucketSyncFlowManager::pipe_set> *psources,
-                                         map<string, RGWBucketSyncFlowManager::pipe_set> *ptargets,
-                                         std::set<string> *psource_zones,
-                                         std::set<string> *ptarget_zones,
+void RGWBucketSyncPolicyHandler::reflect(RGWBucketSyncFlowManager::pipe_set *psource_pipes,
+                                         RGWBucketSyncFlowManager::pipe_set *ptarget_pipes,
+                                         map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set> *psources,
+                                         map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set> *ptargets,
+                                         std::set<rgw_zone_id> *psource_zones,
+                                         std::set<rgw_zone_id> *ptarget_zones,
                                          bool only_enabled) const
 {
-  RGWBucketSyncFlowManager::pipe_set _sources_by_name;
-  RGWBucketSyncFlowManager::pipe_set _targets_by_name;
-  map<string, RGWBucketSyncFlowManager::pipe_set> _sources;
-  map<string, RGWBucketSyncFlowManager::pipe_set> _targets;
-  std::set<string> _source_zones;
-  std::set<string> _target_zones;
+  RGWBucketSyncFlowManager::pipe_set _source_pipes;
+  RGWBucketSyncFlowManager::pipe_set _target_pipes;
+  map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set> _sources;
+  map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set> _targets;
+  std::set<rgw_zone_id> _source_zones;
+  std::set<rgw_zone_id> _target_zones;
 
-  flow_mgr->reflect(bucket, &_sources_by_name, &_targets_by_name, only_enabled);
+  flow_mgr->reflect(bucket, &_source_pipes, &_target_pipes, only_enabled);
 
-  for (auto& entry : _sources_by_name.pipe_map) {
+  for (auto& entry : _source_pipes.pipe_map) {
     auto& pipe = entry.second;
     if (!pipe.source.zone) {
       continue;
     }
     _source_zones.insert(*pipe.source.zone);
-    rgw_sync_bucket_pipe new_pipe = pipe;
-    string zone_id;
-
-    if (zone_svc->find_zone_id_by_name(*pipe.source.zone, &zone_id)) {
-      new_pipe.source.zone = zone_id;
-    }
-    _sources[*new_pipe.source.zone].insert(new_pipe);
+    _sources[*pipe.source.zone].insert(pipe);
   }
 
-  for (auto& entry : _targets_by_name.pipe_map) {
+  for (auto& entry : _target_pipes.pipe_map) {
     auto& pipe = entry.second;
     if (!pipe.dest.zone) {
       continue;
     }
     _target_zones.insert(*pipe.dest.zone);
-    rgw_sync_bucket_pipe new_pipe = pipe;
-    string zone_id;
-    if (zone_svc->find_zone_id_by_name(*pipe.dest.zone, &zone_id)) {
-      new_pipe.dest.zone = zone_id;
-    }
-    _targets[*new_pipe.dest.zone].insert(new_pipe);
+    _targets[*pipe.dest.zone].insert(pipe);
   }
 
-  if (psources_by_name) {
-    *psources_by_name = std::move(_sources_by_name);
+  if (psource_pipes) {
+    *psource_pipes = std::move(_source_pipes);
   }
-  if (ptargets_by_name) {
-    *ptargets_by_name = std::move(_targets_by_name);
+  if (ptarget_pipes) {
+    *ptarget_pipes = std::move(_target_pipes);
   }
   if (psources) {
     *psources = std::move(_sources);
@@ -693,21 +685,21 @@ void RGWBucketSyncPolicyHandler::reflect(RGWBucketSyncFlowManager::pipe_set *pso
   }
 }
 
-void RGWBucketSyncPolicyHandler::get_pipes(std::set<rgw_sync_bucket_pipe> *sources, std::set<rgw_sync_bucket_pipe> *targets,
-                                          std::optional<rgw_sync_bucket_entity> filter_peer) { /* return raw pipes (with zone name) */
-  for (auto& entry : sources_by_name.pipe_map) {
+void RGWBucketSyncPolicyHandler::get_pipes(std::set<rgw_sync_bucket_pipe> *_sources, std::set<rgw_sync_bucket_pipe> *_targets,
+                                           std::optional<rgw_sync_bucket_entity> filter_peer) { /* return raw pipes */
+  for (auto& entry : source_pipes.pipe_map) {
     auto& source_pipe = entry.second;
     if (!filter_peer ||
         source_pipe.source.match(*filter_peer)) {
-      sources->insert(source_pipe);
+      _sources->insert(source_pipe);
     }
   }
 
-  for (auto& entry : targets_by_name.pipe_map) {
+  for (auto& entry : target_pipes.pipe_map) {
     auto& target_pipe = entry.second;
     if (!filter_peer ||
         target_pipe.dest.match(*filter_peer)) {
-      targets->insert(target_pipe);
+      _targets->insert(target_pipe);
     }
   }
 }
index 8f8ea1cb32d2527c51293411ac934dbf75b7af34..ceb1c14b90951a171e21ea0d6f361b89d240e71a 100644 (file)
@@ -28,7 +28,7 @@ struct rgw_sync_bucket_pipes;
 struct rgw_sync_policy_info;
 
 struct rgw_sync_group_pipe_map {
-  string zone;
+  rgw_zone_id zone;
   std::optional<rgw_bucket> bucket;
 
   rgw_sync_policy_group::Status status{rgw_sync_policy_group::Status::FORBIDDEN};
@@ -38,7 +38,7 @@ struct rgw_sync_group_pipe_map {
   zb_pipe_map_t sources; /* all the pipes where zone is pulling from */
   zb_pipe_map_t dests; /* all the pipes that pull from zone */
 
-  std::set<string> *pall_zones{nullptr};
+  std::set<rgw_zone_id> *pall_zones{nullptr};
   rgw_sync_data_flow_group *default_flow{nullptr}; /* flow to use if policy doesn't define it,
                                                       used in the case of bucket sync policy, not at the
                                                       zonegroup level */
@@ -46,41 +46,41 @@ struct rgw_sync_group_pipe_map {
   void dump(ceph::Formatter *f) const;
 
   template <typename CB1, typename CB2>
-  void try_add_to_pipe_map(const string& source_zone,
-                           const string& dest_zone,
+  void try_add_to_pipe_map(const rgw_zone_id& source_zone,
+                           const rgw_zone_id& dest_zone,
                            const std::vector<rgw_sync_bucket_pipes>& pipes,
                            zb_pipe_map_t *pipe_map,
                            CB1 filter_cb,
                            CB2 call_filter_cb);
           
   template <typename CB>
-  void try_add_source(const string& source_zone,
-                      const string& dest_zone,
+  void try_add_source(const rgw_zone_id& source_zone,
+                      const rgw_zone_id& dest_zone,
                       const std::vector<rgw_sync_bucket_pipes>& pipes,
                       CB filter_cb);
           
   template <typename CB>
-  void try_add_dest(const string& source_zone,
-                  const string& dest_zone,
+  void try_add_dest(const rgw_zone_id& source_zone,
+                  const rgw_zone_id& dest_zone,
                   const std::vector<rgw_sync_bucket_pipes>& pipes,
                   CB filter_cb);
           
   pair<zb_pipe_map_t::const_iterator, zb_pipe_map_t::const_iterator> find_pipes(const zb_pipe_map_t& m,
-                                                                                const string& zone,
+                                                                                const rgw_zone_id& zone,
                                                                                 std::optional<rgw_bucket> b) const;
 
   template <typename CB>
-  void init(const string& _zone,
+  void init(const rgw_zone_id& _zone,
             std::optional<rgw_bucket> _bucket,
             const rgw_sync_policy_group& group,
             rgw_sync_data_flow_group *_default_flow,
-            std::set<std::string> *_pall_zones,
+            std::set<rgw_zone_id> *_pall_zones,
             CB filter_cb);
 
   /*
    * find all relevant pipes in our zone that match {dest_bucket} <- {source_zone, source_bucket}
    */
-  vector<rgw_sync_bucket_pipe> find_source_pipes(const string& source_zone,
+  vector<rgw_sync_bucket_pipe> find_source_pipes(const rgw_zone_id& source_zone,
                                                  std::optional<rgw_bucket> source_bucket,
                                                  std::optional<rgw_bucket> dest_bucket) const;
 
@@ -89,15 +89,15 @@ struct rgw_sync_group_pipe_map {
    * source bucket in out zone {source_bucket} -> {dest_zone, dest_bucket}
    */
   vector<rgw_sync_bucket_pipe> find_dest_pipes(std::optional<rgw_bucket> source_bucket,
-                                               const string& dest_zone,
+                                               const rgw_zone_id& dest_zone,
                                                std::optional<rgw_bucket> dest_bucket) const;
 
   /*
    * find all relevant pipes from {source_zone, source_bucket} -> {dest_zone, dest_bucket}
    */
-  vector<rgw_sync_bucket_pipe> find_pipes(const string& source_zone,
+  vector<rgw_sync_bucket_pipe> find_pipes(const rgw_zone_id& source_zone,
                                           std::optional<rgw_bucket> source_bucket,
-                                          const string& dest_zone,
+                                          const rgw_zone_id& dest_zone,
                                           std::optional<rgw_bucket> dest_bucket) const;
 };
 
@@ -216,18 +216,18 @@ public:
 
 private:
 
-  string zone_name;
+  rgw_zone_id zone_id;
   std::optional<rgw_bucket> bucket;
 
   const RGWBucketSyncFlowManager *parent{nullptr};
 
   map<string, rgw_sync_group_pipe_map> flow_groups;
 
-  std::set<std::string> all_zones;
+  std::set<rgw_zone_id> all_zones;
 
-  bool allowed_data_flow(const string& source_zone,
+  bool allowed_data_flow(const rgw_zone_id& source_zone,
                          std::optional<rgw_bucket> source_bucket,
-                         const string& dest_zone,
+                         const rgw_zone_id& dest_zone,
                          std::optional<rgw_bucket> dest_bucket,
                          bool check_activated) const;
 
@@ -240,7 +240,7 @@ private:
 
 public:
 
-  RGWBucketSyncFlowManager(const string& _zone_name,
+  RGWBucketSyncFlowManager(const rgw_zone_id& _zone_id,
                            std::optional<rgw_bucket> _bucket,
                            const RGWBucketSyncFlowManager *_parent);
 
@@ -260,20 +260,20 @@ class RGWBucketSyncPolicyHandler {
   const RGWBucketSyncPolicyHandler *parent{nullptr};
   RGWSI_Zone *zone_svc;
   RGWSI_Bucket_Sync *bucket_sync_svc;
-  string zone_name;
+  rgw_zone_id zone_id;
   std::optional<RGWBucketInfo> bucket_info;
   std::optional<rgw_bucket> bucket;
   std::unique_ptr<RGWBucketSyncFlowManager> flow_mgr;
   rgw_sync_policy_info sync_policy;
 
-  RGWBucketSyncFlowManager::pipe_set sources_by_name;
-  RGWBucketSyncFlowManager::pipe_set targets_by_name;
+  RGWBucketSyncFlowManager::pipe_set source_pipes;
+  RGWBucketSyncFlowManager::pipe_set target_pipes;
 
-  map<string, RGWBucketSyncFlowManager::pipe_set> sources; /* source pipes by source zone id */
-  map<string, RGWBucketSyncFlowManager::pipe_set> targets; /* target pipes by target zone id */
+  map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set> sources; /* source pipes by source zone id */
+  map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set> targets; /* target pipes by target zone id */
 
-  std::set<string> source_zones; /* source zones by name */
-  std::set<string> target_zones; /* target zones by name */
+  std::set<rgw_zone_id> source_zones;
+  std::set<rgw_zone_id> target_zones;
 
   std::set<rgw_bucket> source_hints;
   std::set<rgw_bucket> target_hints;
@@ -299,7 +299,7 @@ public:
   RGWBucketSyncPolicyHandler(RGWSI_Zone *_zone_svc,
                              RGWSI_SyncModules *sync_modules_svc,
                             RGWSI_Bucket_Sync *bucket_sync_svc,
-                             std::optional<string> effective_zone = std::nullopt);
+                             std::optional<rgw_zone_id> effective_zone = std::nullopt);
 
   RGWBucketSyncPolicyHandler *alloc_child(const RGWBucketInfo& bucket_info) const;
   RGWBucketSyncPolicyHandler *alloc_child(const rgw_bucket& bucket,
@@ -307,12 +307,12 @@ public:
 
   int init(optional_yield y);
 
-  void reflect(RGWBucketSyncFlowManager::pipe_set *psources_by_name,
-               RGWBucketSyncFlowManager::pipe_set *ptargets_by_name,
-               map<string, RGWBucketSyncFlowManager::pipe_set> *psources,
-               map<string, RGWBucketSyncFlowManager::pipe_set> *ptargets,
-               std::set<string> *psource_zones,
-               std::set<string> *ptarget_zones,
+  void reflect(RGWBucketSyncFlowManager::pipe_set *psource_pipes,
+               RGWBucketSyncFlowManager::pipe_set *ptarget_pipes,
+               map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set> *psources,
+               map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set> *ptargets,
+               std::set<rgw_zone_id> *psource_zones,
+               std::set<rgw_zone_id> *ptarget_zones,
                bool only_enabled) const;
 
   void set_resolved_hints(std::set<rgw_sync_bucket_pipe>&& _resolved_sources,
@@ -329,19 +329,19 @@ public:
     return resolved_dests;
   }
 
-  const std::set<string>& get_source_zones() const {
+  const std::set<rgw_zone_id>& get_source_zones() const {
     return source_zones;
   }
 
-  const std::set<string>& get_target_zones() const {
+  const std::set<rgw_zone_id>& get_target_zones() const {
     return target_zones;
   }
 
-  const  map<string, RGWBucketSyncFlowManager::pipe_set>& get_sources() {
+  const  map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set>& get_sources() {
     return sources;
   }
 
-  const  map<string, RGWBucketSyncFlowManager::pipe_set>& get_targets() {
+  const  map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set>& get_targets() {
     return targets;
   }
 
@@ -349,9 +349,9 @@ public:
     return bucket_info;
   }
 
-  void get_pipes(RGWBucketSyncFlowManager::pipe_set **sources, RGWBucketSyncFlowManager::pipe_set **targets) { /* return raw pipes (with zone name) */
-    *sources = &sources_by_name;
-    *targets = &targets_by_name;
+  void get_pipes(RGWBucketSyncFlowManager::pipe_set **_sources, RGWBucketSyncFlowManager::pipe_set **_targets) { /* return raw pipes (with zone name) */
+    *_sources = &source_pipes;
+    *_targets = &target_pipes;
   }
   void get_pipes(std::set<rgw_sync_bucket_pipe> *sources, std::set<rgw_sync_bucket_pipe> *targets,
                  std::optional<rgw_sync_bucket_entity> filter_peer);
index 4d8af33f3cc1bc7e3337cb8d0816e15fed32c8e2..7e9cfb8e0a5344f7e1fe84293387d126a3ceeb08 100644 (file)
@@ -2065,3 +2065,13 @@ bool RGWBucketInfo::empty_sync_policy() const
   return sync_policy->empty();
 }
 
+void encode_json(const char *name, const rgw_zone_id& zid, Formatter *f)
+{
+  encode_json(name, zid.id, f);
+}
+
+void decode_json_obj(rgw_zone_id& zid, JSONObj *obj)
+{
+  decode_json_obj(zid.id, obj);
+}
+
index 0df1d90ec15b318fe228356e8e4788a4bcb0eba6..2aa72159ba5540f5f816886a4a21dd771490a74a 100644 (file)
@@ -2662,4 +2662,70 @@ int decode_bl(bufferlist& bl, T& t)
   return 0;
 }
 
+/*
+ * should avoid encoding rgw_opt_zone_nid, and rgw_zone_nid,
+ * these should be used for run time representation of zone,
+ * but internally we should keep zone ids
+ */
+struct rgw_opt_zone_nid {
+  std::optional<string> id;
+  std::optional<string> name;
+};
+
+struct rgw_zone_nid {
+  string id;
+  string name;
+};
+
+struct rgw_zone_id {
+  string id;
+
+  rgw_zone_id() {}
+  rgw_zone_id(const string& _id) : id(_id) {}
+  rgw_zone_id(string&& _id) : id(std::move(_id)) {}
+
+  void encode(bufferlist& bl) const {
+    /* backward compatiblity, not using ENCODE_{START,END} macros */
+    ceph::encode(id, bl);
+  }
+
+  void decode(bufferlist::const_iterator& bl) {
+    /* backward compatiblity, not using DECODE_{START,END} macros */
+    ceph::decode(id, bl);
+  }
+
+  void clear() {
+    id.clear();
+  }
+
+  bool operator==(const string& _id) const {
+    return (id == _id);
+  }
+  bool operator==(const rgw_zone_id& zid) const {
+    return (id == zid.id);
+  }
+  bool operator!=(const rgw_zone_id& zid) const {
+    return (id != zid.id);
+  }
+  bool operator<(const rgw_zone_id& zid) const {
+    return (id < zid.id);
+  }
+  bool operator>(const rgw_zone_id& zid) const {
+    return (id > zid.id);
+  }
+
+  bool empty() const {
+    return id.empty();
+  }
+};
+WRITE_CLASS_ENCODER(rgw_zone_id)
+
+static inline ostream& operator<<(ostream& os, const rgw_zone_id& zid) {
+  os << zid.id;
+  return os;
+}
+
+void encode_json(const char *name, const rgw_zone_id& zid, Formatter *f);
+void decode_json_obj(rgw_zone_id& zid, JSONObj *obj);
+
 #endif
index 63109879cb20a3725c301e4cd1b5244560d52d2f..5b689e6d493d76753b1668030f4cd0e2a043e638 100644 (file)
@@ -918,7 +918,7 @@ class RGWRadosBILogTrimCR : public RGWSimpleCoroutine {
 
 class RGWAsyncFetchRemoteObj : public RGWAsyncRadosRequest {
   rgw::sal::RGWRadosStore *store;
-  string source_zone;
+  rgw_zone_id source_zone;
 
   rgw_bucket src_bucket;
   std::optional<rgw_placement_rule> dest_placement_rule;
@@ -939,7 +939,7 @@ protected:
   int _send_request() override;
 public:
   RGWAsyncFetchRemoteObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, rgw::sal::RGWRadosStore *_store,
-                         const string& _source_zone,
+                         const rgw_zone_id& _source_zone,
                          const rgw_bucket& _src_bucket,
                         std::optional<rgw_placement_rule> _dest_placement_rule,
                          const RGWBucketInfo& _dest_bucket_info,
@@ -969,7 +969,7 @@ class RGWFetchRemoteObjCR : public RGWSimpleCoroutine {
   CephContext *cct;
   RGWAsyncRadosProcessor *async_rados;
   rgw::sal::RGWRadosStore *store;
-  string source_zone;
+  rgw_zone_id source_zone;
 
   rgw_bucket src_bucket;
   std::optional<rgw_placement_rule> dest_placement_rule;
@@ -990,7 +990,7 @@ class RGWFetchRemoteObjCR : public RGWSimpleCoroutine {
 
 public:
   RGWFetchRemoteObjCR(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RGWRadosStore *_store,
-                      const string& _source_zone,
+                      const rgw_zone_id& _source_zone,
                       const rgw_bucket& _src_bucket,
                      std::optional<rgw_placement_rule> _dest_placement_rule,
                       const RGWBucketInfo& _dest_bucket_info,
@@ -1039,7 +1039,7 @@ public:
 
 class RGWAsyncStatRemoteObj : public RGWAsyncRadosRequest {
   rgw::sal::RGWRadosStore *store;
-  string source_zone;
+  rgw_zone_id source_zone;
 
   rgw_bucket src_bucket;
   rgw_obj_key key;
@@ -1054,7 +1054,7 @@ protected:
   int _send_request() override;
 public:
   RGWAsyncStatRemoteObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, rgw::sal::RGWRadosStore *_store,
-                         const string& _source_zone,
+                         const rgw_zone_id& _source_zone,
                          rgw_bucket& _src_bucket,
                          const rgw_obj_key& _key,
                          ceph::real_time *_pmtime,
@@ -1076,7 +1076,7 @@ class RGWStatRemoteObjCR : public RGWSimpleCoroutine {
   CephContext *cct;
   RGWAsyncRadosProcessor *async_rados;
   rgw::sal::RGWRadosStore *store;
-  string source_zone;
+  rgw_zone_id source_zone;
 
   rgw_bucket src_bucket;
   rgw_obj_key key;
@@ -1091,7 +1091,7 @@ class RGWStatRemoteObjCR : public RGWSimpleCoroutine {
 
 public:
   RGWStatRemoteObjCR(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RGWRadosStore *_store,
-                      const string& _source_zone,
+                      const rgw_zone_id& _source_zone,
                       rgw_bucket& _src_bucket,
                       const rgw_obj_key& _key,
                       ceph::real_time *_pmtime,
@@ -1136,7 +1136,7 @@ public:
 
 class RGWAsyncRemoveObj : public RGWAsyncRadosRequest {
   rgw::sal::RGWRadosStore *store;
-  string source_zone;
+  rgw_zone_id source_zone;
 
   RGWBucketInfo bucket_info;
 
@@ -1155,7 +1155,7 @@ protected:
   int _send_request() override;
 public:
   RGWAsyncRemoveObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, rgw::sal::RGWRadosStore *_store,
-                         const string& _source_zone,
+                         const rgw_zone_id& _source_zone,
                          RGWBucketInfo& _bucket_info,
                          const rgw_obj_key& _key,
                          const string& _owner,
@@ -1189,7 +1189,7 @@ class RGWRemoveObjCR : public RGWSimpleCoroutine {
   CephContext *cct;
   RGWAsyncRadosProcessor *async_rados;
   rgw::sal::RGWRadosStore *store;
-  string source_zone;
+  rgw_zone_id source_zone;
 
   RGWBucketInfo bucket_info;
 
@@ -1209,7 +1209,7 @@ class RGWRemoveObjCR : public RGWSimpleCoroutine {
 
 public:
   RGWRemoveObjCR(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RGWRadosStore *_store,
-                      const string& _source_zone,
+                      const rgw_zone_id& _source_zone,
                       RGWBucketInfo& _bucket_info,
                       const rgw_obj_key& _key,
                       bool _versioned,
index ccbd4a4d0ffd26a82511ee8b279a084e6764464d..28bee86ef4bf02db85fdb14fb78c8ac86678544f 100644 (file)
@@ -76,7 +76,7 @@ struct rgw_bucket_lifecycle_config_params {
 using RGWBucketLifecycleConfigCR = RGWSimpleWriteOnlyAsyncCR<rgw_bucket_lifecycle_config_params>;
 
 struct rgw_bucket_get_sync_policy_params {
-  std::optional<string> zone;
+  std::optional<rgw_zone_id> zone;
   std::optional<rgw_bucket> bucket;
 };
 
index 385d84c66c762382046faadd6b68f5aa41a3c034..e0665db88118ecd4f7a350556e78fd26f05c13c0 100644 (file)
@@ -533,7 +533,7 @@ public:
 
       /* fetch current position in logs */
       yield {
-        RGWRESTConn *conn = sync_env->svc->zone->get_zone_conn_by_id(sc->source_zone);
+        RGWRESTConn *conn = sync_env->svc->zone->get_zone_conn(sc->source_zone);
         if (!conn) {
           tn->log(0, SSTR("ERROR: connection to zone " << sc->source_zone << " does not exist!"));
           return set_cr_error(-EIO);
@@ -631,7 +631,7 @@ int RGWRemoteDataLog::read_source_log_shards_next(map<int, string> shard_markers
   return run(new RGWListRemoteDataLogCR(&sc, shard_markers, 1, result));
 }
 
-int RGWRemoteDataLog::init(const string& _source_zone, RGWRESTConn *_conn, RGWSyncErrorLogger *_error_logger,
+int RGWRemoteDataLog::init(const rgw_zone_id& _source_zone, RGWRESTConn *_conn, RGWSyncErrorLogger *_error_logger,
                            RGWSyncTraceManager *_sync_tracer, RGWSyncModuleInstanceRef& _sync_module,
                            PerfCounters* counters)
 {
@@ -738,10 +738,10 @@ int RGWRemoteDataLog::init_sync_status(int num_shards)
   return ret;
 }
 
-static string full_data_sync_index_shard_oid(const string& source_zone, int shard_id)
+static string full_data_sync_index_shard_oid(const rgw_zone_id& source_zone, int shard_id)
 {
-  char buf[datalog_sync_full_sync_index_prefix.size() + 1 + source_zone.size() + 1 + 16];
-  snprintf(buf, sizeof(buf), "%s.%s.%d", datalog_sync_full_sync_index_prefix.c_str(), source_zone.c_str(), shard_id);
+  char buf[datalog_sync_full_sync_index_prefix.size() + 1 + source_zone.id.size() + 1 + 16];
+  snprintf(buf, sizeof(buf), "%s.%s.%d", datalog_sync_full_sync_index_prefix.c_str(), source_zone.id.c_str(), shard_id);
   return string(buf);
 }
 
@@ -810,7 +810,7 @@ public:
                          rgw_data_sync_status *_sync_status) : RGWCoroutine(_sc->cct), sc(_sc), sync_env(_sc->env),
                                                       store(sync_env->store), sync_status(_sync_status),
                                                      req_ret(0), ret(0), entries_index(NULL), i(0), failed(false), truncated(false) {
-    oid_prefix = datalog_sync_full_sync_index_prefix + "." + sc->source_zone; 
+    oid_prefix = datalog_sync_full_sync_index_prefix + "." + sc->source_zone.id
     path = "/admin/metadata/bucket.instance";
     num_shards = sync_status->sync_info.num_shards;
   }
@@ -1054,7 +1054,7 @@ private:
   bool _has_bucket_info{false};
 
 public:
-  string zone;
+  rgw_zone_id zone;
 
   rgw_sync_pipe_info_entity() {}
   rgw_sync_pipe_info_entity(const rgw_sync_bucket_entity& e,
@@ -1245,7 +1245,7 @@ class RGWRunBucketSourcesSyncCR : public RGWCoroutine {
   RGWDataSyncCtx *cur_sc{nullptr};
 
   RGWRESTConn *conn{nullptr};
-  string last_zone;
+  rgw_zone_id last_zone;
 
   int ret{0};
 
@@ -2158,7 +2158,7 @@ int RGWDataSyncStatusManager::init()
 {
   RGWZone *zone_def;
 
-  if (!store->svc()->zone->find_zone_by_id(source_zone, &zone_def)) {
+  if (!store->svc()->zone->find_zone(source_zone, &zone_def)) {
     ldpp_dout(this, 0) << "ERROR: failed to find zone config info for zone=" << source_zone << dendl;
     return -EIO;
   }
@@ -2173,7 +2173,7 @@ int RGWDataSyncStatusManager::init()
     sync_module = store->getRados()->get_sync_module();
   }
 
-  conn = store->svc()->zone->get_zone_conn_by_id(source_zone);
+  conn = store->svc()->zone->get_zone_conn(source_zone);
   if (!conn) {
     ldpp_dout(this, 0) << "connection object to zone " << source_zone << " does not exist" << dendl;
     return -EINVAL;
@@ -2219,22 +2219,22 @@ unsigned RGWDataSyncStatusManager::get_subsys() const
 
 std::ostream& RGWDataSyncStatusManager::gen_prefix(std::ostream& out) const
 {
-  auto zone = std::string_view{source_zone};
+  auto zone = std::string_view{source_zone.id};
   return out << "data sync zone:" << zone.substr(0, 8) << ' ';
 }
 
-string RGWDataSyncStatusManager::sync_status_oid(const string& source_zone)
+string RGWDataSyncStatusManager::sync_status_oid(const rgw_zone_id& source_zone)
 {
-  char buf[datalog_sync_status_oid_prefix.size() + source_zone.size() + 16];
-  snprintf(buf, sizeof(buf), "%s.%s", datalog_sync_status_oid_prefix.c_str(), source_zone.c_str());
+  char buf[datalog_sync_status_oid_prefix.size() + source_zone.id.size() + 16];
+  snprintf(buf, sizeof(buf), "%s.%s", datalog_sync_status_oid_prefix.c_str(), source_zone.id.c_str());
 
   return string(buf);
 }
 
-string RGWDataSyncStatusManager::shard_obj_name(const string& source_zone, int shard_id)
+string RGWDataSyncStatusManager::shard_obj_name(const rgw_zone_id& source_zone, int shard_id)
 {
-  char buf[datalog_sync_status_shard_prefix.size() + source_zone.size() + 16];
-  snprintf(buf, sizeof(buf), "%s.%s.%d", datalog_sync_status_shard_prefix.c_str(), source_zone.c_str(), shard_id);
+  char buf[datalog_sync_status_shard_prefix.size() + source_zone.id.size() + 16];
+  snprintf(buf, sizeof(buf), "%s.%s.%d", datalog_sync_status_shard_prefix.c_str(), source_zone.id.c_str(), shard_id);
 
   return string(buf);
 }
@@ -2335,7 +2335,7 @@ public:
 
 RGWRemoteBucketManager::RGWRemoteBucketManager(const DoutPrefixProvider *_dpp,
                                                RGWDataSyncEnv *_sync_env,
-                                               const string& _source_zone,
+                                               const rgw_zone_id& _source_zone,
                                                RGWRESTConn *_conn,
                                                const RGWBucketInfo& source_bucket_info,
                                                const rgw_bucket& dest_bucket) : dpp(_dpp), sync_env(_sync_env)
@@ -2655,7 +2655,7 @@ RGWCoroutine *RGWRemoteBucketManager::read_sync_status_cr(int num, rgw_bucket_sh
 }
 
 RGWBucketPipeSyncStatusManager::RGWBucketPipeSyncStatusManager(rgw::sal::RGWRadosStore *_store,
-                                                               std::optional<string> _source_zone,
+                                                               std::optional<rgw_zone_id> _source_zone,
                                                                std::optional<rgw_bucket> _source_bucket,
                                                                const rgw_bucket& _dest_bucket) : store(_store),
                                                                                    cr_mgr(_store->ctx(), _store->getRados()->get_cr_registry()),
@@ -3203,7 +3203,7 @@ public:
       status_oid(status_oid),
       tn(sync_env->sync_tracer->add_node(tn_parent, "full_sync",
                                          SSTR(bucket_shard_str{bs}))) {
-    zones_trace.insert(sc->source_zone, sync_pipe.info.dest_bs.bucket.get_key());
+    zones_trace.insert(sc->source_zone.id, sync_pipe.info.dest_bs.bucket.get_key());
     marker_tracker.set_tn(tn);
     prefix_handler.set_rules(sync_pipe.get_rules());
   }
@@ -3348,7 +3348,7 @@ class RGWBucketShardIncrementalSyncCR : public RGWCoroutine {
   RGWBucketIncSyncShardMarkerTrack marker_tracker;
   bool updated_status{false};
   const string& status_oid;
-  const string& zone_id;
+  rgw_zone_id zone_id;
   string target_location_key;
 
   string cur_id;
@@ -3434,7 +3434,7 @@ int RGWBucketShardIncrementalSyncCR::operate()
         if (e.state != CLS_RGW_STATE_COMPLETE) {
           continue;
         }
-        if (e.zones_trace.exists(zone_id, target_location_key)) {
+        if (e.zones_trace.exists(zone_id.id, target_location_key)) {
           continue;
         }
         auto& squash_entry = squash_map[make_pair(e.object, e.instance)];
@@ -3508,7 +3508,7 @@ int RGWBucketShardIncrementalSyncCR::operate()
           marker_tracker.try_update_high_marker(cur_id, 0, entry->timestamp);
           continue;
         }
-        if (entry->zones_trace.exists(zone_id, target_location_key)) {
+        if (entry->zones_trace.exists(zone_id.id, target_location_key)) {
           set_status() << "redundant operation, skipping";
           tn->log(20, SSTR("skipping object: "
               <<bucket_shard_str{bs} <<"/"<<key<<": redundant operation"));
@@ -3629,66 +3629,11 @@ int RGWBucketShardIncrementalSyncCR::operate()
   return 0;
 }
 
-struct rgw_bucket_sync_source_local_info {
-  string id;
-  string type;
-  string zone;
-  rgw_bucket bucket;
-  /* FIXME: config */
-
-  void encode(bufferlist& bl) const {
-    ENCODE_START(1, 1, bl);
-    encode(id, bl);
-    encode(type, bl);
-    encode(zone, bl);
-    encode(bucket, bl);
-    ENCODE_FINISH(bl);
-  }
-
-  void decode(bufferlist::const_iterator& bl) {
-    DECODE_START(1, bl);
-    decode(id, bl);
-    decode(type, bl);
-    decode(zone, bl);
-    decode(bucket, bl);
-    DECODE_FINISH(bl);
-  }
-  void dump(ceph::Formatter *f) const {
-    encode_json("id", id, f);
-    encode_json("type", type, f);
-    encode_json("zone", zone, f);
-    encode_json("bucket", bucket, f);
-  }
-};
-WRITE_CLASS_ENCODER(rgw_bucket_sync_source_local_info)
-
-struct rgw_bucket_sync_sources_local_info {
-  map<string, rgw_bucket_sync_source_local_info> sources; /* id -> source */
-
-  void encode(bufferlist& bl) const {
-    ENCODE_START(1, 1, bl);
-    encode(sources, bl);
-    ENCODE_FINISH(bl);
-  }
-
-  void decode(bufferlist::const_iterator& bl) {
-    DECODE_START(1, bl);
-    decode(sources, bl);
-    DECODE_FINISH(bl);
-  }
-
-  void dump(ceph::Formatter *f) const {
-    encode_json("sources", sources, f);
-  }
-};
-WRITE_CLASS_ENCODER(rgw_bucket_sync_sources_local_info)
-
-
 class RGWGetBucketPeersCR : public RGWCoroutine {
   RGWDataSyncEnv *sync_env;
 
   std::optional<rgw_bucket> target_bucket;
-  std::optional<string> source_zone;
+  std::optional<rgw_zone_id> source_zone;
   std::optional<rgw_bucket> source_bucket;
 
   rgw_sync_pipe_info_set *pipes;
@@ -3705,9 +3650,9 @@ class RGWGetBucketPeersCR : public RGWCoroutine {
 
   RGWSyncTraceNodeRef tn;
 
-  using pipe_const_iter = map<string, RGWBucketSyncFlowManager::pipe_set>::const_iterator;
+  using pipe_const_iter = map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set>::const_iterator;
 
-  static pair<pipe_const_iter, pipe_const_iter> get_pipe_iters(const map<string, RGWBucketSyncFlowManager::pipe_set>& m, std::optional<string> zone) {
+  static pair<pipe_const_iter, pipe_const_iter> get_pipe_iters(const map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set>& m, std::optional<rgw_zone_id> zone) {
     if (!zone) {
       return { m.begin(), m.end() };
     }
@@ -3719,11 +3664,11 @@ class RGWGetBucketPeersCR : public RGWCoroutine {
     return { b, std::next(b) };
   }
 
-  void filter_sources(std::optional<string> source_zone,
+  void filter_sources(std::optional<rgw_zone_id> source_zone,
                       std::optional<rgw_bucket> source_bucket,
-                      const map<string, RGWBucketSyncFlowManager::pipe_set>& all_sources,
+                      const map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set>& all_sources,
                       rgw_sync_pipe_info_set *result) {
-    ldpp_dout(sync_env->dpp, 20) << __func__ << ": source_zone=" << source_zone.value_or("*")
+    ldpp_dout(sync_env->dpp, 20) << __func__ << ": source_zone=" << source_zone.value_or(rgw_zone_id("*")).id
                                 << " source_bucket=" << source_bucket.value_or(rgw_bucket())
                                 << " all_sources.size()=" << all_sources.size() << dendl;
     auto iters = get_pipe_iters(all_sources, source_zone);
@@ -3743,11 +3688,11 @@ class RGWGetBucketPeersCR : public RGWCoroutine {
     }
   }
 
-  void filter_targets(std::optional<string> target_zone,
+  void filter_targets(std::optional<rgw_zone_id> target_zone,
                       std::optional<rgw_bucket> target_bucket,
-                      const map<string, RGWBucketSyncFlowManager::pipe_set>& all_targets,
+                      const map<rgw_zone_id, RGWBucketSyncFlowManager::pipe_set>& all_targets,
                       rgw_sync_pipe_info_set *result) {
-    ldpp_dout(sync_env->dpp, 20) << __func__ << ": target_zone=" << source_zone.value_or("*")
+    ldpp_dout(sync_env->dpp, 20) << __func__ << ": target_zone=" << source_zone.value_or(rgw_zone_id("*")).id
                                 << " target_bucket=" << source_bucket.value_or(rgw_bucket())
                                 << " all_targets.size()=" << all_targets.size() << dendl;
     auto iters = get_pipe_iters(all_targets, target_zone);
@@ -3796,7 +3741,7 @@ class RGWGetBucketPeersCR : public RGWCoroutine {
 public:
   RGWGetBucketPeersCR(RGWDataSyncEnv *_sync_env,
                       std::optional<rgw_bucket> _target_bucket,
-                      std::optional<string> _source_zone,
+                      std::optional<rgw_zone_id> _source_zone,
                       std::optional<rgw_bucket> _source_bucket,
                       rgw_sync_pipe_info_set *_pipes,
                       const RGWSyncTraceNodeRef& _tn_parent)
@@ -3809,7 +3754,7 @@ public:
       tn(sync_env->sync_tracer->add_node(_tn_parent, "get_bucket_peers",
                                          SSTR( "target=" << target_bucket.value_or(rgw_bucket())
                                                << ":source=" << target_bucket.value_or(rgw_bucket())
-                                               << ":source_zone=" << source_zone.value_or("*")))) {
+                                               << ":source_zone=" << source_zone.value_or(rgw_zone_id("*")).id))) {
       }
 
   int operate() override;
@@ -4276,13 +4221,13 @@ int RGWBucketPipeSyncStatusManager::init()
     return ret;
   }
 
-  string last_zone;
+  rgw_zone_id last_zone;
 
   for (auto& pipe : pipes) {
     auto& szone = pipe.source.zone;
 
     if (last_zone != szone) {
-      conn = store->svc()->zone->get_zone_conn_by_id(szone);
+      conn = store->svc()->zone->get_zone_conn(szone);
       if (!conn) {
         ldpp_dout(this, 0) << "connection object to zone " << szone << " does not exist" << dendl;
         return -EINVAL;
@@ -4369,26 +4314,26 @@ unsigned RGWBucketPipeSyncStatusManager::get_subsys() const
 
 std::ostream& RGWBucketPipeSyncStatusManager::gen_prefix(std::ostream& out) const
 {
-  auto zone = std::string_view{source_zone.value_or("*")};
+  auto zone = std::string_view{source_zone.value_or(rgw_zone_id("*")).id};
   return out << "bucket sync zone:" << zone.substr(0, 8)
     << " bucket:" << dest_bucket << ' ';
 }
 
-string RGWBucketPipeSyncStatusManager::status_oid(const string& source_zone,
+string RGWBucketPipeSyncStatusManager::status_oid(const rgw_zone_id& source_zone,
                                               const rgw_bucket_sync_pair_info& sync_pair)
 {
   if (sync_pair.source_bs == sync_pair.dest_bs) {
-    return bucket_status_oid_prefix + "." + source_zone + ":" + sync_pair.dest_bs.get_key();
+    return bucket_status_oid_prefix + "." + source_zone.id + ":" + sync_pair.dest_bs.get_key();
   } else {
-    return bucket_status_oid_prefix + "." + source_zone + ":" + sync_pair.dest_bs.get_key() + ":" + sync_pair.source_bs.get_key();
+    return bucket_status_oid_prefix + "." + source_zone.id + ":" + sync_pair.dest_bs.get_key() + ":" + sync_pair.source_bs.get_key();
   }
 }
 
-string RGWBucketPipeSyncStatusManager::obj_status_oid(const string& source_zone,
+string RGWBucketPipeSyncStatusManager::obj_status_oid(const rgw_zone_id& source_zone,
                                                   const rgw_obj& obj)
 {
 #warning FIXME
-  return object_status_oid_prefix + "." + source_zone + ":" + obj.bucket.get_key() + ":" +
+  return object_status_oid_prefix + "." + source_zone.id + ":" + obj.bucket.get_key() + ":" +
          obj.key.name + ":" + obj.key.instance;
 }
 
index 4ea134400686fdcbb6ccb3207c48ee37b99beff0..6a9c9a4d8afd5a302104ea698e0a85c9a2ec6f53 100644 (file)
@@ -311,11 +311,11 @@ struct RGWDataSyncCtx {
   RGWDataSyncEnv *env{nullptr};
 
   RGWRESTConn *conn{nullptr};
-  string source_zone;
+  rgw_zone_id source_zone;
 
   void init(RGWDataSyncEnv *_env,
             RGWRESTConn *_conn,
-            const string& _source_zone) {
+            const rgw_zone_id& _source_zone) {
     cct = _env->cct;
     env = _env;
     conn = _conn;
@@ -348,7 +348,7 @@ public:
   RGWRemoteDataLog(const DoutPrefixProvider *dpp,
                    rgw::sal::RGWRadosStore *_store,
                    RGWAsyncRadosProcessor *async_rados);
-  int init(const string& _source_zone, RGWRESTConn *_conn, RGWSyncErrorLogger *_error_logger,
+  int init(const rgw_zone_id& _source_zone, RGWRESTConn *_conn, RGWSyncErrorLogger *_error_logger,
            RGWSyncTraceManager *_sync_tracer, RGWSyncModuleInstanceRef& module,
            PerfCounters* _counters);
   void finish();
@@ -368,7 +368,7 @@ public:
 class RGWDataSyncStatusManager : public DoutPrefixProvider {
   rgw::sal::RGWRadosStore *store;
 
-  string source_zone;
+  rgw_zone_id source_zone;
   RGWRESTConn *conn;
   RGWSyncErrorLogger *error_logger;
   RGWSyncModuleInstanceRef sync_module;
@@ -385,12 +385,12 @@ class RGWDataSyncStatusManager : public DoutPrefixProvider {
 
 public:
   RGWDataSyncStatusManager(rgw::sal::RGWRadosStore *_store, RGWAsyncRadosProcessor *async_rados,
-                           const string& _source_zone, PerfCounters* counters)
+                           const rgw_zone_id& _source_zone, PerfCounters* counters)
     : store(_store), source_zone(_source_zone), conn(NULL), error_logger(NULL),
       sync_module(nullptr), counters(counters),
       source_log(this, store, async_rados), num_shards(0) {}
   RGWDataSyncStatusManager(rgw::sal::RGWRadosStore *_store, RGWAsyncRadosProcessor *async_rados,
-                           const string& _source_zone, PerfCounters* counters,
+                           const rgw_zone_id& _source_zone, PerfCounters* counters,
                            const RGWSyncModuleInstanceRef& _sync_module)
     : store(_store), source_zone(_source_zone), conn(NULL), error_logger(NULL),
       sync_module(_sync_module), counters(counters),
@@ -401,8 +401,8 @@ public:
   int init();
   void finalize();
 
-  static string shard_obj_name(const string& source_zone, int shard_id);
-  static string sync_status_oid(const string& source_zone);
+  static string shard_obj_name(const rgw_zone_id& source_zone, int shard_id);
+  static string sync_status_oid(const rgw_zone_id& source_zone);
 
   int read_sync_status(rgw_data_sync_status *sync_status) {
     return source_log.read_sync_status(sync_status);
@@ -558,7 +558,7 @@ class RGWRemoteBucketManager {
   RGWDataSyncEnv *sync_env;
 
   RGWRESTConn *conn{nullptr};
-  string source_zone;
+  rgw_zone_id source_zone;
 
   vector<rgw_bucket_sync_pair_info> sync_pairs;
 
@@ -570,11 +570,11 @@ class RGWRemoteBucketManager {
 public:
   RGWRemoteBucketManager(const DoutPrefixProvider *_dpp,
                      RGWDataSyncEnv *_sync_env,
-                     const string& _source_zone, RGWRESTConn *_conn,
+                     const rgw_zone_id& _source_zone, RGWRESTConn *_conn,
                      const RGWBucketInfo& source_bucket_info,
                      const rgw_bucket& dest_bucket);
 
-  void init(const string& _source_zone, RGWRESTConn *_conn,
+  void init(const rgw_zone_id& _source_zone, RGWRESTConn *_conn,
             const rgw_bucket& source_bucket, int shard_id,
             const rgw_bucket& dest_bucket);
 
@@ -598,7 +598,7 @@ class RGWBucketPipeSyncStatusManager : public DoutPrefixProvider {
 
   RGWHTTPManager http_manager;
 
-  std::optional<string> source_zone;
+  std::optional<rgw_zone_id> source_zone;
   std::optional<rgw_bucket> source_bucket;
 
   RGWRESTConn *conn;
@@ -619,7 +619,7 @@ class RGWBucketPipeSyncStatusManager : public DoutPrefixProvider {
 
 public:
   RGWBucketPipeSyncStatusManager(rgw::sal::RGWRadosStore *_store,
-                             std::optional<string> _source_zone,
+                             std::optional<rgw_zone_id> _source_zone,
                              std::optional<rgw_bucket> _source_bucket,
                              const rgw_bucket& dest_bucket);
   ~RGWBucketPipeSyncStatusManager();
@@ -629,9 +629,9 @@ public:
   map<int, rgw_bucket_shard_sync_info>& get_sync_status() { return sync_status; }
   int init_sync_status();
 
-  static string status_oid(const string& source_zone, const rgw_bucket_sync_pair_info& bs);
-  static string obj_status_oid(const string& source_zone, const rgw_obj& obj); /* specific source obj sync status,
-                                                                                  can be used by sync modules */
+  static string status_oid(const rgw_zone_id& source_zone, const rgw_bucket_sync_pair_info& bs);
+  static string obj_status_oid(const rgw_zone_id& source_zone, const rgw_obj& obj); /* specific source obj sync status,
+                                                                                       can be used by sync modules */
 
   // implements DoutPrefixProvider
   CephContext *get_cct() const override;
index 4a6abb6d51350f1b8635d833e00e65951e9141d0..54ef0baa992dbcf98e0af8d319c32a5fc3207b96 100644 (file)
@@ -1392,7 +1392,7 @@ void RGWZoneGroup::dump(Formatter *f) const
   encode_json("sync_policy", sync_policy, f);
 }
 
-static void decode_zones(map<string, RGWZone>& zones, JSONObj *o)
+static void decode_zones(map<rgw_zone_id, RGWZone>& zones, JSONObj *o)
 {
   RGWZone z;
   z.decode_json(o);
@@ -2030,3 +2030,4 @@ void rgw_user::dump(Formatter *f) const
 {
   ::encode_json("user", *this, f);
 }
+
index a6cdaa00261b81ac8a2b70c6904d64d5fc282a75..c68c9addb5b5106643b93eef6b11ad91a5b89f72 100644 (file)
@@ -283,13 +283,13 @@ public:
     http_manager.start();
   }
 
-  int notify_all(map<string, RGWRESTConn *>& conn_map, set<int>& shards) {
+  int notify_all(map<rgw_zone_id, RGWRESTConn *>& conn_map, set<int>& shards) {
     rgw_http_param_pair pairs[] = { { "type", "metadata" },
                                     { "notify", NULL },
                                     { NULL, NULL } };
 
     list<RGWCoroutinesStack *> stacks;
-    for (map<string, RGWRESTConn *>::iterator iter = conn_map.begin(); iter != conn_map.end(); ++iter) {
+    for (auto iter = conn_map.begin(); iter != conn_map.end(); ++iter) {
       RGWRESTConn *conn = iter->second;
       RGWCoroutinesStack *stack = new RGWCoroutinesStack(store->ctx(), this);
       stack->call(new RGWPostRESTResourceCR<set<int>, int>(store->ctx(), conn, &http_manager, "/admin/log", pairs, shards, NULL));
@@ -310,14 +310,14 @@ public:
     http_manager.start();
   }
 
-  int notify_all(map<string, RGWRESTConn *>& conn_map, map<int, set<string> >& shards) {
+  int notify_all(map<rgw_zone_id, RGWRESTConn *>& conn_map, map<int, set<string> >& shards) {
     rgw_http_param_pair pairs[] = { { "type", "data" },
                                     { "notify", NULL },
                                     { "source-zone", store->svc.zone->get_zone_params().get_id().c_str() },
                                     { NULL, NULL } };
 
     list<RGWCoroutinesStack *> stacks;
-    for (map<string, RGWRESTConn *>::iterator iter = conn_map.begin(); iter != conn_map.end(); ++iter) {
+    for (auto iter = conn_map.begin(); iter != conn_map.end(); ++iter) {
       RGWRESTConn *conn = iter->second;
       RGWCoroutinesStack *stack = new RGWCoroutinesStack(store->ctx(), this);
       stack->call(new RGWPostRESTResourceCR<map<int, set<string> >, int>(store->ctx(), conn, &http_manager, "/admin/log", pairs, shards, NULL));
@@ -625,11 +625,11 @@ void RGWRados::wakeup_meta_sync_shards(set<int>& shard_ids)
   }
 }
 
-void RGWRados::wakeup_data_sync_shards(const string& source_zone, map<int, set<string> >& shard_ids)
+void RGWRados::wakeup_data_sync_shards(const rgw_zone_id& source_zone, map<int, set<string> >& shard_ids)
 {
   ldout(ctx(), 20) << __func__ << ": source_zone=" << source_zone << ", shard_ids=" << shard_ids << dendl;
   std::lock_guard l{data_sync_thread_lock};
-  map<string, RGWDataSyncProcessorThread *>::iterator iter = data_sync_processor_threads.find(source_zone);
+  auto iter = data_sync_processor_threads.find(source_zone);
   if (iter == data_sync_processor_threads.end()) {
     ldout(ctx(), 10) << __func__ << ": couldn't find sync thread for zone " << source_zone << ", skipping async data sync processing" << dendl;
     return;
@@ -649,7 +649,7 @@ RGWMetaSyncStatusManager* RGWRados::get_meta_sync_manager()
   return nullptr;
 }
 
-RGWDataSyncStatusManager* RGWRados::get_data_sync_manager(const std::string& source_zone)
+RGWDataSyncStatusManager* RGWRados::get_data_sync_manager(const rgw_zone_id& source_zone)
 {
   std::lock_guard l{data_sync_thread_lock};
   auto thread = data_sync_processor_threads.find(source_zone);
@@ -1105,7 +1105,7 @@ int RGWRados::register_to_service_map(const string& daemon_type, const map<strin
   metadata["zonegroup_id"] = svc.zone->get_zonegroup().get_id();
   metadata["zonegroup_name"] = svc.zone->get_zonegroup().get_name();
   metadata["zone_name"] = svc.zone->zone_name();
-  metadata["zone_id"] = svc.zone->zone_id();
+  metadata["zone_id"] = svc.zone->zone_id().id;
   string name = cct->_conf->name.get_id();
   if (name.compare(0, 4, "rgw.") == 0) {
     name = name.substr(4);
@@ -1240,7 +1240,7 @@ int RGWRados::init_complete()
         return ret;
       }
       thread->start();
-      data_sync_processor_threads[source_zone->id] = thread;
+      data_sync_processor_threads[rgw_zone_id(source_zone->id)] = thread;
     }
     auto interval = cct->_conf->rgw_sync_log_trim_interval;
     if (interval > 0) {
@@ -2747,7 +2747,7 @@ int RGWRados::swift_versioning_copy(RGWObjectCtx& obj_ctx,
 
   obj_ctx.set_atomic(dest_obj);
 
-  string no_zone;
+  rgw_zone_id no_zone;
 
   r = copy_obj(obj_ctx,
                user,
@@ -2819,7 +2819,7 @@ int RGWRados::swift_versioning_restore(RGWObjectCtx& obj_ctx,
 
   /* This code will be executed on latest version of the object. */
   const auto handler = [&](const rgw_bucket_dir_entry& entry) -> int {
-    std::string no_zone;
+    rgw_zone_id no_zone;
 
     /* We don't support object versioning of Swift API on those buckets that
      * are already versioned using the S3 mechanism. This affects also bucket
@@ -3505,7 +3505,7 @@ public:
 int RGWRados::stat_remote_obj(RGWObjectCtx& obj_ctx,
                const rgw_user& user_id,
                req_info *info,
-               const string& source_zone,
+               const rgw_zone_id& source_zone,
                rgw_obj& src_obj,
                const RGWBucketInfo *src_bucket_info,
                real_time *src_mtime,
@@ -3546,7 +3546,7 @@ int RGWRados::stat_remote_obj(RGWObjectCtx& obj_ctx,
     }
   } else {
     auto& zone_conn_map = svc.zone->get_zone_conn_map();
-    map<string, RGWRESTConn *>::iterator iter = zone_conn_map.find(source_zone);
+    auto iter = zone_conn_map.find(source_zone);
     if (iter == zone_conn_map.end()) {
       ldout(cct, 0) << "could not find zone connection to zone: " << source_zone << dendl;
       return -ENOENT;
@@ -3619,7 +3619,7 @@ int RGWRados::stat_remote_obj(RGWObjectCtx& obj_ctx,
 int RGWRados::fetch_remote_obj(RGWObjectCtx& obj_ctx,
                const rgw_user& user_id,
                req_info *info,
-               const string& source_zone,
+               const rgw_zone_id& source_zone,
                const rgw_obj& dest_obj,
                const rgw_obj& src_obj,
                const RGWBucketInfo& dest_bucket_info,
@@ -3677,7 +3677,7 @@ int RGWRados::fetch_remote_obj(RGWObjectCtx& obj_ctx,
       conn = iter->second;
     }
   } else {
-    map<string, RGWRESTConn *>::iterator iter = zone_conn_map.find(source_zone);
+    auto iter = zone_conn_map.find(source_zone);
     if (iter == zone_conn_map.end()) {
       ldout(cct, 0) << "could not find zone connection to zone: " << source_zone << dendl;
       return -ENOENT;
@@ -3936,7 +3936,7 @@ int RGWRados::copy_obj_to_remote_dest(RGWObjState *astate,
 int RGWRados::copy_obj(RGWObjectCtx& obj_ctx,
                const rgw_user& user_id,
                req_info *info,
-               const string& source_zone,
+               const rgw_zone_id& source_zone,
                rgw_obj& dest_obj,
                rgw_obj& src_obj,
                RGWBucketInfo& dest_bucket_info,
index 9eab78c83b5942e3b5eb2124f78bb4eb31b4b161..e730a2f45aba64d85d3f8c51d974ea7472b49090 100644 (file)
@@ -412,7 +412,7 @@ class RGWRados
   RGWDataNotifier *data_notifier;
   RGWMetaSyncProcessorThread *meta_sync_processor_thread;
   RGWSyncTraceManager *sync_tracer = nullptr;
-  map<string, RGWDataSyncProcessorThread *> data_sync_processor_threads;
+  map<rgw_zone_id, RGWDataSyncProcessorThread *> data_sync_processor_threads;
 
   boost::optional<rgw::BucketTrimManager> bucket_trim;
   RGWSyncLogTrimThread *sync_log_trimmer{nullptr};
@@ -1058,7 +1058,7 @@ public:
   int stat_remote_obj(RGWObjectCtx& obj_ctx,
                const rgw_user& user_id,
                req_info *info,
-               const string& source_zone,
+               const rgw_zone_id& source_zone,
                rgw_obj& src_obj,
                const RGWBucketInfo *src_bucket_info,
                real_time *src_mtime,
@@ -1077,7 +1077,7 @@ public:
   int fetch_remote_obj(RGWObjectCtx& obj_ctx,
                        const rgw_user& user_id,
                        req_info *info,
-                       const string& source_zone,
+                       const rgw_zone_id& source_zone,
                        const rgw_obj& dest_obj,
                        const rgw_obj& src_obj,
                        const RGWBucketInfo& dest_bucket_info,
@@ -1120,7 +1120,7 @@ public:
   int copy_obj(RGWObjectCtx& obj_ctx,
                const rgw_user& user_id,
                req_info *info,
-               const string& source_zone,
+               const rgw_zone_id& source_zone,
                rgw_obj& dest_obj,
                rgw_obj& src_obj,
                RGWBucketInfo& dest_bucket_info,
@@ -1180,10 +1180,10 @@ public:
   int delete_bucket(RGWBucketInfo& bucket_info, RGWObjVersionTracker& objv_tracker, optional_yield y, bool check_empty = true);
 
   void wakeup_meta_sync_shards(set<int>& shard_ids);
-  void wakeup_data_sync_shards(const string& source_zone, map<int, set<string> >& shard_ids);
+  void wakeup_data_sync_shards(const rgw_zone_id& source_zone, map<int, set<string> >& shard_ids);
 
   RGWMetaSyncStatusManager* get_meta_sync_manager();
-  RGWDataSyncStatusManager* get_data_sync_manager(const std::string& source_zone);
+  RGWDataSyncStatusManager* get_data_sync_manager(const rgw_zone_id& source_zone);
 
   int set_bucket_owner(rgw_bucket& bucket, ACLOwner& owner);
   int set_buckets_enabled(std::vector<rgw_bucket>& buckets, bool enabled);
@@ -1397,8 +1397,8 @@ public:
 
   int get_target_shard_id(const RGWBucketInfo& bucket_info, const string& obj_key, int *shard_id);
 
-  int lock_exclusive(const rgw_pool& pool, const string& oid, ceph::timespan& duration, string& zone_id, string& owner_id);
-  int unlock(const rgw_pool& pool, const string& oid, string& zone_id, string& owner_id);
+  int lock_exclusive(const rgw_pool& pool, const string& oid, ceph::timespan& duration, rgw_zone_id& zone_id, string& owner_id);
+  int unlock(const rgw_pool& pool, const string& oid, rgw_zone_id& zone_id, string& owner_id);
 
   void update_gc_chain(rgw_obj& head_obj, RGWObjManifest& manifest, cls_rgw_obj_chain *chain);
   int send_chain_to_gc(cls_rgw_obj_chain& chain, const string& tag);
index 103b28864cff398325e271c3cb4f74c3e96bbd45..e479b5347810b94be4751588c36817b08a4718b5 100644 (file)
@@ -1610,7 +1610,7 @@ public:
                               << " zone_short_id=" << src_zone_short_id << " pg_ver=" << src_pg_ver
                               << dendl;
 
-      source_conn = sync_env->svc->zone->get_zone_conn_by_id(sc->source_zone);
+      source_conn = sync_env->svc->zone->get_zone_conn(sc->source_zone);
       if (!source_conn) {
         ldout(sc->cct, 0) << "ERROR: cannot find http connection to zone " << sc->source_zone << dendl;
         return set_cr_error(-EINVAL);
index 5d0cad7e1e48f268b8fb6ece6dbb3f2c25c333b2..01a1fb6ccde92dd066c1f34d7b61bd287c5ca380 100644 (file)
@@ -151,7 +151,7 @@ void rgw_sync_bucket_entity::apply_bucket(std::optional<rgw_bucket> b)
   }
 }
 
-void rgw_sync_bucket_entities::add_zones(const std::vector<string>& new_zones) {
+void rgw_sync_bucket_entities::add_zones(const std::vector<rgw_zone_id>& new_zones) {
   for (auto& z : new_zones) {
     if (z == "*") {
       all_zones = true;
@@ -194,7 +194,7 @@ std::vector<rgw_sync_bucket_entity> rgw_sync_bucket_entities::expand() const
   return result;
 }
 
-void rgw_sync_bucket_entities::remove_zones(const std::vector<string>& rm_zones) {
+void rgw_sync_bucket_entities::remove_zones(const std::vector<rgw_zone_id>& rm_zones) {
   all_zones = false;
 
   if (!zones) {
@@ -346,7 +346,7 @@ bool rgw_sync_data_flow_group::find_symmetrical(const string& flow_id, bool crea
   return true;
 }
 
-void rgw_sync_data_flow_group::remove_symmetrical(const string& flow_id, std::optional<std::vector<string> > zones)
+void rgw_sync_data_flow_group::remove_symmetrical(const string& flow_id, std::optional<std::vector<rgw_zone_id> > zones)
 {
   if (!symmetrical) {
     return;
@@ -387,7 +387,7 @@ void rgw_sync_data_flow_group::remove_symmetrical(const string& flow_id, std::op
   }
 }
 
-bool rgw_sync_data_flow_group::find_directional(const string& source_zone, const string& dest_zone, bool create, rgw_sync_directional_rule **flow_group)
+bool rgw_sync_data_flow_group::find_directional(const rgw_zone_id& source_zone, const rgw_zone_id& dest_zone, bool create, rgw_sync_directional_rule **flow_group)
 {
   if (!directional) {
     if (!create) {
@@ -417,7 +417,7 @@ bool rgw_sync_data_flow_group::find_directional(const string& source_zone, const
   return true;
 }
 
-void rgw_sync_data_flow_group::remove_directional(const string& source_zone, const string& dest_zone)
+void rgw_sync_data_flow_group::remove_directional(const rgw_zone_id& source_zone, const rgw_zone_id& dest_zone)
 {
   if (!directional) {
     return;
@@ -436,7 +436,7 @@ void rgw_sync_data_flow_group::remove_directional(const string& source_zone, con
   }
 }
 
-void rgw_sync_data_flow_group::init_default(const std::set<string>& zones)
+void rgw_sync_data_flow_group::init_default(const std::set<rgw_zone_id>& zones)
 {
   symmetrical.emplace();
   symmetrical->push_back(rgw_sync_symmetric_group("default", zones));
index d312f7e790845c1062f87170272413a752f718da..12353777464296f722a1433759b85ff5d260ac68 100644 (file)
 
 struct rgw_sync_symmetric_group {
   string id;
-  std::set<string> zones;
+  std::set<rgw_zone_id> zones;
 
   rgw_sync_symmetric_group() {}
   rgw_sync_symmetric_group(const string& _id,
-                           const std::set<string> _zones) : id(_id), zones(_zones) {}
+                           const std::set<rgw_zone_id> _zones) : id(_id), zones(_zones) {}
 
 
   void encode(bufferlist& bl) const {
@@ -47,8 +47,8 @@ struct rgw_sync_symmetric_group {
 WRITE_CLASS_ENCODER(rgw_sync_symmetric_group)
 
 struct rgw_sync_directional_rule {
-  string source_zone;
-  string dest_zone;
+  rgw_zone_id source_zone;
+  rgw_zone_id dest_zone;
 
   void encode(bufferlist& bl) const {
     ENCODE_START(1, 1, bl);
@@ -70,7 +70,7 @@ struct rgw_sync_directional_rule {
 WRITE_CLASS_ENCODER(rgw_sync_directional_rule)
 
 struct rgw_sync_bucket_entity {
-  std::optional<string> zone; /* define specific zones */
+  std::optional<rgw_zone_id> zone; /* define specific zones */
   std::optional<rgw_bucket> bucket; /* define specific bucket */
 
   static bool match_str(const string& s1, const string& s2) { /* empty string is wildcard */
@@ -82,7 +82,7 @@ struct rgw_sync_bucket_entity {
   bool all_zones{false};
 
   rgw_sync_bucket_entity() {}
-  rgw_sync_bucket_entity(const string& _zone,
+  rgw_sync_bucket_entity(const rgw_zone_id& _zone,
                          std::optional<rgw_bucket> _bucket) : zone(_zone),
                                                               bucket(_bucket.value_or(rgw_bucket())) {}
 
@@ -115,7 +115,7 @@ struct rgw_sync_bucket_entity {
 
   string bucket_key() const;
 
-  bool match_zone(const string& z) const {
+  bool match_zone(const rgw_zone_id& z) const {
     if (all_zones) {
       return true;
     }
@@ -126,7 +126,7 @@ struct rgw_sync_bucket_entity {
     return (*zone == z);
   }
 
-  void apply_zone(const string& z) {
+  void apply_zone(const rgw_zone_id& z) {
     all_zones = false;
     zone = z;
   }
@@ -166,7 +166,7 @@ struct rgw_sync_bucket_entity {
     if (zone < e.zone) {
       return true;
     }
-    if (zone > e.zone) {
+    if (e.zone < zone) {
       return false;
     }
     return (bucket < e.bucket);
@@ -356,7 +356,7 @@ WRITE_CLASS_ENCODER(rgw_sync_bucket_pipe)
 
 struct rgw_sync_bucket_entities {
   std::optional<rgw_bucket> bucket; /* define specific bucket */
-  std::optional<std::set<string> > zones; /* define specific zones, if not set then all zones */
+  std::optional<std::set<rgw_zone_id> > zones; /* define specific zones, if not set then all zones */
 
   bool all_zones{false};
 
@@ -394,8 +394,8 @@ struct rgw_sync_bucket_entities {
             rgw_sync_bucket_entity::match_str(bucket->bucket_id, b->bucket_id));
   }
 
-  void add_zones(const std::vector<string>& new_zones);
-  void remove_zones(const std::vector<string>& rm_zones);
+  void add_zones(const std::vector<rgw_zone_id>& new_zones);
+  void remove_zones(const std::vector<rgw_zone_id>& rm_zones);
   void set_bucket(std::optional<string> tenant,
                   std::optional<string> bucket_name,
                   std::optional<string> bucket_id);
@@ -403,7 +403,7 @@ struct rgw_sync_bucket_entities {
                      std::optional<string> bucket_name,
                      std::optional<string> bucket_id);
 
-  bool match_zone(const string& zone) const {
+  bool match_zone(const rgw_zone_id& zone) const {
     if (all_zones) {
       return true;
     } else if (!zones) {
@@ -448,15 +448,15 @@ struct rgw_sync_bucket_pipes {
     DECODE_FINISH(bl);
   }
 
-  bool match_source(const string& zone, std::optional<rgw_bucket> b) const {
+  bool match_source(const rgw_zone_id& zone, std::optional<rgw_bucket> b) const {
     return (source.match_zone(zone) && source.match_bucket(b));
   }
 
-  bool match_dest(const string& zone, std::optional<rgw_bucket> b) const {
+  bool match_dest(const rgw_zone_id& zone, std::optional<rgw_bucket> b) const {
     return (dest.match_zone(zone) && dest.match_bucket(b));
   }
 
-  bool contains_zone_bucket(const string& zone, std::optional<rgw_bucket> b) const {
+  bool contains_zone_bucket(const rgw_zone_id& zone, std::optional<rgw_bucket> b) const {
     return (match_source(zone, b) || match_dest(zone, b));
   }
 
@@ -507,11 +507,11 @@ struct rgw_sync_data_flow_group {
   }
 
   bool find_symmetrical(const string& flow_id, bool create, rgw_sync_symmetric_group **flow_group);
-  void remove_symmetrical(const string& flow_id, std::optional<std::vector<string> > zones);
-  bool find_directional(const string& source_zone, const string& dest_zone, bool create, rgw_sync_directional_rule **flow_group);
-  void remove_directional(const string& source_zone, const string& dest_zone);
+  void remove_symmetrical(const string& flow_id, std::optional<std::vector<rgw_zone_id> > zones);
+  bool find_directional(const rgw_zone_id& source_zone, const rgw_zone_id& dest_zone, bool create, rgw_sync_directional_rule **flow_group);
+  void remove_directional(const rgw_zone_id& source_zone, const rgw_zone_id& dest_zone);
 
-  void init_default(const std::set<string>& zones);
+  void init_default(const std::set<rgw_zone_id>& zones);
 };
 WRITE_CLASS_ENCODER(rgw_sync_data_flow_group)
 
index 3cd728f0114d1d9cd4d09dac8c5c23304b60b2aa..1c1941936aefbea7c5d831fe095089ddeb78f507 100644 (file)
@@ -144,8 +144,8 @@ connection_map make_peer_connections(rgw::sal::RGWRadosStore *store,
   for (auto& g : zonegroups) {
     for (auto& z : g.second.zones) {
       std::unique_ptr<RGWRESTConn> conn{
-        new RGWRESTConn(store->ctx(), store->svc()->zone, z.first, z.second.endpoints)};
-      connections.emplace(z.first, std::move(conn));
+        new RGWRESTConn(store->ctx(), store->svc()->zone, z.first.id, z.second.endpoints)};
+      connections.emplace(z.first.id, std::move(conn));
     }
   }
   return connections;
@@ -206,13 +206,13 @@ struct TrimEnv {
   rgw::sal::RGWRadosStore *const store;
   RGWHTTPManager *const http;
   int num_shards;
-  const std::string& zone;
+  const rgw_zone_id& zone;
   Cursor current; //< cursor to current period
   epoch_t last_trim_epoch{0}; //< epoch of last mdlog that was purged
 
   TrimEnv(const DoutPrefixProvider *dpp, rgw::sal::RGWRadosStore *store, RGWHTTPManager *http, int num_shards)
     : dpp(dpp), store(store), http(http), num_shards(num_shards),
-      zone(store->svc()->zone->get_zone_params().get_id()),
+      zone(store->svc()->zone->zone_id()),
       current(store->svc()->mdlog->get_period_history()->get_current())
   {}
 };
@@ -229,7 +229,7 @@ struct MasterTrimEnv : public TrimEnv {
   {
     auto& period = current.get_period();
     connections = make_peer_connections(store, period.get_map().zonegroups);
-    connections.erase(zone);
+    connections.erase(zone.id);
     peer_status.resize(connections.size());
   }
 };
index e47e169d50d4cc9c95eab9bcbe82319c12f9e91b..ac2d8ab6fb145a313aa7994dde630ca87a75dea5 100644 (file)
@@ -261,14 +261,14 @@ void RGWZoneGroup::post_process_params()
   bool log_data = zones.size() > 1;
 
   if (master_zone.empty()) {
-    map<string, RGWZone>::iterator iter = zones.begin();
+    auto iter = zones.begin();
     if (iter != zones.end()) {
       master_zone = iter->first;
     }
   }
   
-  for (map<string, RGWZone>::iterator iter = zones.begin(); iter != zones.end(); ++iter) {
-    RGWZone& zone = iter->second;
+  for (auto& item : zones) {
+    RGWZone& zone = item.second;
     zone.log_data = log_data;
 
     RGWZoneParams zone_params(zone.id, zone.name);
@@ -278,9 +278,8 @@ void RGWZoneGroup::post_process_params()
       continue;
     }
 
-    for (map<string, RGWZonePlacementInfo>::iterator iter = zone_params.placement_pools.begin(); 
-         iter != zone_params.placement_pools.end(); ++iter) {
-      const string& placement_name = iter->first;
+    for (auto& pitem : zone_params.placement_pools) {
+      const string& placement_name = pitem.first;
       if (placement_targets.find(placement_name) == placement_targets.end()) {
         RGWZoneGroupPlacementTarget placement_target;
         placement_target.name = placement_name;
@@ -296,7 +295,7 @@ void RGWZoneGroup::post_process_params()
 
 int RGWZoneGroup::remove_zone(const std::string& zone_id)
 {
-  map<string, RGWZone>::iterator iter = zones.find(zone_id);
+  auto iter = zones.find(zone_id);
   if (iter == zones.end()) {
     ldout(cct, 0) << "zone id " << zone_id << " is not a part of zonegroup "
         << name << dendl;
index 002c72e443b8a2a594dd9d8d3cde429cef7110a7..f5c055130109b5f20b5c0001f8198ff1762de33b 100644 (file)
@@ -33,6 +33,7 @@ extern std::string default_storage_pool_suffix;
 class JSONObj;
 class RGWSyncModulesManager;
 
+
 struct RGWNameToId {
   std::string obj_id;
 
@@ -382,9 +383,9 @@ struct RGWZoneParams : RGWSystemMetaObj {
 
   RGWZoneParams() : RGWSystemMetaObj() {}
   explicit RGWZoneParams(const std::string& name) : RGWSystemMetaObj(name){}
-  RGWZoneParams(const std::string& id, const std::string& name) : RGWSystemMetaObj(id, name) {}
-  RGWZoneParams(const std::string& id, const std::string& name, const std::string& _realm_id)
-    : RGWSystemMetaObj(id, name), realm_id(_realm_id) {}
+  RGWZoneParams(const rgw_zone_id& id, const std::string& name) : RGWSystemMetaObj(id.id, name) {}
+  RGWZoneParams(const rgw_zone_id& id, const std::string& name, const std::string& _realm_id)
+    : RGWSystemMetaObj(id.id, name), realm_id(_realm_id) {}
 
   rgw_pool get_pool(CephContext *cct) const override;
   const std::string get_default_oid(bool old_format = false) const override;
@@ -695,8 +696,8 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
   list<std::string> endpoints;
   bool is_master = false;
 
-  std::string master_zone;
-  map<std::string, RGWZone> zones;
+  rgw_zone_id master_zone;
+  map<rgw_zone_id, RGWZone> zones;
 
   map<std::string, RGWZoneGroupPlacementTarget> placement_targets;
   rgw_placement_rule default_placement;
@@ -1021,7 +1022,7 @@ class RGWPeriod
   RGWPeriodMap period_map;
   RGWPeriodConfig period_config;
   std::string master_zonegroup;
-  std::string master_zone;
+  rgw_zone_id master_zone;
 
   std::string realm_id;
   std::string realm_name;
@@ -1054,7 +1055,7 @@ public:
   epoch_t get_epoch() const { return epoch; }
   epoch_t get_realm_epoch() const { return realm_epoch; }
   const std::string& get_predecessor() const { return predecessor_uuid; }
-  const std::string& get_master_zone() const { return master_zone; }
+  const rgw_zone_id& get_master_zone() const { return master_zone; }
   const std::string& get_master_zonegroup() const { return master_zonegroup; }
   const std::string& get_realm() const { return realm_id; }
   const RGWPeriodMap& get_map() const { return period_map; }
@@ -1073,9 +1074,9 @@ public:
     period_config.bucket_quota = bucket_quota;
   }
 
-  void set_id(const std::string& id) {
-    this->id = id;
-    period_map.id = id;
+  void set_id(const string& _id) {
+    this->id = _id;
+    period_map.id = _id;
   }
   void set_epoch(epoch_t epoch) { this->epoch = epoch; }
   void set_realm_epoch(epoch_t epoch) { realm_epoch = epoch; }
index c0d6bdd9a8a35253bde0b1b5cb9ada7aa423698c..4016490f71db8a764260fd990d4188e70c9e00b2 100644 (file)
@@ -31,7 +31,7 @@ public:
   RGWSI_Bucket_Sync(CephContext *cct) : RGWServiceInstance(cct) {}
 
   virtual int get_policy_handler(RGWSI_Bucket_X_Ctx& ctx,
-                                 std::optional<string> zone,
+                                 std::optional<rgw_zone_id> zone,
                                  std::optional<rgw_bucket> bucket,
                                  RGWBucketSyncPolicyHandlerRef *handler,
                                  optional_yield y) = 0;
index 31fa3ca1539527bdcd5b1df82ad85dec19ef0c9c..da3c9874f24afce2af1cef8c69debbceded49d62 100644 (file)
@@ -68,19 +68,13 @@ int RGWSI_Bucket_Sync_SObj::do_start()
 }
 
 void RGWSI_Bucket_Sync_SObj::get_hint_entities(RGWSI_Bucket_X_Ctx& ctx,
-                                               const std::set<string>& zone_names,
+                                               const std::set<rgw_zone_id>& zones,
                                                const std::set<rgw_bucket>& buckets,
                                                std::set<rgw_sync_bucket_entity> *hint_entities,
                                                optional_yield y)
 {
-  for (auto& zone : zone_names) {
+  for (auto& zone : zones) {
     for (auto& b : buckets) {
-      string zid;
-      if (!svc.zone->find_zone_id_by_name(zone, &zid)) {
-       cerr << "WARNING: cannot find zone id for zone=" << zone << ", skippping" << std::endl;
-       continue;
-      }
-
       RGWBucketInfo hint_bucket_info;
       int ret = svc.bucket_sobj->read_bucket_info(ctx, b, &hint_bucket_info,
                                                   nullptr, nullptr, boost::none,
@@ -90,7 +84,7 @@ void RGWSI_Bucket_Sync_SObj::get_hint_entities(RGWSI_Bucket_X_Ctx& ctx,
        continue;
       }
 
-      hint_entities->insert(rgw_sync_bucket_entity(zid, hint_bucket_info.bucket));
+      hint_entities->insert(rgw_sync_bucket_entity(zone, hint_bucket_info.bucket));
     }
   }
 }
@@ -102,8 +96,8 @@ int RGWSI_Bucket_Sync_SObj::resolve_policy_hints(RGWSI_Bucket_X_Ctx& ctx,
                                                  std::map<optional_zone_bucket, RGWBucketSyncPolicyHandlerRef>& temp_map,
                                                  optional_yield y)
 {
-  set<string> source_zones;
-  set<string> target_zones;
+  set<rgw_zone_id> source_zones;
+  set<rgw_zone_id> target_zones;
 
   zone_policy_handler->reflect(nullptr, nullptr,
                                nullptr, nullptr,
@@ -153,7 +147,7 @@ int RGWSI_Bucket_Sync_SObj::resolve_policy_hints(RGWSI_Bucket_X_Ctx& ctx,
 }
 
 int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx,
-                                                  std::optional<string> zone,
+                                                  std::optional<rgw_zone_id> zone,
                                                   std::optional<rgw_bucket> _bucket,
                                                   std::map<optional_zone_bucket, RGWBucketSyncPolicyHandlerRef>& temp_map,
                                                   RGWBucketSyncPolicyHandlerRef *handler,
@@ -170,7 +164,7 @@ int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx,
   string bucket_key;
 
   if (zone && *zone != svc.zone->zone_id()) {
-    zone_key = *zone;
+    zone_key = zone->id;
   }
 
   bucket_key = RGWSI_Bucket::get_bi_meta_key(bucket);
@@ -202,6 +196,10 @@ int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx,
   }
 
   auto zone_policy_handler = svc.zone->get_sync_policy_handler(zone);
+  if (!zone_policy_handler) {
+    ldout(cct, 20) << "ERROR: could not find policy handler for zone=" << zone << dendl;
+    return -ENOENT;
+  }
 
   e.handler.reset(zone_policy_handler->alloc_child(bucket_info));
 
@@ -234,7 +232,7 @@ int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx,
 }
 
 int RGWSI_Bucket_Sync_SObj::get_policy_handler(RGWSI_Bucket_X_Ctx& ctx,
-                                               std::optional<string> zone,
+                                               std::optional<rgw_zone_id> zone,
                                                std::optional<rgw_bucket> _bucket,
                                                RGWBucketSyncPolicyHandlerRef *handler,
                                                optional_yield y)
index ae497f3b580c8e61b60a9ccf71e31138975722fd..9dc0e380b3bd7d7527553de40c710f39d2f3c75b 100644 (file)
@@ -47,10 +47,10 @@ class RGWSI_Bucket_Sync_SObj : public RGWSI_Bucket_Sync
   int do_start() override;
 
   struct optional_zone_bucket {
-    optional<string> zone;
+    optional<rgw_zone_id> zone;
     optional<rgw_bucket> bucket;
 
-    optional_zone_bucket(const optional<string>& _zone,
+    optional_zone_bucket(const optional<rgw_zone_id>& _zone,
                          const optional<rgw_bucket>& _bucket) : zone(_zone), bucket(_bucket) {}
 
     bool operator<(const optional_zone_bucket& ozb) const {
@@ -65,7 +65,7 @@ class RGWSI_Bucket_Sync_SObj : public RGWSI_Bucket_Sync
   };
 
   void get_hint_entities(RGWSI_Bucket_X_Ctx& ctx,
-                         const std::set<string>& zone_names,
+                         const std::set<rgw_zone_id>& zone_names,
                          const std::set<rgw_bucket>& buckets,
                          std::set<rgw_sync_bucket_entity> *hint_entities,
                          optional_yield y);
@@ -76,7 +76,7 @@ class RGWSI_Bucket_Sync_SObj : public RGWSI_Bucket_Sync
                            std::map<optional_zone_bucket, RGWBucketSyncPolicyHandlerRef>& temp_map,
                            optional_yield y);
   int do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx,
-                            std::optional<string> zone,
+                            std::optional<rgw_zone_id> zone,
                             std::optional<rgw_bucket> _bucket,
                             std::map<optional_zone_bucket, RGWBucketSyncPolicyHandlerRef>& temp_map,
                             RGWBucketSyncPolicyHandlerRef *handler,
@@ -99,7 +99,7 @@ public:
 
 
   int get_policy_handler(RGWSI_Bucket_X_Ctx& ctx,
-                         std::optional<string> zone,
+                         std::optional<rgw_zone_id> zone,
                          std::optional<rgw_bucket> bucket,
                          RGWBucketSyncPolicyHandlerRef *handler,
                          optional_yield y);
index 511984f9a292aa34693d3b75d45a703892321a44..404937574c968e30d5c49fb347e632b5ceb3d492 100644 (file)
@@ -47,7 +47,7 @@ RGWSI_Zone::~RGWSI_Zone()
   delete current_period;
 }
 
-std::shared_ptr<RGWBucketSyncPolicyHandler> RGWSI_Zone::get_sync_policy_handler(std::optional<string> zone) const {
+std::shared_ptr<RGWBucketSyncPolicyHandler> RGWSI_Zone::get_sync_policy_handler(std::optional<rgw_zone_id> zone) const {
   if (!zone || *zone == zone_id()) {
     return sync_policy_handler;
   }
@@ -142,6 +142,9 @@ int RGWSI_Zone::do_start()
     lderr(cct) << "failed reading zone info: ret "<< ret << " " << cpp_strerror(-ret) << dendl;
     return ret;
   }
+
+  cur_zone_id = rgw_zone_id(zone_params->get_id());
+
   auto zone_iter = zonegroup->zones.find(zone_params->get_id());
   if (zone_iter == zonegroup->zones.end()) {
     if (using_local) {
@@ -166,7 +169,7 @@ int RGWSI_Zone::do_start()
   zone_short_id = current_period->get_map().get_zone_short_id(zone_params->get_id());
 
   for (auto ziter : zonegroup->zones) {
-    auto zone_handler = new RGWBucketSyncPolicyHandler(this, sync_modules_svc, bucket_sync_svc, ziter.second.name);
+    auto zone_handler = new RGWBucketSyncPolicyHandler(this, sync_modules_svc, bucket_sync_svc, ziter.second.id);
     ret = zone_handler->init(null_yield);
     if (ret < 0) {
       lderr(cct) << "ERROR: could not initialize zone policy handler for zone=" << ziter.second.name << dendl;
@@ -177,13 +180,13 @@ int RGWSI_Zone::do_start()
 
   sync_policy_handler = sync_policy_handlers[zone_id()]; /* we made sure earlier that zonegroup->zones has our zone */
 
-  set<string> source_zones_by_name;
-  set<string> target_zones_by_name;
+  set<rgw_zone_id> source_zones;
+  set<rgw_zone_id> target_zones;
 
   sync_policy_handler->reflect(nullptr, nullptr,
                                nullptr, nullptr,
-                               &source_zones_by_name,
-                               &target_zones_by_name,
+                               &source_zones,
+                               &target_zones,
                                false); /* relaxed: also get all zones that we allow to sync to/from */
 
   ret = sync_modules_svc->start();
@@ -201,7 +204,7 @@ int RGWSI_Zone::do_start()
 
   /* first build all zones index */
   for (auto ziter : zonegroup->zones) {
-    const string& id = ziter.first;
+    const rgw_zone_id& id = ziter.first;
     RGWZone& z = ziter.second;
     zone_id_by_name[z.name] = id;
     zone_by_id[id] = z;
@@ -212,7 +215,7 @@ int RGWSI_Zone::do_start()
   }
 
   for (const auto& ziter : zonegroup->zones) {
-    const string& id = ziter.first;
+    const rgw_zone_id& id = ziter.first;
     const RGWZone& z = ziter.second;
     if (id == zone_id()) {
       continue;
@@ -225,8 +228,8 @@ int RGWSI_Zone::do_start()
     RGWRESTConn *conn = new RGWRESTConn(cct, this, z.id, z.endpoints);
     zone_conn_map[id] = conn;
 
-    bool zone_is_source = source_zones_by_name.find(z.name) != source_zones_by_name.end();
-    bool zone_is_target = target_zones_by_name.find(z.name) != target_zones_by_name.end();
+    bool zone_is_source = source_zones.find(z.id) != source_zones.end();
+    bool zone_is_target = target_zones.find(z.id) != target_zones.end();
 
     if (zone_is_source || zone_is_target) {
       if (zone_is_source) {
@@ -250,14 +253,13 @@ void RGWSI_Zone::shutdown()
 {
   delete rest_master_conn;
 
-  map<string, RGWRESTConn *>::iterator iter;
-  for (iter = zone_conn_map.begin(); iter != zone_conn_map.end(); ++iter) {
-    RGWRESTConn *conn = iter->second;
+  for (auto& item : zone_conn_map) {
+    auto conn = item.second;
     delete conn;
   }
 
-  for (iter = zonegroup_conn_map.begin(); iter != zonegroup_conn_map.end(); ++iter) {
-    RGWRESTConn *conn = iter->second;
+  for (auto& item : zonegroup_conn_map) {
+    auto conn = item.second;
     delete conn;
   }
 }
@@ -405,7 +407,8 @@ int RGWSI_Zone::replace_region_with_zonegroup()
     return 0;
   }
 
-  string master_region, master_zone;
+  string master_region;
+  rgw_zone_id master_zone;
   for (list<string>::iterator iter = regions.begin(); iter != regions.end(); ++iter) {
     if (*iter != default_zonegroup_name){
       RGWZoneGroup region(*iter);
@@ -425,7 +428,7 @@ int RGWSI_Zone::replace_region_with_zonegroup()
      The realm name will be the region and zone concatenated
      realm id will be mds of its name */
   if (realm->get_id().empty() && !master_region.empty() && !master_zone.empty()) {
-    string new_realm_name = master_region + "." + master_zone;
+    string new_realm_name = master_region + "." + master_zone.id;
     unsigned char md5[CEPH_CRYPTO_MD5_DIGESTSIZE];
     char md5_str[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1];
     MD5 hash;
@@ -507,11 +510,11 @@ int RGWSI_Zone::replace_region_with_zonegroup()
         return ret;
       }
     }
-    for (map<string, RGWZone>::const_iterator iter = zonegroup.zones.begin(); iter != zonegroup.zones.end();
+    for (auto iter = zonegroup.zones.begin(); iter != zonegroup.zones.end();
          ++iter) {
       ldout(cct, 0) << __func__ << " Converting zone" << iter->first << dendl;
-      RGWZoneParams zoneparams(iter->first, iter->first);
-      zoneparams.set_id(iter->first);
+      RGWZoneParams zoneparams(iter->first, iter->second.name);
+      zoneparams.set_id(iter->first.id);
       zoneparams.realm_id = realm->get_id();
       ret = zoneparams.init(cct, sysobj_svc);
       if (ret < 0 && ret != -ENOENT) {
@@ -893,12 +896,8 @@ const string& RGWSI_Zone::zone_name() const
 {
   return get_zone_params().get_name();
 }
-const string& RGWSI_Zone::zone_id() const
-{
-  return get_zone_params().get_id();
-}
 
-bool RGWSI_Zone::find_zone_by_id(const string& id, RGWZone **zone)
+bool RGWSI_Zone::find_zone(const rgw_zone_id& id, RGWZone **zone)
 {
   auto iter = zone_by_id.find(id);
   if (iter == zone_by_id.end()) {
@@ -908,8 +907,8 @@ bool RGWSI_Zone::find_zone_by_id(const string& id, RGWZone **zone)
   return true;
 }
 
-RGWRESTConn *RGWSI_Zone::get_zone_conn_by_id(const string& id) {
-  auto citer = zone_conn_map.find(id);
+RGWRESTConn *RGWSI_Zone::get_zone_conn(const rgw_zone_id& zone_id) {
+  auto citer = zone_conn_map.find(zone_id.id);
   if (citer == zone_conn_map.end()) {
     return NULL;
   }
@@ -923,10 +922,10 @@ RGWRESTConn *RGWSI_Zone::get_zone_conn_by_name(const string& name) {
     return NULL;
   }
 
-  return get_zone_conn_by_id(i->second);
+  return get_zone_conn(i->second);
 }
 
-bool RGWSI_Zone::find_zone_id_by_name(const string& name, string *id) {
+bool RGWSI_Zone::find_zone_id_by_name(const string& name, rgw_zone_id *id) {
   auto i = zone_id_by_name.find(name);
   if (i == zone_id_by_name.end()) {
     return false;
@@ -992,7 +991,7 @@ bool RGWSI_Zone::is_syncing_bucket_meta(const rgw_bucket& bucket)
   }
 
   /* zone is not master */
-  if (zonegroup->master_zone.compare(zone_public_config->id) != 0) {
+  if (zonegroup->master_zone != zone_public_config->id) {
     return false;
   }
 
index e20575f163278b27f820f64afca9d1c527f31436..5a51b6de2537aaf8022ab1f4b044c8ec8bf8843e 100644 (file)
@@ -38,20 +38,21 @@ class RGWSI_Zone : public RGWServiceInstance
   RGWZone *zone_public_config{nullptr}; /* external zone params, e.g., entrypoints, log flags, etc. */  
   RGWZoneParams *zone_params{nullptr}; /* internal zone params, e.g., rados pools */
   RGWPeriod *current_period{nullptr};
+  rgw_zone_id cur_zone_id;
   uint32_t zone_short_id{0};
   bool writeable_zone{false};
 
   std::shared_ptr<RGWBucketSyncPolicyHandler> sync_policy_handler;
-  std::map<string, std::shared_ptr<RGWBucketSyncPolicyHandler> > sync_policy_handlers;
+  std::map<rgw_zone_id, std::shared_ptr<RGWBucketSyncPolicyHandler> > sync_policy_handlers;
 
   RGWRESTConn *rest_master_conn{nullptr};
-  map<string, RGWRESTConn *> zone_conn_map;
+  map<rgw_zone_id, RGWRESTConn *> zone_conn_map;
   std::vector<const RGWZone*> data_sync_source_zones;
-  map<string, RGWRESTConn *> zone_data_notify_to_map;
+  map<rgw_zone_id, RGWRESTConn *> zone_data_notify_to_map;
   map<string, RGWRESTConn *> zonegroup_conn_map;
 
-  map<string, string> zone_id_by_name;
-  map<string, RGWZone> zone_by_id;
+  map<string, rgw_zone_id> zone_id_by_name;
+  map<rgw_zone_id, RGWZone> zone_by_id;
 
   std::unique_ptr<rgw_sync_policy_info> sync_policy;
 
@@ -79,10 +80,12 @@ public:
   int get_zonegroup(const string& id, RGWZoneGroup& zonegroup) const;
   const RGWZone& get_zone() const;
 
-  std::shared_ptr<RGWBucketSyncPolicyHandler> get_sync_policy_handler(std::optional<string> zone = nullopt) const;
+  std::shared_ptr<RGWBucketSyncPolicyHandler> get_sync_policy_handler(std::optional<rgw_zone_id> zone = nullopt) const;
 
   const string& zone_name() const;
-  const string& zone_id() const;
+  const rgw_zone_id& zone_id() const {
+    return cur_zone_id;
+  }
   uint32_t get_zone_short_id() const;
 
   const string& get_current_period_id() const;
@@ -101,7 +104,7 @@ public:
     return zonegroup_conn_map;
   }
 
-  map<string, RGWRESTConn *>& get_zone_conn_map() {
+  map<rgw_zone_id, RGWRESTConn *>& get_zone_conn_map() {
     return zone_conn_map;
   }
 
@@ -109,15 +112,15 @@ public:
     return data_sync_source_zones;
   }
 
-  map<string, RGWRESTConn *>& get_zone_data_notify_to_map() {
+  map<rgw_zone_id, RGWRESTConn *>& get_zone_data_notify_to_map() {
     return zone_data_notify_to_map;
   }
 
-  bool find_zone_by_id(const string& id, RGWZone **zone);
+  bool find_zone(const rgw_zone_id& id, RGWZone **zone);
 
-  RGWRESTConn *get_zone_conn_by_id(const string& id);
+  RGWRESTConn *get_zone_conn(const rgw_zone_id& zone_id);
   RGWRESTConn *get_zone_conn_by_name(const string& name);
-  bool find_zone_id_by_name(const string& name, string *id);
+  bool find_zone_id_by_name(const string& name, rgw_zone_id *id);
 
   int select_bucket_placement(const RGWUserInfo& user_info, const string& zonegroup_id,
                               const rgw_placement_rule& rule,