From 7810567fa37308bfeadf63e65f08adc36bfb886e Mon Sep 17 00:00:00 2001 From: Abhishek Lekshmanan Date: Tue, 21 Nov 2017 16:38:27 +0100 Subject: [PATCH] cls/rgw: trim all usage entries in cls_rgw Currently trim usage will only trim upto 128 omap entries, since we need to run this in a loop until we're done, actually make the cls return -ENODATA so that we know when to stop the loop (inspired by a similar call in cls_log) this involves the following changes * return -ENODATA when iterate entries goes through and the value of iter (which is set as the last value of key when succeeded) * use IoCtx for calling the loop from within cls rather than in rgw * drop the goto call in rgw_rados since we can return once we're done processing Fixes: http://tracker.ceph.com/issues/22234 Signed-off-by: Abhishek Lekshmanan (cherry picked from commit b548a3f3443452210d92cad574bcb73ba6d2ce42) --- src/cls/rgw/cls_rgw.cc | 11 +++++------ src/cls/rgw/cls_rgw_client.cc | 20 +++++++++++++++++--- src/cls/rgw/cls_rgw_client.h | 2 +- src/rgw/rgw_rados.cc | 11 ++--------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/cls/rgw/cls_rgw.cc b/src/cls/rgw/cls_rgw.cc index 354a132da4881..564e81d179dc2 100644 --- a/src/cls/rgw/cls_rgw.cc +++ b/src/cls/rgw/cls_rgw.cc @@ -2955,17 +2955,13 @@ static int usage_iterate_range(cls_method_context_t hctx, uint64_t start, uint64 if (!by_user && key.compare(end_key) >= 0) { CLS_LOG(20, "usage_iterate_range reached key=%s, done", key.c_str()); - if (truncated_status) { - key_iter = key; - } + key_iter = key; return 0; } if (by_user && key.compare(0, user_key.size(), user_key) != 0) { CLS_LOG(20, "usage_iterate_range reached key=%s, done", key.c_str()); - if (truncated_status) { - key_iter = key; - } + key_iter = key; return 0; } @@ -3081,6 +3077,9 @@ int rgw_user_usage_log_trim(cls_method_context_t hctx, bufferlist *in, bufferlis if (ret < 0) return ret; + if (!more && iter.empty()) + return -ENODATA; + return 0; } diff --git a/src/cls/rgw/cls_rgw_client.cc b/src/cls/rgw/cls_rgw_client.cc index 11b8df4fec520..3c4ed919a6de2 100644 --- a/src/cls/rgw/cls_rgw_client.cc +++ b/src/cls/rgw/cls_rgw_client.cc @@ -624,8 +624,8 @@ int cls_rgw_usage_log_read(IoCtx& io_ctx, string& oid, string& user, return 0; } -void cls_rgw_usage_log_trim(ObjectWriteOperation& op, string& user, - uint64_t start_epoch, uint64_t end_epoch) +int cls_rgw_usage_log_trim(IoCtx& io_ctx, const string& oid, string& user, + uint64_t start_epoch, uint64_t end_epoch) { bufferlist in; rgw_cls_usage_log_trim_op call; @@ -633,9 +633,23 @@ void cls_rgw_usage_log_trim(ObjectWriteOperation& op, string& user, call.end_epoch = end_epoch; call.user = user; ::encode(call, in); - op.exec(RGW_CLASS, RGW_USER_USAGE_LOG_TRIM, in); + + bool done = false; + do { + ObjectWriteOperation op; + op.exec(RGW_CLASS, RGW_USER_USAGE_LOG_TRIM, in); + int r = io_ctx.operate(oid, &op); + if (r == -ENODATA) + done = true; + else if (r < 0) + return r; + } while (!done); + + return 0; } + + void cls_rgw_usage_log_add(ObjectWriteOperation& op, rgw_usage_log_info& info) { bufferlist in; diff --git a/src/cls/rgw/cls_rgw_client.h b/src/cls/rgw/cls_rgw_client.h index 3a49c2dbbefd6..936a1a19b212f 100644 --- a/src/cls/rgw/cls_rgw_client.h +++ b/src/cls/rgw/cls_rgw_client.h @@ -493,7 +493,7 @@ int cls_rgw_usage_log_read(librados::IoCtx& io_ctx, string& oid, string& user, string& read_iter, map& usage, bool *is_truncated); -void cls_rgw_usage_log_trim(librados::ObjectWriteOperation& op, string& user, +int cls_rgw_usage_log_trim(librados::IoCtx& io_ctx, const string& oid, string& user, uint64_t start_epoch, uint64_t end_epoch); void cls_rgw_usage_log_add(librados::ObjectWriteOperation& op, rgw_usage_log_info& info); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index a44fc01a85034..593787e191438 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -5140,16 +5140,12 @@ int RGWRados::trim_usage(rgw_user& user, uint64_t start_epoch, uint64_t end_epoc usage_log_hash(cct, user_str, first_hash, index); hash = first_hash; - do { int ret = cls_obj_usage_log_trim(hash, user_str, start_epoch, end_epoch); - if (ret == -ENOENT) - goto next; - if (ret < 0) + if (ret < 0 && ret != -ENOENT) return ret; -next: usage_log_hash(cct, user_str, hash, ++index); } while (hash != first_hash); @@ -12928,10 +12924,7 @@ int RGWRados::cls_obj_usage_log_trim(string& oid, string& user, uint64_t start_e return r; } - ObjectWriteOperation op; - cls_rgw_usage_log_trim(op, user, start_epoch, end_epoch); - - r = ref.ioctx.operate(ref.oid, &op); + r = cls_rgw_usage_log_trim(ref.ioctx, ref.oid, user, start_epoch, end_epoch); return r; } -- 2.39.5