From: Yehuda Sadeh Date: Tue, 28 Apr 2015 23:45:49 +0000 (-0700) Subject: rgw-admin: build index of bucket indexes X-Git-Tag: v9.0.3~76^2~18 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=16a2dbd838b69fb445c06122a68fc65ec3a7b3de;p=ceph.git rgw-admin: build index of bucket indexes for the orphan search tool Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_orphan.cc b/src/rgw/rgw_orphan.cc index 42e05d12d98c..57d96c057e18 100644 --- a/src/rgw/rgw_orphan.cc +++ b/src/rgw/rgw_orphan.cc @@ -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 >& oids) +int RGWOrphanSearch::log_oids(map& log_shards, map >& oids) { map >::iterator miter = oids.begin(); @@ -131,7 +134,7 @@ int RGWOrphanSearch::log_oids(map >& 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 > instances; + + bool truncated; + + RGWObjectCtx obj_ctx(store); + + int count = 0; + + do { + list 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::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; diff --git a/src/rgw/rgw_orphan.h b/src/rgw/rgw_orphan.h index 82de63574cac..29f62114b320 100644 --- a/src/rgw/rgw_orphan.h +++ b/src/rgw/rgw_orphan.h @@ -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 orphan_objs_log; + map all_objs_index; + map buckets_instance_index; - string log_objs_prefix; + string index_objs_prefix; struct log_iter_info { string oid; @@ -129,7 +131,7 @@ class RGWOrphanSearch { list::iterator end; }; - int log_oids(map >& oids); + int log_oids(map& log_shards, map >& 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(); };