From 1caf954dab136e7d5cff97f76ce362c1bfb8d3f4 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 10 Jan 2024 17:07:27 -0500 Subject: [PATCH] rgw/topic: metadata key format in rgw_pubsub.h 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 --- src/rgw/driver/rados/rgw_sal_rados.cc | 10 ++++----- src/rgw/rgw_pubsub.cc | 29 +++++++++++++++++++++++++-- src/rgw/rgw_pubsub.h | 7 +++++++ src/rgw/services/svc_topic_rados.h | 9 +-------- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/rgw/driver/rados/rgw_sal_rados.cc b/src/rgw/driver/rados/rgw_sal_rados.cc index 6aba08828b725..0e6cbf96aea85 100644 --- a/src/rgw/driver/rados/rgw_sal_rados.cc +++ b/src/rgw/driver/rados/rgw_sal_rados.cc @@ -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); } diff --git a/src/rgw/rgw_pubsub.cc b/src/rgw/rgw_pubsub.cc index bec78b687c83e..474a7c2316342 100644 --- a/src/rgw/rgw_pubsub.cc +++ b/src/rgw/rgw_pubsub.cc @@ -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" @@ -17,6 +18,30 @@ #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; } diff --git a/src/rgw/rgw_pubsub.h b/src/rgw/rgw_pubsub.h index 519c1053ab31f..f03d7542b7388 100644 --- a/src/rgw/rgw_pubsub.h +++ b/src/rgw/rgw_pubsub.h @@ -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); diff --git a/src/rgw/services/svc_topic_rados.h b/src/rgw/services/svc_topic_rados.h index bc4e35373459e..4d7f37cc02d48 100644 --- a/src/rgw/services/svc_topic_rados.h +++ b/src/rgw/services/svc_topic_rados.h @@ -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); -- 2.39.5