diff options
author | J. Eric Ivancich <ivancich@users.noreply.github.com> | 2019-04-03 18:34:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-03 18:34:20 +0200 |
commit | 00ec1eeccbd1c7302fd3095546c42cfce8d82153 (patch) | |
tree | 4b6956cd87a0ce6a2303607558528bbdd0c6d54d | |
parent | Merge PR #27343 into master (diff) | |
parent | rgw_orphan: fix detailed mode flag (diff) | |
download | ceph-00ec1eeccbd1c7302fd3095546c42cfce8d82153.tar.xz ceph-00ec1eeccbd1c7302fd3095546c42cfce8d82153.zip |
Merge pull request #26412 from theanalyst/rgw-orphan-fixes
rgw: orphan fixes
-rw-r--r-- | src/rgw/rgw_admin.cc | 6 | ||||
-rw-r--r-- | src/rgw/rgw_orphan.cc | 76 | ||||
-rw-r--r-- | src/rgw/rgw_orphan.h | 5 | ||||
-rw-r--r-- | src/test/cli/radosgw-admin/help.t | 1 |
4 files changed, 76 insertions, 12 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 7cd368e9e6f..b844c2447ba 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -356,6 +356,7 @@ void usage() cout << " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n"; cout << " --job-id set the job id (for orphans find)\n"; cout << " --max-concurrent-ios maximum concurrent ios for orphans find (default: 32)\n"; + cout << " --detail detailed mode, log and stat head objects as well\n"; cout << "\nOrphans list-jobs options:\n"; cout << " --extra-info provide extra info in job list\n"; cout << "\nRole options:\n"; @@ -2839,6 +2840,7 @@ int main(int argc, const char **argv) bool num_shards_specified = false; int max_concurrent_ios = 32; uint64_t orphan_stale_secs = (24 * 3600); + int detail = false; std::string val; std::ostringstream errs; @@ -3213,6 +3215,8 @@ int main(int argc, const char **argv) event_id = val; } else if (ceph_argparse_witharg(args, i, &val, "--event-type", "--event-types", (char*)NULL)) { get_str_set(val, ",", event_types); + } else if (ceph_argparse_binary_flag(args, i, &detail, NULL, "--detail", (char*)NULL)) { + // do nothing } else if (strncmp(*i, "-", 1) == 0) { cerr << "ERROR: invalid flag " << *i << std::endl; return EINVAL; @@ -6618,7 +6622,7 @@ next: info.job_name = job_id; info.num_shards = num_shards; - int ret = search.init(job_id, &info); + int ret = search.init(job_id, &info, detail); if (ret < 0) { cerr << "could not init search, ret=" << ret << std::endl; return -ret; diff --git a/src/rgw/rgw_orphan.cc b/src/rgw/rgw_orphan.cc index 930bbb04895..567bb93b4fd 100644 --- a/src/rgw/rgw_orphan.cc +++ b/src/rgw/rgw_orphan.cc @@ -11,6 +11,7 @@ #include "rgw_rados.h" #include "rgw_orphan.h" #include "rgw_zone.h" +#include "rgw_bucket.h" #include "services/svc_zone.h" #include "services/svc_sys_obj.h" @@ -185,12 +186,19 @@ int RGWOrphanStore::read_entries(const string& oid, const string& marker, map<st return 0; } -int RGWOrphanSearch::init(const string& job_name, RGWOrphanSearchInfo *info) { +int RGWOrphanSearch::init(const string& job_name, RGWOrphanSearchInfo *info, bool _detailed_mode) +{ int r = orphan_store.init(); if (r < 0) { return r; } + constexpr int64_t MAX_LIST_OBJS_ENTRIES=100; + + max_list_bucket_entries = std::max(store->ctx()->_conf->rgw_list_bucket_min_readahead, + MAX_LIST_OBJS_ENTRIES); + + detailed_mode = _detailed_mode; RGWOrphanSearchState state; r = orphan_store.read_job(job_name, state); if (r < 0 && r != -ENOENT) { @@ -432,6 +440,12 @@ int RGWOrphanSearch::handle_stat_result(map<int, list<string> >& oids, RGWRados: } else { RGWObjManifest& manifest = result.manifest; + if (!detailed_mode && + manifest.get_obj_size() <= manifest.get_head_size()) { + ldout(store->ctx(), 5) << "skipping object as it fits in a head" << dendl; + return 0; + } + RGWObjManifest::obj_iterator miter; for (miter = manifest.obj_begin(); miter != manifest.obj_end(); ++miter) { const rgw_raw_obj& loc = miter.get_location().get_raw_obj(store); @@ -472,11 +486,47 @@ done: int RGWOrphanSearch::build_linked_oids_for_bucket(const string& bucket_instance_id, map<int, list<string> >& oids) { - ldout(store->ctx(), 10) << "building linked oids for bucket instance: " << bucket_instance_id << dendl; - RGWBucketInfo bucket_info; RGWObjectCtx obj_ctx(store); auto sysobj_ctx = store->svc.sysobj->init_obj_ctx(); - int ret = store->get_bucket_instance_info(sysobj_ctx, bucket_instance_id, bucket_info, NULL, NULL); + + rgw_bucket orphan_bucket; + int shard_id; + int ret = rgw_bucket_parse_bucket_key(store->ctx(), bucket_instance_id, + &orphan_bucket, &shard_id); + if (ret < 0) { + ldout(store->ctx(),0) << __func__ << " failed to parse bucket instance: " + << bucket_instance_id << " skipping" << dendl; + return ret; + } + + RGWBucketInfo cur_bucket_info; + ret = store->get_bucket_info(sysobj_ctx, orphan_bucket.tenant, + orphan_bucket.name, cur_bucket_info, nullptr); + if (ret < 0) { + if (ret == -ENOENT) { + /* probably raced with bucket removal */ + return 0; + } + lderr(store->ctx()) << __func__ << ": ERROR: RGWRados::get_bucket_instance_info() returned ret=" << ret << dendl; + return ret; + } + + if (cur_bucket_info.bucket.bucket_id != orphan_bucket.bucket_id) { + ldout(store->ctx(), 0) << __func__ << ": Skipping stale bucket instance: " + << orphan_bucket.name << ": " + << orphan_bucket.bucket_id << dendl; + return 0; + } + + if (cur_bucket_info.reshard_status == CLS_RGW_RESHARD_IN_PROGRESS) { + ldout(store->ctx(), 0) << __func__ << ": reshard in progress. Skipping " + << orphan_bucket.name << ": " + << orphan_bucket.bucket_id << dendl; + return 0; + } + + RGWBucketInfo bucket_info; + ret = store->get_bucket_instance_info(sysobj_ctx, bucket_instance_id, bucket_info, nullptr, nullptr); if (ret < 0) { if (ret == -ENOENT) { /* probably raced with bucket removal */ @@ -486,6 +536,7 @@ int RGWOrphanSearch::build_linked_oids_for_bucket(const string& bucket_instance_ return ret; } + ldout(store->ctx(), 10) << "building linked oids for bucket instance: " << bucket_instance_id << dendl; RGWRados::Bucket target(store, bucket_info); RGWRados::Bucket::List list_op(&target); @@ -498,13 +549,11 @@ int RGWOrphanSearch::build_linked_oids_for_bucket(const string& bucket_instance_ deque<RGWRados::Object::Stat> stat_ops; - int count = 0; - do { vector<rgw_bucket_dir_entry> result; -#define MAX_LIST_OBJS_ENTRIES 100 - ret = list_op.list_objects(MAX_LIST_OBJS_ENTRIES, &result, NULL, &truncated); + ret = list_op.list_objects(max_list_bucket_entries, + &result, nullptr, &truncated); if (ret < 0) { cerr << "ERROR: store->list_objects(): " << cpp_strerror(-ret) << std::endl; return -ret; @@ -519,6 +568,14 @@ int RGWOrphanSearch::build_linked_oids_for_bucket(const string& bucket_instance_ } ldout(store->ctx(), 20) << __func__ << ": entry.key.name=" << entry.key.name << " entry.key.instance=" << entry.key.instance << dendl; + + if (!detailed_mode && + entry.meta.accounted_size <= (uint64_t)store->ctx()->_conf->rgw_max_chunk_size) { + ldout(store->ctx(),5) << __func__ << "skipping stat as the object " << entry.key.name + << "fits in a head" << dendl; + continue; + } + rgw_obj obj(bucket_info.bucket, entry.key); RGWRados::Object op_target(store, bucket_info, obj_ctx, obj); @@ -540,13 +597,12 @@ int RGWOrphanSearch::build_linked_oids_for_bucket(const string& bucket_instance_ } } } - if (++count >= COUNT_BEFORE_FLUSH) { + if (oids.size() >= COUNT_BEFORE_FLUSH) { ret = log_oids(linked_objs_index, oids); if (ret < 0) { cerr << __func__ << ": ERROR: log_oids() returned ret=" << ret << std::endl; return ret; } - count = 0; oids.clear(); } } diff --git a/src/rgw/rgw_orphan.h b/src/rgw/rgw_orphan.h index d8076faec9a..7d808eeda65 100644 --- a/src/rgw/rgw_orphan.h +++ b/src/rgw/rgw_orphan.h @@ -163,6 +163,9 @@ class RGWOrphanSearch { uint16_t max_concurrent_ios; uint64_t stale_secs; + int64_t max_list_bucket_entries; + + bool detailed_mode; struct log_iter_info { string oid; @@ -192,7 +195,7 @@ public: return orphan_store.write_job(search_info.job_name, state); } - int init(const string& job_name, RGWOrphanSearchInfo *info); + int init(const string& job_name, RGWOrphanSearchInfo *info, bool _detailed_mode=false); int create(const string& job_name, int num_shards); diff --git a/src/test/cli/radosgw-admin/help.t b/src/test/cli/radosgw-admin/help.t index e70c8588e46..1aa039e0617 100644 --- a/src/test/cli/radosgw-admin/help.t +++ b/src/test/cli/radosgw-admin/help.t @@ -280,6 +280,7 @@ --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400) --job-id set the job id (for orphans find) --max-concurrent-ios maximum concurrent ios for orphans find (default: 32) + --detail detailed mode, log and stat head objects as well Orphans list-jobs options: --extra-info provide extra info in job list |