From: Casey Bodley Date: Thu, 26 Jan 2017 21:57:23 +0000 (-0500) Subject: radosgw-admin: add 'mdlog autotrim' command X-Git-Tag: v12.0.3~20^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=16462640a311fdd262a3ee74552fc2297a4f1db5;p=ceph.git radosgw-admin: add 'mdlog autotrim' command Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index d941de8783e3..b412b5c9faa2 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -421,6 +421,7 @@ enum { OPT_METADATA_SYNC_INIT, OPT_METADATA_SYNC_RUN, OPT_MDLOG_LIST, + OPT_MDLOG_AUTOTRIM, OPT_MDLOG_TRIM, OPT_MDLOG_FETCH, OPT_MDLOG_STATUS, @@ -819,6 +820,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_ } else if (strcmp(prev_cmd, "mdlog") == 0) { if (strcmp(cmd, "list") == 0) return OPT_MDLOG_LIST; + if (strcmp(cmd, "autotrim") == 0) + return OPT_MDLOG_AUTOTRIM; if (strcmp(cmd, "trim") == 0) return OPT_MDLOG_TRIM; if (strcmp(cmd, "fetch") == 0) @@ -6173,6 +6176,26 @@ next: formatter->flush(cout); } + if (opt_cmd == OPT_MDLOG_AUTOTRIM) { + // need a full history for purging old mdlog periods + store->meta_mgr->init_oldest_log_period(); + + RGWCoroutinesManager crs(store->ctx(), store->get_cr_registry()); + RGWHTTPManager http(store->ctx(), crs.get_completion_mgr()); + int ret = http.set_threaded(); + if (ret < 0) { + cerr << "failed to initialize http client with " << cpp_strerror(ret) << std::endl; + return -ret; + } + + auto num_shards = g_conf->rgw_md_log_max_shards; + ret = crs.run(create_admin_meta_log_trim_cr(store, &http, num_shards)); + if (ret < 0) { + cerr << "automated mdlog trim failed with " << cpp_strerror(ret) << std::endl; + return -ret; + } + } + if (opt_cmd == OPT_MDLOG_TRIM) { utime_t start_time, end_time; diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index f402916fcdfe..e14f941a8f11 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -2962,3 +2962,28 @@ RGWCoroutine* create_meta_log_trim_cr(RGWRados *store, RGWHTTPManager *http, } return new MetaPeerTrimPollCR(store, http, num_shards, interval); } + + +struct MetaMasterAdminTrimCR : private MasterTrimEnv, public MetaMasterTrimCR { + MetaMasterAdminTrimCR(RGWRados *store, RGWHTTPManager *http, int num_shards) + : MasterTrimEnv(store, http, num_shards), + MetaMasterTrimCR(*static_cast(this)) + {} +}; + +struct MetaPeerAdminTrimCR : private PeerTrimEnv, public MetaPeerTrimCR { + MetaPeerAdminTrimCR(RGWRados *store, RGWHTTPManager *http, int num_shards) + : PeerTrimEnv(store, http, num_shards), + MetaPeerTrimCR(*static_cast(this)) + {} +}; + +RGWCoroutine* create_admin_meta_log_trim_cr(RGWRados *store, + RGWHTTPManager *http, + int num_shards) +{ + if (store->is_meta_master()) { + return new MetaMasterAdminTrimCR(store, http, num_shards); + } + return new MetaPeerAdminTrimCR(store, http, num_shards); +} diff --git a/src/rgw/rgw_sync.h b/src/rgw/rgw_sync.h index 0f1719b279fb..3672f4b8bf65 100644 --- a/src/rgw/rgw_sync.h +++ b/src/rgw/rgw_sync.h @@ -454,4 +454,9 @@ public: RGWCoroutine* create_meta_log_trim_cr(RGWRados *store, RGWHTTPManager *http, int num_shards, utime_t interval); +// factory function for mdlog trim via radosgw-admin +RGWCoroutine* create_admin_meta_log_trim_cr(RGWRados *store, + RGWHTTPManager *http, + int num_shards); + #endif