]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/rgw: trim all usage entries in cls_rgw
authorAbhishek Lekshmanan <abhishek@suse.com>
Tue, 21 Nov 2017 15:38:27 +0000 (16:38 +0100)
committerAbhishek Lekshmanan <abhishek@suse.com>
Tue, 28 Nov 2017 10:31:44 +0000 (11:31 +0100)
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 <abhishek@suse.com>
src/cls/rgw/cls_rgw.cc
src/cls/rgw/cls_rgw_client.cc
src/cls/rgw/cls_rgw_client.h
src/rgw/rgw_rados.cc

index ba3d4c4bb1b2d720a7103fba06c6d9eb687b0372..c10ed0351241c78b3b540b2495232df02f900922 100644 (file)
@@ -2952,17 +2952,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;
     }
 
@@ -3078,6 +3074,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;
 }
 
index 11b8df4fec520b1b1719e4890d1324514b58090a..3c4ed919a6de243a20d8d30978099aecb10d43c8 100644 (file)
@@ -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;
index e33dfe668d9cb7aa58ae92fc9308d0ba2e6a50e9..c4ab0f648a5c2ac922142a2de2c8a9c522ec3f2a 100644 (file)
@@ -503,7 +503,7 @@ int cls_rgw_usage_log_read(librados::IoCtx& io_ctx, string& oid, string& user,
                            string& read_iter, map<rgw_user_bucket, rgw_usage_log_entry>& 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);
index e21d4bbca46608f8f2d9323a7e18e021662ae622..c479a59fb86cc84b4d97e36bff584d049ad18d76 100644 (file)
@@ -5123,16 +5123,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);
 
@@ -12881,10 +12877,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;
 }