if (!by_user && key.compare(end_key) >= 0) {
CLS_LOG(20, "usage_iterate_range reached key=%s, done", key.c_str());
- if (truncated_status) {
- key_iter = key;
- }
+ key_iter = key;
return 0;
}
if (by_user && key.compare(0, user_key.size(), user_key) != 0) {
CLS_LOG(20, "usage_iterate_range reached key=%s, done", key.c_str());
- if (truncated_status) {
- key_iter = key;
- }
+ key_iter = key;
return 0;
}
if (ret < 0)
return ret;
+ if (!more && iter.empty())
+ return -ENODATA;
+
return 0;
}
return 0;
}
-void cls_rgw_usage_log_trim(ObjectWriteOperation& op, string& user,
- uint64_t start_epoch, uint64_t end_epoch)
+int cls_rgw_usage_log_trim(IoCtx& io_ctx, const string& oid, string& user,
+ uint64_t start_epoch, uint64_t end_epoch)
{
bufferlist in;
rgw_cls_usage_log_trim_op call;
call.end_epoch = end_epoch;
call.user = user;
::encode(call, in);
- op.exec(RGW_CLASS, RGW_USER_USAGE_LOG_TRIM, in);
+
+ bool done = false;
+ do {
+ ObjectWriteOperation op;
+ op.exec(RGW_CLASS, RGW_USER_USAGE_LOG_TRIM, in);
+ int r = io_ctx.operate(oid, &op);
+ if (r == -ENODATA)
+ done = true;
+ else if (r < 0)
+ return r;
+ } while (!done);
+
+ return 0;
}
+
+
void cls_rgw_usage_log_add(ObjectWriteOperation& op, rgw_usage_log_info& info)
{
bufferlist in;
string& read_iter, map<rgw_user_bucket, rgw_usage_log_entry>& usage,
bool *is_truncated);
-void cls_rgw_usage_log_trim(librados::ObjectWriteOperation& op, string& user,
+int cls_rgw_usage_log_trim(librados::IoCtx& io_ctx, const string& oid, string& user,
uint64_t start_epoch, uint64_t end_epoch);
void cls_rgw_usage_log_add(librados::ObjectWriteOperation& op, rgw_usage_log_info& info);
usage_log_hash(cct, user_str, first_hash, index);
hash = first_hash;
-
do {
int ret = cls_obj_usage_log_trim(hash, user_str, start_epoch, end_epoch);
- if (ret == -ENOENT)
- goto next;
- if (ret < 0)
+ if (ret < 0 && ret != -ENOENT)
return ret;
-next:
usage_log_hash(cct, user_str, hash, ++index);
} while (hash != first_hash);
return r;
}
- ObjectWriteOperation op;
- cls_rgw_usage_log_trim(op, user, start_epoch, end_epoch);
-
- r = ref.ioctx.operate(ref.oid, &op);
+ r = cls_rgw_usage_log_trim(ref.ioctx, ref.oid, user, start_epoch, end_epoch);
return r;
}