return 0;
}
-static int bi_log_list_trim_cb(cls_method_context_t hctx, const string& key, rgw_bi_log_entry& info, void *param)
-{
- list<rgw_bi_log_entry> *entries = (list<rgw_bi_log_entry> *)param;
-
- entries->push_back(info);
- return 0;
-}
-
-static int bi_log_remove_entry(cls_method_context_t hctx, rgw_bi_log_entry& entry)
-{
- string key;
- key = BI_PREFIX_CHAR;
- key.append(bucket_index_prefixes[BI_BUCKET_LOG_INDEX]);
- key.append(entry.id);
- return cls_cxx_map_remove_key(hctx, key);
-}
-
-static int bi_log_list_trim_entries(cls_method_context_t hctx,
- const string& start_marker, const string& end_marker,
- list<rgw_bi_log_entry>& entries, bool *truncated)
-{
- string key_iter;
-#define MAX_TRIM_ENTRIES 1000 /* max entries to trim in a single operation */
- int ret = bi_log_iterate_entries(hctx, start_marker, end_marker,
- key_iter, MAX_TRIM_ENTRIES, truncated,
- bi_log_list_trim_cb, &entries);
- return ret;
-}
-
static int rgw_bi_log_trim(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
{
auto in_iter = in->cbegin();
return -EINVAL;
}
- cls_rgw_bi_log_list_ret op_ret;
- list<rgw_bi_log_entry> entries;
-#define MAX_TRIM_ENTRIES 1000 /* don't do more than that in a single operation */
- bool truncated;
- int ret = bi_log_list_trim_entries(hctx, op.start_marker, op.end_marker, entries, &truncated);
- if (ret < 0)
- return ret;
+ string key_begin(1, BI_PREFIX_CHAR);
+ key_begin.append(bucket_index_prefixes[BI_BUCKET_LOG_INDEX]);
+ key_begin.append(op.start_marker);
- if (entries.empty())
- return -ENODATA;
+ string key_end;
+ if (op.end_marker.empty()) {
+ key_end = BI_PREFIX_CHAR;
+ key_end.append(bucket_index_prefixes[BI_BUCKET_LOG_INDEX + 1]);
+ } else {
+ key_end = BI_PREFIX_CHAR;
+ key_end.append(bucket_index_prefixes[BI_BUCKET_LOG_INDEX]);
+ key_end.append(op.end_marker);
+ // cls_cxx_map_remove_range() expects one-past-end
+ key_end.append(1, '\0');
+ }
- list<rgw_bi_log_entry>::iterator iter;
- for (iter = entries.begin(); iter != entries.end(); ++iter) {
- rgw_bi_log_entry& entry = *iter;
+ // list a single key to detect whether the range is empty
+ const size_t max_entries = 1;
+ std::set<std::string> keys;
+ bool more = false;
- ret = bi_log_remove_entry(hctx, entry);
- if (ret < 0)
- return ret;
+ int rc = cls_cxx_map_get_keys(hctx, key_begin, max_entries, &keys, &more);
+ if (rc < 0) {
+ CLS_LOG(1, "ERROR: cls_cxx_map_get_keys failed rc=%d", rc);
+ return rc;
+ }
+
+ if (keys.empty()) {
+ CLS_LOG(20, "range is empty key_begin=%s", key_begin.c_str());
+ return -ENODATA;
+ }
+
+ const std::string& first_key = *keys.begin();
+ if (key_end < first_key) {
+ CLS_LOG(20, "listed key %s past key_end=%s", first_key.c_str(), key_end.c_str());
+ return -ENODATA;
}
+ CLS_LOG(20, "listed key %s, removing through %s",
+ first_key.c_str(), key_end.c_str());
+
+ rc = cls_cxx_map_remove_range(hctx, first_key, key_end);
+ if (rc < 0) {
+ CLS_LOG(1, "ERROR: cls_cxx_map_remove_range failed rc=%d", rc);
+ return rc;
+ }
return 0;
}