diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-03-12 14:31:27 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-03-12 14:31:27 -0700 |
commit | abc497539436139b2f96ab5943ffd08085d118a1 (patch) | |
tree | eb79eb199975914c2b4b210fde3003998e5a3b50 | |
parent | dbe5feb2335f2cf4e14897dfc04b983960894986 (diff) | |
download | ceph-abc497539436139b2f96ab5943ffd08085d118a1.tar.gz |
cls_log: trim works in chunks, returns -ENODATA when done
Also created a higher level interface that iterates until
done.
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/cls/log/cls_log.cc | 7 | ||||
-rw-r--r-- | src/cls/log/cls_log_client.cc | 21 | ||||
-rw-r--r-- | src/cls/log/cls_log_client.h | 1 |
3 files changed, 28 insertions, 1 deletions
diff --git a/src/cls/log/cls_log.cc b/src/cls/log/cls_log.cc index fad61eb3442..c0bb97be940 100644 --- a/src/cls/log/cls_log.cc +++ b/src/cls/log/cls_log.cc @@ -153,13 +153,14 @@ static int cls_log_trim(cls_method_context_t hctx, bufferlist *in, bufferlist *o #define MAX_TRIM_ENTRIES 1000 size_t max_entries = MAX_TRIM_ENTRIES; - int rc = cls_cxx_map_get_vals(hctx, index, log_index_prefix, max_entries, &keys); + int rc = cls_cxx_map_get_vals(hctx, from_index, log_index_prefix, max_entries, &keys); if (rc < 0) return rc; map<string, bufferlist>::iterator iter = keys.begin(); size_t i; + bool removed = false; for (i = 0; i < max_entries && iter != keys.end(); ++i, ++iter) { const string& index = iter->first; @@ -171,8 +172,12 @@ static int cls_log_trim(cls_method_context_t hctx, bufferlist *in, bufferlist *o CLS_LOG(1, "ERROR: cls_log_trim_op(): failed to decode entry\n"); return -EINVAL; } + removed = true; } + if (!removed) + return -ENODATA; + return 0; } diff --git a/src/cls/log/cls_log_client.cc b/src/cls/log/cls_log_client.cc index 0f1854f58bf..e765f368572 100644 --- a/src/cls/log/cls_log_client.cc +++ b/src/cls/log/cls_log_client.cc @@ -29,6 +29,27 @@ void cls_log_trim(librados::ObjectWriteOperation& op, utime_t& from, utime_t& to op.exec("log", "trim", in); } +int cls_log_trim(librados::IoCtx& io_ctx, string& oid, utime_t& from, utime_t& to) +{ + bool done = false; + + do { + ObjectWriteOperation op; + + cls_log_trim(op, from, to); + + int r = io_ctx.operate(oid, &op); + if (r == -ENODATA) + done = true; + else if (r < 0) + return r; + + } while (!done); + + + return 0; +} + class LogListCtx : public ObjectOperationCompletion { list<cls_log_entry> *entries; bool *truncated; diff --git a/src/cls/log/cls_log_client.h b/src/cls/log/cls_log_client.h index b2543c09c13..ba062c7566d 100644 --- a/src/cls/log/cls_log_client.h +++ b/src/cls/log/cls_log_client.h @@ -13,5 +13,6 @@ void cls_log_add(librados::ObjectWriteOperation& op, cls_log_entry& entry); void cls_log_list(librados::ObjectReadOperation& op, utime_t& from, int max, list<cls_log_entry>& entries); void cls_log_trim(librados::ObjectWriteOperation& op, utime_t& from, utime_t& to); +int cls_log_trim(librados::IoCtx& io_ctx, string& oid, utime_t& from, utime_t& to); #endif |