]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Fix up to 1000 entries at a time in check_bad_index_multipart 16880/head
authorOrit Wasserman <owasserm@redhat.com>
Mon, 31 Jul 2017 11:45:25 +0000 (14:45 +0300)
committerMatt Benjamin <mbenjamin@redhat.com>
Thu, 10 Aug 2017 19:53:19 +0000 (15:53 -0400)
Fixes: http://tracker.ceph.com/issues/20772
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
(cherry picked from commit 25cef9a09721e1a67d217535d4d624ab60adca02)
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h

index 88695ad74953ba0e6cc2161b33843312bec5e2d6..e44ccca1b59b0e2c48aee14f8ebaca3334928e2b 100644 (file)
@@ -431,16 +431,9 @@ int rgw_bucket_set_attrs(RGWRados *store, RGWBucketInfo& bucket_info,
 static void dump_mulipart_index_results(list<rgw_obj_key>& objs_to_unlink,
         Formatter *f)
 {
-  // make sure that an appropiately titled header has been opened previously
-  list<rgw_obj_key>::iterator oiter = objs_to_unlink.begin();
-
-  f->open_array_section("invalid_multipart_entries");
-
-  for ( ; oiter != objs_to_unlink.end(); ++oiter) {
-    f->dump_string("object",  oiter->name);
+  for (const auto& o : objs_to_unlink) {
+    f->dump_string("object",  o.name);
   }
-
-  f->close_section();
 }
 
 void check_bad_user_bucket_mapping(RGWRados *store, const rgw_user& user_id,
@@ -1008,12 +1001,13 @@ static void dump_index_check(map<RGWObjCategory, RGWStorageStats> existing_stats
 }
 
 int RGWBucket::check_bad_index_multipart(RGWBucketAdminOpState& op_state,
-        list<rgw_obj_key>& objs_to_unlink, std::string *err_msg)
+                                        RGWFormatterFlusher& flusher,
+                                        std::string *err_msg)
 {
   bool fix_index = op_state.will_fix_index();
   rgw_bucket bucket = op_state.get_bucket();
 
-  int max = 1000;
+  size_t max = 1000;
 
   map<string, bool> common_prefixes;
   string ns = "";
@@ -1076,6 +1070,11 @@ int RGWBucket::check_bad_index_multipart(RGWBucketAdminOpState& op_state,
 
   } while (is_truncated);
 
+  list<rgw_obj_key> objs_to_unlink;
+  Formatter *f =  flusher.get_formatter();
+
+  f->open_array_section("invalid_multipart_entries");
+
   map<rgw_obj_key, string>::iterator aiter;
   for (aiter = all_objs.begin(); aiter != all_objs.end(); ++aiter) {
     string& name = aiter->second;
@@ -1083,10 +1082,22 @@ int RGWBucket::check_bad_index_multipart(RGWBucketAdminOpState& op_state,
     if (meta_objs.find(name) == meta_objs.end()) {
       objs_to_unlink.push_back(aiter->first);
     }
-  }
 
-  if (objs_to_unlink.empty())
-    return 0;
+    if (objs_to_unlink.size() > max) {
+      if (fix_index) {
+       int r = store->remove_objs_from_index(bucket, objs_to_unlink);
+       if (r < 0) {
+         set_err_msg(err_msg, "ERROR: remove_obj_from_index() returned error: "
+                     + cpp_strerror(-r));
+         return r;
+       }
+      }
+
+      dump_mulipart_index_results(objs_to_unlink, flusher.get_formatter());
+      flusher.flush();
+      objs_to_unlink.clear();
+    }
+  }
 
   if (fix_index) {
     int r = store->remove_objs_from_index(bucket, objs_to_unlink);
@@ -1098,6 +1109,10 @@ int RGWBucket::check_bad_index_multipart(RGWBucketAdminOpState& op_state,
     }
   }
 
+  dump_mulipart_index_results(objs_to_unlink, f);
+  f->close_section();
+  flusher.flush();
+
   return 0;
 }
 
@@ -1315,7 +1330,6 @@ int RGWBucketAdminOp::check_index(RGWRados *store, RGWBucketAdminOpState& op_sta
   map<string, RGWObjEnt> result;
   map<RGWObjCategory, RGWStorageStats> existing_stats;
   map<RGWObjCategory, RGWStorageStats> calculated_stats;
-  list<rgw_obj_key> objs_to_unlink;
 
   RGWBucket bucket;
 
@@ -1326,13 +1340,10 @@ int RGWBucketAdminOp::check_index(RGWRados *store, RGWBucketAdminOpState& op_sta
   Formatter *formatter = flusher.get_formatter();
   flusher.start(0);
 
-  ret = bucket.check_bad_index_multipart(op_state, objs_to_unlink);
+  ret = bucket.check_bad_index_multipart(op_state, flusher);
   if (ret < 0)
     return ret;
 
-  dump_mulipart_index_results(objs_to_unlink, formatter);
-  flusher.flush();
-
   ret = bucket.check_object_index(op_state, result);
   if (ret < 0)
     return ret;
index 765ec6a6caac2a42f793cdd0fcbae3af4d2e5a7d..d68e890c901fb6be12680a2221d4aa78f206c393 100644 (file)
@@ -274,7 +274,8 @@ public:
   int init(RGWRados *storage, RGWBucketAdminOpState& op_state);
 
   int check_bad_index_multipart(RGWBucketAdminOpState& op_state,
-          list<rgw_obj_key>& objs_to_unlink, std::string *err_msg = NULL);
+                               RGWFormatterFlusher& flusher,
+                               std::string *err_msg = NULL);
 
   int check_object_index(RGWBucketAdminOpState& op_state,
           map<string, RGWObjEnt> result, std::string *err_msg = NULL);