]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
radosgw-admin: orphans finish command
authorYehuda Sadeh <yehuda@redhat.com>
Mon, 4 May 2015 21:39:20 +0000 (14:39 -0700)
committerLoic Dachary <ldachary@redhat.com>
Sun, 30 Aug 2015 15:55:59 +0000 (17:55 +0200)
A command to remove orphans data

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
(cherry picked from commit 55d6f5ecf18f532c7f056f8b60c101843594b00c)

src/rgw/rgw_admin.cc
src/rgw/rgw_orphan.cc
src/rgw/rgw_orphan.h

index 7008d6544ef12818eb08803cd423c94dc428a50a..1d24ff5dc7d0563d15a4c8d4aba5c66b1443cb5a 100644 (file)
@@ -234,6 +234,7 @@ enum {
   OPT_GC_LIST,
   OPT_GC_PROCESS,
   OPT_ORPHANS_FIND,
+  OPT_ORPHANS_FINISH,
   OPT_REGION_GET,
   OPT_REGION_LIST,
   OPT_REGION_SET,
@@ -447,6 +448,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
   } else if (strcmp(prev_cmd, "orphans") == 0) {
     if (strcmp(cmd, "find") == 0)
       return OPT_ORPHANS_FIND;
+    if (strcmp(cmd, "finish") == 0)
+      return OPT_ORPHANS_FINISH;
   } else if (strcmp(prev_cmd, "metadata") == 0) {
     if (strcmp(cmd, "get") == 0)
       return OPT_METADATA_GET;
@@ -2587,7 +2590,7 @@ next:
     RGWOrphanSearchInfo info, *pinfo = NULL;
     if (init_search) {
       if (pool_name.empty()) {
-        cerr << "ERROR: --pool-name not specified" << std::endl;
+        cerr << "ERROR: --pool not specified" << std::endl;
         return EINVAL;
       }
       info.pool = pool_name;
@@ -2612,6 +2615,26 @@ next:
     }
   }
 
+  if (opt_cmd == OPT_ORPHANS_FINISH) {
+    RGWOrphanSearch search(store, max_concurrent_ios);
+
+    if (job_id.empty()) {
+      cerr << "ERROR: --job-id not specified" << std::endl;
+      return EINVAL;
+    }
+    int ret = search.init(job_id, NULL);
+    if (ret < 0) {
+      if (ret == -ENOENT) {
+        cerr << "job not found" << std::endl;
+      }
+      return -ret;
+    }
+    ret = search.finish();
+    if (ret < 0) {
+      return -ret;
+    }
+  }
+
   if (opt_cmd == OPT_USER_CHECK) {
     check_bad_user_bucket_mapping(store, user_id, fix);
   }
index 47721c8a52d9843a404e43681ee1bc43eda7ca8b..8600c2e48a3242571cdc64da209df3a143b39812 100644 (file)
@@ -96,6 +96,19 @@ int RGWOrphanStore::write_job(const string& job_name, const RGWOrphanSearchState
   return 0;
 }
 
+int RGWOrphanStore::remove_job(const string& job_name)
+{
+  set<string> keys;
+  keys.insert(job_name);
+
+  int r = ioctx.omap_rm_keys(oid, keys);
+  if (r < 0) {
+    return r;
+  }
+
+  return 0;
+}
+
 int RGWOrphanStore::init()
 {
   const char *log_pool = store->get_zone_params().log_pool.name.c_str();
@@ -731,3 +744,40 @@ int RGWOrphanSearch::run()
 }
 
 
+int RGWOrphanSearch::remove_index(map<int, string>& index)
+{
+  librados::IoCtx& ioctx = orphan_store.get_ioctx();
+
+  for (map<int, string>::iterator iter = index.begin(); iter != index.end(); ++iter) {
+    int r = ioctx.remove(iter->second);
+    if (r < 0) {
+      if (r != -ENOENT) {
+        ldout(store->ctx(), 0) << "ERROR: couldn't remove " << iter->second << ": ret=" << r << dendl;
+      }
+    }
+  }
+  return 0;
+}
+
+int RGWOrphanSearch::finish()
+{
+  int r = remove_index(all_objs_index);
+  if (r < 0) {
+    ldout(store->ctx(), 0) << "ERROR: remove_index(" << all_objs_index << ") returned ret=" << r << dendl;
+  }
+  r = remove_index(buckets_instance_index);
+  if (r < 0) {
+    ldout(store->ctx(), 0) << "ERROR: remove_index(" << buckets_instance_index << ") returned ret=" << r << dendl;
+  }
+  r = remove_index(linked_objs_index);
+  if (r < 0) {
+    ldout(store->ctx(), 0) << "ERROR: remove_index(" << linked_objs_index << ") returned ret=" << r << dendl;
+  }
+
+  r = orphan_store.remove_job(search_info.job_name);
+  if (r < 0) {
+    ldout(store->ctx(), 0) << "ERROR: could not remove job name (" << search_info.job_name << ") ret=" << r << dendl;
+  }
+
+  return r;
+}
index 2b2850a84e135e4cfaf2f141823b31454ca14527..076d07eb589dc7d517bec6507019fe1ea4eb7b9b 100644 (file)
@@ -133,6 +133,7 @@ public:
 
   int read_job(const string& job_name, RGWOrphanSearchState& state);
   int write_job(const string& job_name, const RGWOrphanSearchState& state);
+  int remove_job(const string& job_name);
 
 
   int store_entries(const string& oid, const map<string, bufferlist>& entries);
@@ -142,7 +143,6 @@ public:
 
 class RGWOrphanSearch {
   RGWRados *store;
-  librados::IoCtx log_ioctx;
 
   RGWOrphanStore orphan_store;
 
@@ -173,6 +173,8 @@ class RGWOrphanSearch {
   int handle_stat_result(map<int, list<string> >& oids, RGWRados::Object::Stat::Result& result);
   int pop_and_handle_stat_op(map<int, list<string> >& oids, std::deque<RGWRados::Object::Stat>& ops);
 
+
+  int remove_index(map<int, string>& index);
 public:
   RGWOrphanSearch(RGWRados *_store, int _max_ios) : store(_store), orphan_store(store), max_concurrent_ios(_max_ios) {}
 
@@ -194,6 +196,7 @@ public:
   int compare_oid_indexes();
 
   int run();
+  int finish();
 };