From: Casey Bodley Date: Tue, 13 Nov 2018 22:06:56 +0000 (-0500) Subject: rgw: bucket trim restarts if list_keys_init() returns EINVAL X-Git-Tag: v14.1.0~761^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=72f7cd500d9b63ad874b0b14b5e0a59ed008965c;p=ceph.git rgw: bucket trim restarts if list_keys_init() returns EINVAL if the marker stored in bilog.trim is no longer valid, restart the listing with an empty marker Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_sync_log_trim.cc b/src/rgw/rgw_sync_log_trim.cc index cd15df604b7d..fd23ad59d920 100644 --- a/src/rgw/rgw_sync_log_trim.cc +++ b/src/rgw/rgw_sync_log_trim.cc @@ -17,6 +17,7 @@ #include #include +#include "include/scope_guard.h" #include "common/bounded_key_counter.h" #include "common/errno.h" #include "rgw_sync_log_trim.h" @@ -580,7 +581,6 @@ class AsyncMetadataList : public RGWAsyncRadosRequest { const std::string section; const std::string start_marker; MetadataListCallback callback; - void *handle{nullptr}; int _send_request() override; public: @@ -591,54 +591,55 @@ class AsyncMetadataList : public RGWAsyncRadosRequest { : RGWAsyncRadosRequest(caller, cn), cct(cct), mgr(mgr), section(section), start_marker(start_marker), callback(callback) {} - ~AsyncMetadataList() override { - if (handle) { - mgr->list_keys_complete(handle); - } - } }; int AsyncMetadataList::_send_request() { + void* handle = nullptr; + std::list keys; + bool truncated{false}; + std::string marker; + // start a listing at the given marker int r = mgr->list_keys_init(section, start_marker, &handle); - if (r < 0) { + if (r == -EINVAL) { + // restart with empty marker below + } else if (r < 0) { ldout(cct, 10) << "failed to init metadata listing: " << cpp_strerror(r) << dendl; return r; - } - ldout(cct, 20) << "starting metadata listing at " << start_marker << dendl; - - std::list keys; - bool truncated{false}; - std::string marker; - - do { - // get the next key and marker - r = mgr->list_keys_next(handle, 1, keys, &truncated); - if (r < 0) { - ldout(cct, 10) << "failed to list metadata: " - << cpp_strerror(r) << dendl; - return r; - } - marker = mgr->get_marker(handle); - - if (!keys.empty()) { - ceph_assert(keys.size() == 1); - auto& key = keys.front(); - if (!callback(std::move(key), std::move(marker))) { - return 0; + } else { + ldout(cct, 20) << "starting metadata listing at " << start_marker << dendl; + + // release the handle when scope exits + auto g = make_scope_guard([=] { mgr->list_keys_complete(handle); }); + + do { + // get the next key and marker + r = mgr->list_keys_next(handle, 1, keys, &truncated); + if (r < 0) { + ldout(cct, 10) << "failed to list metadata: " + << cpp_strerror(r) << dendl; + return r; } - } - } while (truncated); + marker = mgr->get_marker(handle); + + if (!keys.empty()) { + ceph_assert(keys.size() == 1); + auto& key = keys.front(); + if (!callback(std::move(key), std::move(marker))) { + return 0; + } + } + } while (truncated); - if (start_marker.empty()) { - // already listed all keys - return 0; + if (start_marker.empty()) { + // already listed all keys + return 0; + } } // restart the listing from the beginning (empty marker) - mgr->list_keys_complete(handle); handle = nullptr; r = mgr->list_keys_init(section, "", &handle); @@ -649,6 +650,8 @@ int AsyncMetadataList::_send_request() } ldout(cct, 20) << "restarting metadata listing" << dendl; + // release the handle when scope exits + auto g = make_scope_guard([=] { mgr->list_keys_complete(handle); }); do { // get the next key and marker r = mgr->list_keys_next(handle, 1, keys, &truncated);