]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/topic: metadata key format in rgw_pubsub.h
authorCasey Bodley <cbodley@redhat.com>
Wed, 10 Jan 2024 22:07:27 +0000 (17:07 -0500)
committerCasey Bodley <cbodley@redhat.com>
Tue, 5 Mar 2024 17:55:25 +0000 (12:55 -0500)
the format of topic metadata keys is agnostic to the backend, so the
parsing/formatting functions should be in rgw_pubsub.h

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/driver/rados/rgw_sal_rados.cc
src/rgw/rgw_pubsub.cc
src/rgw/rgw_pubsub.h
src/rgw/services/svc_topic_rados.h

index 6aba08828b7259313f373174623b2c23bfe609ca..0e6cbf96aea852689ea238776ae045f16324b1b0 100644 (file)
@@ -1149,8 +1149,8 @@ int RadosStore::read_topic_v2(const std::string& topic_name,
       svc()->topic->svc.meta_be->alloc_ctx());
   ctx->init(svc()->topic->get_be_handler());
   const int ret = svc()->topic->svc.meta_be->get(
-      ctx.get(), get_topic_key(topic_name, tenant), params, objv_tracker, y,
-      dpp);
+      ctx.get(), get_topic_metadata_key(tenant, topic_name),
+      params, objv_tracker, y, dpp);
   if (ret < 0) {
     return ret;
   }
@@ -1178,8 +1178,8 @@ int RadosStore::write_topic_v2(const rgw_pubsub_topic& topic,
       svc()->topic->svc.meta_be->alloc_ctx());
   ctx->init(svc()->topic->get_be_handler());
   return svc()->topic->svc.meta_be->put(
-      ctx.get(), get_topic_key(topic.name, topic.user.tenant), params,
-      objv_tracker, y, dpp);
+      ctx.get(), get_topic_metadata_key(topic.user.tenant, topic.name),
+      params, objv_tracker, y, dpp);
 }
 
 int RadosStore::remove_topic_v2(const std::string& topic_name,
@@ -1192,7 +1192,7 @@ int RadosStore::remove_topic_v2(const std::string& topic_name,
       svc()->topic->svc.meta_be->alloc_ctx());
   ctx->init(svc()->topic->get_be_handler());
   return svc()->topic->svc.meta_be->remove(ctx.get(),
-                                           get_topic_key(topic_name, tenant),
+                                           get_topic_metadata_key(tenant, topic_name),
                                            params, objv_tracker, y, dpp);
 }
 
index bec78b687c83e932b0a66e0e7e304357cae368c1..474a7c23163427ed8a0ef412d9fe2f088071517d 100644 (file)
@@ -5,6 +5,7 @@
 #include "rgw_b64.h"
 #include "rgw_sal.h"
 #include "rgw_pubsub.h"
+#include "rgw_string.h"
 #include "rgw_tools.h"
 #include "rgw_xml.h"
 #include "rgw_arn.h"
 
 #define dout_subsys ceph_subsys_rgw
 
+static constexpr std::string_view topic_tenant_delim = ":";
+
+// format and parse topic metadata keys as tenant:name
+std::string get_topic_metadata_key(std::string_view tenant,
+                                   std::string_view topic_name)
+{
+  return string_cat_reserve(tenant, topic_tenant_delim, topic_name);
+}
+
+void parse_topic_metadata_key(const std::string& key,
+                              std::string& tenant,
+                              std::string& name)
+{
+  // expected format: tenant_name:topic_name*
+  auto pos = key.find(topic_tenant_delim);
+  if (pos != std::string::npos) {
+    tenant = key.substr(0, pos);
+    name = key.substr(pos + 1);
+  } else {
+    tenant.clear();
+    name = key;
+  }
+}
+
 void set_event_id(std::string& id, const std::string& hash, const utime_t& ts) {
   char buf[64];
   const auto len = snprintf(buf, sizeof(buf), "%010ld.%06ld.%s", (long)ts.sec(), (long)ts.usec(), hash.c_str());
@@ -540,10 +565,10 @@ int RGWPubSub::get_topics(const DoutPrefixProvider* dpp,
         << "ERROR: lists_keys_next(): " << cpp_strerror(-ret) << dendl;
     return ret;
   }
-  for (auto& topic_entry : topics) {
+  for (const auto& key : topics) {
     std::string topic_name;
     std::string topic_tenant;
-    parse_topic_entry(topic_entry, &topic_tenant, &topic_name);
+    parse_topic_metadata_key(key, topic_tenant, topic_name);
     if (tenant != topic_tenant) {
       continue;
     }
index 519c1053ab31f201b674d64830af87af5c0c814a..f03d7542b7388ad3c3769214c6c56dcb6d97034b 100644 (file)
@@ -690,3 +690,10 @@ int remove_notification_v2(const DoutPrefixProvider* dpp,
 int get_bucket_notifications(const DoutPrefixProvider* dpp,
                              rgw::sal::Bucket* bucket,
                              rgw_pubsub_bucket_topics& bucket_topics);
+
+// format and parse topic metadata keys as tenant:name
+std::string get_topic_metadata_key(std::string_view topic_name,
+                                   std::string_view tenant);
+void parse_topic_metadata_key(const std::string& key,
+                              std::string& tenant_name,
+                              std::string& topic_name);
index bc4e35373459ee73048b4d25c56b6f833bdc7c62..4d7f37cc02d485903fd8d7f76a5acbe2c2640bae 100644 (file)
@@ -88,11 +88,4 @@ class RGWTopicMetadataHandler : public RGWMetadataHandler_GenericMetaBE {
   RGWSI_Topic_RADOS* topic_svc;
 };
 
-std::string get_topic_key(const std::string& topic_name,
-                          const std::string& tenant);
-
-void parse_topic_entry(const std::string& topic_entry,
-                       std::string* tenant_name,
-                       std::string* topic_name);
-
-std::string get_bucket_topic_mapping_oid(const rgw_pubsub_topic& topic);
\ No newline at end of file
+std::string get_bucket_topic_mapping_oid(const rgw_pubsub_topic& topic);