]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw-admin: build index of bucket indexes
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 28 Apr 2015 23:45:49 +0000 (16:45 -0700)
committerLoic Dachary <ldachary@redhat.com>
Sun, 30 Aug 2015 15:55:58 +0000 (17:55 +0200)
for the orphan search tool

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

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

index 42e05d12d98c76dd0d5fbfefba2018377157720a..57d96c057e18dc2cc60e6773238c38cc58246333 100644 (file)
@@ -111,19 +111,22 @@ int RGWOrphanSearch::init(const string& job_name, RGWOrphanSearchInfo *info) {
     search_state = state.state;
   }
 
-  log_objs_prefix = RGW_ORPHAN_LOG_PREFIX + string(".");
-  log_objs_prefix += job_name;
+  index_objs_prefix = RGW_ORPHAN_INDEX_PREFIX + string(".");
+  index_objs_prefix += job_name;
 
   for (int i = 0; i < search_info.num_shards; i++) {
     char buf[128];
 
-    snprintf(buf, sizeof(buf), "%s.%d", log_objs_prefix.c_str(), i);
-    orphan_objs_log[i] = buf;
+    snprintf(buf, sizeof(buf), "%s.rados.%d", index_objs_prefix.c_str(), i);
+    all_objs_index[i] = buf;
+
+    snprintf(buf, sizeof(buf), "%s.buckets.%d", index_objs_prefix.c_str(), i);
+    buckets_instance_index[i] = buf;
   }
   return 0;
 }
 
