From: Yuri Weinstein Date: Mon, 19 Nov 2018 16:49:06 +0000 (-0800) Subject: Merge pull request #23819 from dongbula/nf-add-bucket-option-in-usage X-Git-Tag: v14.1.0~878 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=02df8f3008d6ab0903cb1bb5577ca813dd3c4d00;p=ceph-ci.git Merge pull request #23819 from dongbula/nf-add-bucket-option-in-usage rgw: add bucket as option when show/trim usage Reviewed-by: Casey Bodley --- 02df8f3008d6ab0903cb1bb5577ca813dd3c4d00 diff --cc src/rgw/rgw_rados.cc index 25a28730274,5f3ddd11b4c..30c1dc6cee5 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@@ -9249,10 -13598,12 +9250,12 @@@ int RGWRados::cls_obj_usage_log_add(con return r; } - int RGWRados::cls_obj_usage_log_read(string& oid, string& user, uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries, - string& read_iter, map& usage, bool *is_truncated) + int RGWRados::cls_obj_usage_log_read(const string& oid, const string& user, const string& bucket, + uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries, + string& read_iter, map& usage, + bool *is_truncated) { - rgw_raw_obj obj(get_zone_params().usage_log_pool, oid); + rgw_raw_obj obj(svc.zone->get_zone_params().usage_log_pool, oid); rgw_rados_ref ref; int r = get_raw_obj_ref(obj, &ref); @@@ -9268,9 -13619,10 +9271,10 @@@ return r; } - int RGWRados::cls_obj_usage_log_trim(string& oid, string& user, uint64_t start_epoch, uint64_t end_epoch) + int RGWRados::cls_obj_usage_log_trim(const string& oid, const string& user, const string& bucket, + uint64_t start_epoch, uint64_t end_epoch) { - rgw_raw_obj obj(get_zone_params().usage_log_pool, oid); + rgw_raw_obj obj(svc.zone->get_zone_params().usage_log_pool, oid); rgw_rados_ref ref; int r = get_raw_obj_ref(obj, &ref); diff --cc src/test/cls_rgw/test_cls_rgw.cc index 7e78acf8a1c,607600572b3..a248eb802c1 --- a/src/test/cls_rgw/test_cls_rgw.cc +++ b/src/test/cls_rgw/test_cls_rgw.cc @@@ -830,17 -841,40 +841,40 @@@ TEST(cls_rgw, usage_basic // read the entries, and see that we have all the added entries ASSERT_EQ(0, ret); ASSERT_FALSE(truncated); - ASSERT_EQ(total_usage_entries, usage.size()); + ASSERT_EQ(static_cast(total_usage_entries), usage.size()); // delete and read to assert that we've deleted all the values - ASSERT_EQ(0, cls_rgw_usage_log_trim(ioctx, oid, user, start_epoch, end_epoch)); + ASSERT_EQ(0, cls_rgw_usage_log_trim(ioctx, oid, user, "", start_epoch, end_epoch)); - ret = cls_rgw_usage_log_read(ioctx, oid, user, start_epoch, end_epoch, + ret = cls_rgw_usage_log_read(ioctx, oid, user, "", start_epoch, end_epoch, max_entries, read_iter, usage2, &truncated); ASSERT_EQ(0, ret); - ASSERT_EQ(0, usage2.size()); + ASSERT_EQ(0u, usage2.size()); + // add and read to assert that bucket option is valid for usage reading + string bucket1 = "bucket-usage-1"; + string bucket2 = "bucket-usage-2"; + info = gen_usage_log_info(payer, bucket1, 100); + cls_rgw_usage_log_add(op, info); + ASSERT_EQ(0, ioctx.operate(oid, &op)); + + info = gen_usage_log_info(payer, bucket2, 100); + cls_rgw_usage_log_add(op, info); + ASSERT_EQ(0, ioctx.operate(oid, &op)); + ret = cls_rgw_usage_log_read(ioctx, oid, "", bucket1, start_epoch, end_epoch, + max_entries, read_iter, usage2, &truncated); + ASSERT_EQ(0, ret); + ASSERT_EQ(100, usage2.size()); + + // delete and read to assert that bucket option is valid for usage trim + ASSERT_EQ(0, cls_rgw_usage_log_trim(ioctx, oid, "", bucket1, start_epoch, end_epoch)); + + ret = cls_rgw_usage_log_read(ioctx, oid, "", bucket1, start_epoch, end_epoch, + max_entries, read_iter, usage2, &truncated); + ASSERT_EQ(0, ret); + ASSERT_EQ(0, usage2.size()); + ASSERT_EQ(0, cls_rgw_usage_log_trim(ioctx, oid, "", bucket2, start_epoch, end_epoch)); } TEST(cls_rgw, usage_clear_no_obj) @@@ -876,10 -910,10 +910,10 @@@ TEST(cls_rgw, usage_clear bool truncated; uint64_t start_epoch{0}, end_epoch{(uint64_t) -1}; string read_iter; - ret = cls_rgw_usage_log_read(ioctx, oid, user, start_epoch, end_epoch, + ret = cls_rgw_usage_log_read(ioctx, oid, user, "", start_epoch, end_epoch, max_entries, read_iter, usage, &truncated); ASSERT_EQ(0, ret); - ASSERT_EQ(0, usage.size()); + ASSERT_EQ(0u, usage.size()); }