Skip to content

Commit 66bf56e

Browse files
authored
Merge pull request ceph#60045 from AliMasarweh/wip-alimasa-notif-list-bucket
RGW|Bucket notification: fix for v2 topics rgw-admin list operation Reviewed-by: yuvalif<[email protected]>
2 parents d588451 + 575a19d commit 66bf56e

File tree

5 files changed

+58
-44
lines changed

5 files changed

+58
-44
lines changed

src/rgw/rgw_admin.cc

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11187,38 +11187,44 @@ int main(int argc, const char **argv)
1118711187
}
1118811188

1118911189
formatter->open_object_section("result");
11190-
formatter->open_array_section("topics");
11191-
do {
11192-
rgw_pubsub_topics result;
11193-
int ret = ps.get_topics(dpp(), next_token, max_entries,
11194-
result, next_token, null_yield);
11195-
if (ret < 0 && ret != -ENOENT) {
11196-
cerr << "ERROR: could not get topics: " << cpp_strerror(-ret) << std::endl;
11197-
return -ret;
11198-
}
11199-
for (const auto& [_, topic] : result.topics) {
11200-
if (owner && *owner != topic.owner) {
11201-
continue;
11190+
rgw_pubsub_topics result;
11191+
if (rgw::all_zonegroups_support(*site, rgw::zone_features::notification_v2) &&
11192+
driver->stat_topics_v1(tenant, null_yield, dpp()) == -ENOENT) {
11193+
formatter->open_array_section("topics");
11194+
do {
11195+
int ret = ps.get_topics_v2(dpp(), next_token, max_entries,
11196+
result, next_token, null_yield);
11197+
if (ret < 0 && ret != -ENOENT) {
11198+
cerr << "ERROR: could not get topics: " << cpp_strerror(-ret) << std::endl;
11199+
return -ret;
1120211200
}
11203-
std::set<std::string> subscribed_buckets;
11204-
if (rgw::all_zonegroups_support(*site, rgw::zone_features::notification_v2) &&
11205-
driver->stat_topics_v1(tenant, null_yield, dpp()) == -ENOENT) {
11201+
for (const auto& [_, topic] : result.topics) {
11202+
if (owner && *owner != topic.owner) {
11203+
continue;
11204+
}
11205+
std::set<std::string> subscribed_buckets;
1120611206
ret = driver->get_bucket_topic_mapping(topic, subscribed_buckets,
1120711207
null_yield, dpp());
1120811208
if (ret < 0) {
1120911209
cerr << "failed to fetch bucket topic mapping info for topic: "
1121011210
<< topic.name << ", ret=" << ret << std::endl;
1121111211
}
1121211212
show_topics_info_v2(topic, subscribed_buckets, formatter.get());
11213-
} else {
11214-
encode_json("result", result, formatter.get());
11215-
}
11216-
if (max_entries_specified) {
11217-
--max_entries;
11213+
if (max_entries_specified) {
11214+
--max_entries;
11215+
}
1121811216
}
11217+
result.topics.clear();
11218+
} while (!next_token.empty() && max_entries > 0);
11219+
formatter->close_section(); // topics
11220+
} else { // v1, list all topics
11221+
int ret = ps.get_topics_v1(dpp(), result, null_yield);
11222+
if (ret < 0 && ret != -ENOENT) {
11223+
cerr << "ERROR: could not get topics: " << cpp_strerror(-ret) << std::endl;
11224+
return -ret;
1121911225
}
11220-
} while (!next_token.empty() && max_entries > 0);
11221-
formatter->close_section(); // topics
11226+
encode_json("result", result, formatter.get());
11227+
}
1122211228
if (max_entries_specified) {
1122311229
encode_json("truncated", !next_token.empty(), formatter.get());
1122411230
if (!next_token.empty()) {

src/rgw/rgw_pubsub.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -570,22 +570,16 @@ RGWPubSub::RGWPubSub(rgw::sal::Driver* _driver,
570570
{
571571
}
572572

573-
int RGWPubSub::get_topics(const DoutPrefixProvider* dpp,
574-
const std::string& start_marker, int max_items,
575-
rgw_pubsub_topics& result, std::string& next_marker,
576-
optional_yield y) const
573+
int RGWPubSub::get_topics_v2(const DoutPrefixProvider* dpp,
574+
const std::string& start_marker, int max_items,
575+
rgw_pubsub_topics& result, std::string& next_marker,
576+
optional_yield y) const
577577
{
578578
if (rgw::account::validate_id(tenant)) {
579579
// if our tenant is an account, return the account listing
580580
return list_account_topics(dpp, start_marker, max_items,
581581
result, next_marker, y);
582582
}
583-
584-
if (!use_notification_v2 || driver->stat_topics_v1(tenant, y, dpp) != -ENOENT) {
585-
// in case of v1 or during migration we use v1 topics
586-
// v1 returns all topics, ignoring marker/max_items
587-
return read_topics_v1(dpp, result, nullptr, y);
588-
}
589583

590584
// TODO: prefix filter on 'tenant:'
591585
void* handle = NULL;
@@ -629,6 +623,13 @@ int RGWPubSub::get_topics(const DoutPrefixProvider* dpp,
629623
return ret;
630624
}
631625

626+
int RGWPubSub::get_topics_v1(const DoutPrefixProvider* dpp,
627+
rgw_pubsub_topics& result,
628+
optional_yield y) const
629+
{
630+
return read_topics_v1(dpp, result, nullptr, y);
631+
}
632+
632633
int RGWPubSub::list_account_topics(const DoutPrefixProvider* dpp,
633634
const std::string& start_marker,
634635
int max_items, rgw_pubsub_topics& result,

src/rgw/rgw_pubsub.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,14 @@ class RGWPubSub
643643

644644
// get a paginated list of topics
645645
// return 0 on success, error code otherwise
646-
int get_topics(const DoutPrefixProvider* dpp,
647-
const std::string& start_marker, int max_items,
648-
rgw_pubsub_topics& result, std::string& next_marker,
646+
int get_topics_v2(const DoutPrefixProvider* dpp,
647+
const std::string& start_marker, int max_items,
648+
rgw_pubsub_topics& result, std::string& next_marker,
649+
optional_yield y) const;
650+
651+
// return 0 on success, error code otherwise
652+
int get_topics_v1(const DoutPrefixProvider* dpp,
653+
rgw_pubsub_topics& result,
649654
optional_yield y) const;
650655

651656
// get a topic with by its name and populate it into "result"

src/rgw/rgw_rest_pubsub.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,13 @@ void RGWPSListTopicsOp::execute(optional_yield y) {
493493
const std::string start_token = s->info.args.get("NextToken");
494494

495495
const RGWPubSub ps(driver, get_account_or_tenant(s->owner.id), *s->penv.site);
496-
constexpr int max_items = 100;
497-
op_ret = ps.get_topics(this, start_token, max_items, result, next_token, y);
496+
if (rgw::all_zonegroups_support(*s->penv.site, rgw::zone_features::notification_v2) &&
497+
driver->stat_topics_v1(s->bucket->get_tenant(), null_yield, this) == -ENOENT) {
498+
op_ret = ps.get_topics_v1(this, result, y);
499+
} else {
500+
constexpr int max_items = 100;
501+
op_ret = ps.get_topics_v2(this, start_token, max_items, result, next_token, y);
502+
}
498503
// if there are no topics it is not considered an error
499504
op_ret = op_ret == -ENOENT ? 0 : op_ret;
500505
if (op_ret < 0) {

src/test/rgw/bucket_notification/test_bn.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -711,19 +711,16 @@ def test_ps_s3_topic_on_master():
711711
assert_equal(status, 404)
712712

713713
# get the remaining 2 topics
714-
result, status = topic_conf1.get_list()
715-
assert_equal(status, 200)
716-
assert_equal(len(result['ListTopicsResponse']['ListTopicsResult']['Topics']['member']), 2)
714+
list_topics(2, tenant)
717715

718716
# delete topics
719-
result = topic_conf2.del_config()
717+
status = topic_conf2.del_config()
720718
assert_equal(status, 200)
721-
result = topic_conf3.del_config()
719+
status = topic_conf3.del_config()
722720
assert_equal(status, 200)
723721

724722
# get topic list, make sure it is empty
725-
result, status = topic_conf1.get_list()
726-
assert_equal(result['ListTopicsResponse']['ListTopicsResult']['Topics'], None)
723+
list_topics(0, tenant)
727724

728725

729726
@attr('basic_test')

0 commit comments

Comments
 (0)