From 3a72e48d5ea1219e9d396b78701022533418c9bf Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Mon, 18 Feb 2019 17:15:15 -0500 Subject: [PATCH] rgw: add 'datalog autotrim' admin command Signed-off-by: Casey Bodley (cherry picked from commit 832eaefa95c797870aa1a5fbdc885ca45a128c80) Conflicts: src/rgw/rgw_admin.cc : Resolved for g_conf --- src/rgw/rgw_admin.cc | 21 +++++++++++++++++++++ src/rgw/rgw_data_sync.cc | 8 ++++++++ src/rgw/rgw_data_sync.h | 6 ++++++ 3 files changed, 35 insertions(+) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index a278a0e155c17..805f5d22ffcf6 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -465,6 +465,7 @@ enum { OPT_DATA_SYNC_RUN, OPT_DATALOG_LIST, OPT_DATALOG_STATUS, + OPT_DATALOG_AUTOTRIM, OPT_DATALOG_TRIM, OPT_OPSTATE_LIST, OPT_OPSTATE_SET, @@ -909,6 +910,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_ } else if (strcmp(prev_cmd, "datalog") == 0) { if (strcmp(cmd, "list") == 0) return OPT_DATALOG_LIST; + if (strcmp(cmd, "autotrim") == 0) + return OPT_DATALOG_AUTOTRIM; if (strcmp(cmd, "trim") == 0) return OPT_DATALOG_TRIM; if (strcmp(cmd, "status") == 0) @@ -7414,6 +7417,24 @@ next: formatter->flush(cout); } + if (opt_cmd == OPT_DATALOG_AUTOTRIM) { + RGWCoroutinesManager crs(store->ctx(), store->get_cr_registry()); + RGWHTTPManager http(store->ctx(), crs.get_completion_mgr()); + int ret = http.start(); + if (ret < 0) { + cerr << "failed to initialize http client with " << cpp_strerror(ret) << std::endl; + return -ret; + } + + auto num_shards = g_conf->rgw_data_log_num_shards; + std::vector markers(num_shards); + ret = crs.run(create_admin_data_log_trim_cr(store, &http, num_shards, markers)); + if (ret < 0) { + cerr << "automated datalog trim failed with " << cpp_strerror(ret) << std::endl; + return -ret; + } + } + if (opt_cmd == OPT_DATALOG_TRIM) { utime_t start_time, end_time; diff --git a/src/rgw/rgw_data_sync.cc b/src/rgw/rgw_data_sync.cc index a740c4914672b..4f192eedc39e4 100644 --- a/src/rgw/rgw_data_sync.cc +++ b/src/rgw/rgw_data_sync.cc @@ -3602,6 +3602,14 @@ int DataLogTrimCR::operate() return 0; } +RGWCoroutine* create_admin_data_log_trim_cr(RGWRados *store, + RGWHTTPManager *http, + int num_shards, + std::vector& markers) +{ + return new DataLogTrimCR(store, http, num_shards, markers); +} + class DataLogTrimPollCR : public RGWCoroutine { RGWRados *store; RGWHTTPManager *http; diff --git a/src/rgw/rgw_data_sync.h b/src/rgw/rgw_data_sync.h index 2d24bf63121e4..0552a475d1a96 100644 --- a/src/rgw/rgw_data_sync.h +++ b/src/rgw/rgw_data_sync.h @@ -577,4 +577,10 @@ extern RGWCoroutine* create_data_log_trim_cr(RGWRados *store, RGWHTTPManager *http, int num_shards, utime_t interval); +// factory function for datalog trim via radosgw-admin +RGWCoroutine* create_admin_data_log_trim_cr(RGWRados *store, + RGWHTTPManager *http, + int num_shards, + std::vector& markers); + #endif -- 2.39.5