]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add functions to list and abort multipart uploads
authorAbhishek Varshney <abhishek.varshney@flipkart.com>
Fri, 16 Jun 2017 12:14:57 +0000 (17:44 +0530)
committerAbhishek Varshney <abhishek.varshney@flipkart.com>
Tue, 20 Jun 2017 17:42:16 +0000 (17:42 +0000)
* list_bucket_multiparts()
* abort_bucket_multiparts()

Fixes: http://tracker.ceph.com/issues/17164
Signed-off-by: Abhishek Varshney <abhishek.varshney@flipkart.com>
src/rgw/rgw_multi.cc
src/rgw/rgw_multi.h

index 220cc5071948827195a497e15db47ac6cc8052e4..d455f9b8f8fb13a8b3757990bc908e5e364505d4 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "rgw_xml.h"
 #include "rgw_multi.h"
+#include "rgw_op.h"
 
 #define dout_subsys ceph_subsys_rgw
 
@@ -245,3 +246,58 @@ int abort_multipart_upload(RGWRados *store, CephContext *cct, RGWObjectCtx *obj_
   return ret == -ENOENT?-ERR_NO_SUCH_UPLOAD:ret;
 }
 
+int list_bucket_multiparts(RGWRados *store, RGWBucketInfo& bucket_info,
+                                string& prefix, string& marker, string& delim,
+                                int& max_uploads, vector<rgw_bucket_dir_entry> *objs,
+                                map<string, bool> *common_prefixes, bool *is_truncated)
+{
+  RGWRados::Bucket target(store, bucket_info);
+  RGWRados::Bucket::List list_op(&target);
+  MultipartMetaFilter mp_filter;
+
+  list_op.params.prefix = prefix;
+  list_op.params.delim = delim;
+  list_op.params.marker = marker;
+  list_op.params.ns = RGW_OBJ_NS_MULTIPART;
+  list_op.params.filter = &mp_filter;
+
+  return(list_op.list_objects(max_uploads, objs, common_prefixes,is_truncated));
+}
+
+int abort_bucket_multiparts(RGWRados *store, CephContext *cct, RGWBucketInfo& bucket_info,
+                               string& prefix, string& delim)
+{
+  int ret, max = 1000, num_deleted = 0;
+  vector<rgw_bucket_dir_entry> objs;
+  RGWObjectCtx obj_ctx(store);
+  string marker;
+  map<string, bool> common_prefixes;
+  bool is_truncated;
+
+  do {
+    ret = list_bucket_multiparts(store, bucket_info, prefix, marker, delim,
+                               max, &objs, &common_prefixes, &is_truncated);
+    if (ret < 0) {
+      return ret;
+    }
+    if (!objs.empty()) {
+      RGWMultipartUploadEntry entry;
+      for (const auto& obj : objs) {
+        rgw_obj_key key(obj.key);
+        if (!entry.mp.from_meta(key.name))
+          continue;
+        entry.obj = obj;
+        ret = abort_multipart_upload(store, cct, &obj_ctx, bucket_info, entry.mp);
+        if (ret < 0) {
+          return ret;
+        }
+        num_deleted++;
+      }
+      if (num_deleted) {
+        ldout(store->ctx(),0) << "WARNING : aborted " << num_deleted << " incomplete multipart uploads" << dendl;
+      }
+    }
+  } while (is_truncated);
+
+  return ret;
+}
index 953a3624380d0ed3db16aa8a3aaf24c1cbec8106..f406213b4090fa72a455cd8245a96020469aa9d9 100644 (file)
@@ -98,4 +98,11 @@ extern int list_multipart_parts(RGWRados *store, struct req_state *s,
 extern int abort_multipart_upload(RGWRados *store, CephContext *cct, RGWObjectCtx *obj_ctx,
                                 RGWBucketInfo& bucket_info, RGWMPObj& mp_obj);
 
+extern int list_bucket_multiparts(RGWRados *store, RGWBucketInfo& bucket_info,
+                                string& prefix, string& marker, string& delim,
+                                int& max_uploads, vector<rgw_bucket_dir_entry> *objs,
+                                map<string, bool> *common_prefixes, bool *is_truncated);
+
+extern int abort_bucket_multiparts(RGWRados *store, CephContext *cct, RGWBucketInfo& bucket_info,
+                                string& prefix, string& delim);
 #endif