-int RGWOrphanSearch::log_oids(map<int, list<string> >& oids)
+int RGWOrphanSearch::log_oids(map<int, string>& log_shards, map<int, list<string> >& oids)
 {
   map<int, list<string> >::iterator miter = oids.begin();
 
@@ -131,7 +134,7 @@ int RGWOrphanSearch::log_oids(map<int, list<string> >& oids)
 
   for (; miter != oids.end(); ++miter) {
     log_iter_info info;
-    info.oid = orphan_objs_log[miter->first];
+    info.oid = log_shards[miter->first];
     info.cur = miter->second.begin();
     info.end = miter->second.end();
     liters.push_back(info);
@@ -210,7 +213,7 @@ int RGWOrphanSearch::build_all_oids_index()
 
 #define COUNT_BEFORE_FLUSH 1000
     if (++count >= COUNT_BEFORE_FLUSH) {
-      ret = log_oids(oids);
+      ret = log_oids(all_objs_index, oids);
       if (ret < 0) {
         cerr << __func__ << ": ERROR: log_oids() returned ret=" << ret << std::endl;
         return ret;
@@ -219,7 +222,7 @@ int RGWOrphanSearch::build_all_oids_index()
       oids.clear();
     }
   }
-  ret = log_oids(oids);
+  ret = log_oids(all_objs_index, oids);
   if (ret < 0) {
     cerr << __func__ << ": ERROR: log_oids() returned ret=" << ret << std::endl;
     return ret;
@@ -228,6 +231,57 @@ int RGWOrphanSearch::build_all_oids_index()
   return 0;
 }
 
+int RGWOrphanSearch::build_buckets_instance_index()
+{
+  void *handle;
+  int max = 1000;
+  string section = "bucket.instance";
+  int ret = store->meta_mgr->list_keys_init(section, &handle);
+  if (ret < 0) {
+    cerr << "ERROR: can't get key: " << cpp_strerror(-ret) << std::endl;
+    return -ret;
+  }
+
+  map<int, list<string> > instances;
+
+  bool truncated;
+
+  RGWObjectCtx obj_ctx(store);
+
+  int count = 0;
+
+  do {
+    list<string> keys;
+    ret = store->meta_mgr->list_keys_next(handle, max, keys, &truncated);
+    if (ret < 0) {
+      cerr << "ERROR: lists_keys_next(): " << cpp_strerror(-ret) << std::endl;
+      return -ret;
+    }
+
+    for (list<string>::iterator iter = keys.begin(); iter != keys.end(); ++iter) {
+      // ssize_t pos = iter->find(':');
+      // string bucket_id = iter->substr(pos + 1);
+
+      int shard = orphan_shard(*iter);
+      instances[shard].push_back(*iter);
+
+      if (++count >= COUNT_BEFORE_FLUSH) {
+        ret = log_oids(buckets_instance_index, instances);
+        if (ret < 0) {
+          cerr << __func__ << ": ERROR: log_oids() returned ret=" << ret << std::endl;
+          return ret;
+        }
+        count = 0;
+        instances.clear();
+      }
+    }
+  } while (truncated);
+
+  store->meta_mgr->list_keys_complete(handle);
+
+  return 0;
+}
+
 int RGWOrphanSearch::run()
 {
   int r;
@@ -244,7 +298,7 @@ int RGWOrphanSearch::run()
       }
       // fall through
     case ORPHAN_SEARCH_LSPOOL:
-      ldout(store->ctx(), 0) << __func__ << "(): listing all objects in pool" << dendl;
+      ldout(store->ctx(), 0) << __func__ << "(): building index of all objects in pool" << dendl;
       r = build_all_oids_index();
       if (r < 0) {
         lderr(store->ctx()) << __func__ << ": ERROR: build_all_objs_index returnr ret=" << r << dendl;
@@ -260,6 +314,23 @@ int RGWOrphanSearch::run()
       // fall through
 
     case ORPHAN_SEARCH_LSBUCKETS:
+      ldout(store->ctx(), 0) << __func__ << "(): building index of all bucket indexes" << dendl;
+      r = build_buckets_instance_index();
+      if (r < 0) {
+        lderr(store->ctx()) << __func__ << ": ERROR: build_all_objs_index returnr ret=" << r << dendl;
+        return r;
+      }
+
+      search_state = ORPHAN_SEARCH_ITERATE_BI;
+      r = save_state();
+      if (r < 0) {
+        lderr(store->ctx()) << __func__ << ": ERROR: failed to save state, ret=" << r << dendl;
+        return r;
+      }
+      // fall through
+
+
+    case ORPHAN_SEARCH_ITERATE_BI:
     case ORPHAN_SEARCH_DONE:
       break;
 
index 82de63574caceff55c5a07912ba87ea1dd07bbec..29f62114b320938358b806e76155e9cff39eabe6 100644 (file)
@@ -24,7 +24,7 @@
 #define dout_subsys ceph_subsys_rgw
 
 #define RGW_ORPHAN_INDEX_OID "orphan.index"
-#define RGW_ORPHAN_LOG_PREFIX "orphan.scan"
+#define RGW_ORPHAN_INDEX_PREFIX "orphan.scan"
 
 
 enum OrphanSearchState {
@@ -32,7 +32,8 @@ enum OrphanSearchState {
   ORPHAN_SEARCH_INIT = 1,
   ORPHAN_SEARCH_LSPOOL = 2,
   ORPHAN_SEARCH_LSBUCKETS = 3,
-  ORPHAN_SEARCH_DONE = 4,
+  ORPHAN_SEARCH_ITERATE_BI = 4,
+  ORPHAN_SEARCH_DONE = 5,
 };
 
 
@@ -119,9 +120,10 @@ class RGWOrphanSearch {
   RGWOrphanSearchInfo search_info;
   OrphanSearchState search_state;
 
-  map<int, string> orphan_objs_log;
+  map<int, string> all_objs_index;
+  map<int, string> buckets_instance_index;
 
-  string log_objs_prefix;
+  string index_objs_prefix;
 
   struct log_iter_info {
     string oid;
@@ -129,7 +131,7 @@ class RGWOrphanSearch {
     list<string>::iterator end;
   };
 
-  int log_oids(map<int, list<string> >& oids);
+  int log_oids(map<int, string>& log_shards, map<int, list<string> >& oids);
 
 #define RGW_ORPHANSEARCH_HASH_PRIME 7877
   int orphan_shard(const string& str) {
@@ -151,6 +153,8 @@ public:
   int create(const string& job_name, int num_shards);
 
   int build_all_oids_index();
+  int build_buckets_instance_index();
+
   int run();
 };