Check that a marker was specified and trim if we don't have one.
Also: In a world where we're parsing for generation, it doesn't really
make sense to have a 'no marker specified' as separate from a marker
that is just an empty string.
Also: Successful datalog trim returns zero, not
-ENODATA, and radosgw-admin should expect this.
Fixes: https://tracker.ceph.com/issues/51712
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
return EINVAL;
}
+ if (marker.empty()) {
+ cerr << "ERROR: marker must be specified for trim operation" << std::endl;
+ return EINVAL;
+ }
+
if (period_id.empty()) {
std::cerr << "missing --period argument" << std::endl;
return EINVAL;
std::vector<rgw_data_change_log_entry> entries;
if (specified_shard_id) {
ret = datalog_svc->list_entries(dpp(), shard_id, max_entries - count,
- entries,
- marker.empty() ?
- std::nullopt :
- std::make_optional(marker),
+ entries, marker,
&marker, &truncated);
} else {
ret = datalog_svc->list_entries(dpp(), max_entries - count, entries,
return EINVAL;
}
- // loop until -ENODATA
- do {
- auto datalog = static_cast<rgw::sal::RadosStore*>(store)->svc()->datalog_rados;
- ret = datalog->trim_entries(dpp(), shard_id, marker);
- } while (ret == 0);
+ if (marker.empty()) {
+ cerr << "ERROR: requires a --marker" << std::endl;
+ return EINVAL;
+ }
+
+ auto datalog = static_cast<rgw::sal::RadosStore*>(store)->svc()->datalog_rados;
+ ret = datalog->trim_entries(dpp(), shard_id, marker);
if (ret < 0 && ret != -ENODATA) {
cerr << "ERROR: trim_entries(): " << cpp_strerror(-ret) << std::endl;
int DataLogBackends::list(const DoutPrefixProvider *dpp, int shard, int max_entries,
std::vector<rgw_data_change_log_entry>& entries,
- std::optional<std::string_view> marker,
- std::string* out_marker, bool* truncated)
+ std::string_view marker,
+ std::string* out_marker,
+ bool* truncated)
{
- const auto [start_id, start_cursor] = cursorgeno(marker);
+ const auto [start_id, start_cursor] = cursorgen(marker);
auto gen_id = start_id;
std::string out_cursor;
while (max_entries > 0) {
int RGWDataChangesLog::list_entries(const DoutPrefixProvider *dpp, int shard, int max_entries,
std::vector<rgw_data_change_log_entry>& entries,
- std::optional<std::string_view> marker,
+ std::string_view marker,
std::string* out_marker, bool* truncated)
{
assert(shard < num_shards);
bool truncated;
entries.clear();
for (; marker.shard < num_shards && int(entries.size()) < max_entries;
- marker.shard++, marker.marker.reset()) {
+ marker.shard++, marker.marker.clear()) {
int ret = list_entries(dpp, marker.shard, max_entries - entries.size(),
entries, marker.marker, NULL, &truncated);
if (ret == -ENOENT) {
struct RGWDataChangesLogMarker {
int shard = 0;
- std::optional<std::string> marker;
+ std::string marker;
RGWDataChangesLogMarker() = default;
};
}
int list(const DoutPrefixProvider *dpp, int shard, int max_entries,
std::vector<rgw_data_change_log_entry>& entries,
- std::optional<std::string_view> marker,
+ std::string_view marker,
std::string* out_marker, bool* truncated);
int trim_entries(const DoutPrefixProvider *dpp, int shard_id, std::string_view marker);
void trim_entries(const DoutPrefixProvider *dpp, int shard_id, std::string_view marker,
int get_log_shard_id(rgw_bucket& bucket, int shard_id);
int list_entries(const DoutPrefixProvider *dpp, int shard, int max_entries,
std::vector<rgw_data_change_log_entry>& entries,
- std::optional<std::string_view> marker,
+ std::string_view marker,
std::string* out_marker, bool* truncated);
int trim_entries(const DoutPrefixProvider *dpp, int shard_id, std::string_view marker);
int trim_entries(const DoutPrefixProvider *dpp, int shard_id, std::string_view marker,
inline std::pair<uint64_t, std::string_view>
cursorgen(std::string_view cursor_) {
+ if (cursor_.empty()) {
+ return { 0, ""sv };
+ }
std::string_view cursor = cursor_;
if (cursor[0] != 'G') {
return { 0, cursor };
return { *gen_id, cursor };
}
-inline std::pair<uint64_t, std::string_view>
-cursorgeno(std::optional<std::string_view> cursor) {
- if (cursor && !cursor->empty()) {
- return cursorgen(*cursor);
- } else {
- return { 0, ""s };
- }
-}
-
class LazyFIFO {
librados::IoCtx& ioctx;
std::string oid;