From f80e2b2bc8879d1cc40338816196f51378aaa785 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 4 May 2015 14:39:20 -0700 Subject: [PATCH] radosgw-admin: orphans finish command A command to remove orphans data Signed-off-by: Yehuda Sadeh (cherry picked from commit 55d6f5ecf18f532c7f056f8b60c101843594b00c) --- src/rgw/rgw_admin.cc | 25 +++++++++++++++++++++- src/rgw/rgw_orphan.cc | 50 +++++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_orphan.h | 5 ++++- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 7008d6544ef12..1d24ff5dc7d05 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -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); } diff --git a/src/rgw/rgw_orphan.cc b/src/rgw/rgw_orphan.cc index 47721c8a52d98..8600c2e48a324 100644 --- a/src/rgw/rgw_orphan.cc +++ b/src/rgw/rgw_orphan.cc @@ -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 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& index) +{ + librados::IoCtx& ioctx = orphan_store.get_ioctx(); + + for (map::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; +} diff --git a/src/rgw/rgw_orphan.h b/src/rgw/rgw_orphan.h index 2b2850a84e135..076d07eb589dc 100644 --- a/src/rgw/rgw_orphan.h +++ b/src/rgw/rgw_orphan.h @@ -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& 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 >& oids, RGWRados::Object::Stat::Result& result); int pop_and_handle_stat_op(map >& oids, std::deque& ops); + + int remove_index(map& 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(); }; -- 2.39.5