From: Shinobu Kinjo Date: Wed, 15 Mar 2017 18:56:22 +0000 (+0900) Subject: Clean up: cls/timeindex/cls_timeindex_client.h|cc X-Git-Tag: v12.0.2~274^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b712c40ff0f3ccb896fbb0f8a6c7e0bedd005a28;p=ceph.git Clean up: cls/timeindex/cls_timeindex_client.h|cc Signed-off-by: Shinobu Kinjo --- diff --git a/src/cls/timeindex/cls_timeindex_client.cc b/src/cls/timeindex/cls_timeindex_client.cc index 778cf12e0665..3aa7adf02ffd 100644 --- a/src/cls/timeindex/cls_timeindex_client.cc +++ b/src/cls/timeindex/cls_timeindex_client.cc @@ -5,153 +5,118 @@ #include "include/types.h" #include "cls/timeindex/cls_timeindex_ops.h" +#include "cls/timeindex/cls_timeindex_client.h" #include "include/rados/librados.hpp" #include "include/compat.h" - -using namespace librados; - - -void cls_timeindex_add(librados::ObjectWriteOperation& op, list& entries) +void cls_timeindex_add( + librados::ObjectWriteOperation& op, + std::list& entries) { - bufferlist in; + librados::bufferlist in; cls_timeindex_add_op call; - call.entries = entries; ::encode(call, in); op.exec("timeindex", "add", in); } -void cls_timeindex_add(librados::ObjectWriteOperation& op, cls_timeindex_entry& entry) +void cls_timeindex_add( + librados::ObjectWriteOperation& op, + cls_timeindex_entry& entry) { - bufferlist in; + librados::bufferlist in; cls_timeindex_add_op call; - call.entries.push_back(entry); ::encode(call, in); op.exec("timeindex", "add", in); } -void cls_timeindex_add_prepare_entry(cls_timeindex_entry& entry, - const utime_t& key_timestamp, - const string& key_ext, - const bufferlist& bl) +void cls_timeindex_add_prepare_entry( + cls_timeindex_entry& entry, + const utime_t& key_timestamp, + const std::string& key_ext, + const librados::bufferlist& bl) { - entry.key_ts = key_timestamp; + entry.key_ts = key_timestamp; entry.key_ext = key_ext; - entry.value = bl; + entry.value = bl; } -void cls_timeindex_add(librados::ObjectWriteOperation& op, - const utime_t& key_timestamp, - const string& key_ext, - const bufferlist& bl) +void cls_timeindex_add( + librados::ObjectWriteOperation& op, + const utime_t& key_timestamp, + const std::string& key_ext, + const librados::bufferlist& bl) { cls_timeindex_entry entry; - cls_timeindex_add_prepare_entry(entry, key_timestamp, key_ext, bl); cls_timeindex_add(op, entry); } -void cls_timeindex_trim(librados::ObjectWriteOperation& op, - const utime_t& from_time, - const utime_t& to_time, - const string& from_marker, - const string& to_marker) +void cls_timeindex_trim( + librados::ObjectWriteOperation& op, + const utime_t& from_time, + const utime_t& to_time, + const std::string& from_marker, + const std::string& to_marker) { - bufferlist in; + librados::bufferlist in; cls_timeindex_trim_op call; - - call.from_time = from_time; - call.to_time = to_time; + call.from_time = from_time; + call.to_time = to_time; call.from_marker = from_marker; - call.to_marker = to_marker; + call.to_marker = to_marker; ::encode(call, in); op.exec("timeindex", "trim", in); } -int cls_timeindex_trim(librados::IoCtx& io_ctx, - const string& oid, - const utime_t& from_time, - const utime_t& to_time, - const string& from_marker, - const string& to_marker) +int cls_timeindex_trim( + librados::IoCtx& io_ctx, + const std::string& oid, + const utime_t& from_time, + const utime_t& to_time, + const std::string& from_marker, + const std::string& to_marker) { bool done = false; do { - ObjectWriteOperation op; - + librados::ObjectWriteOperation op; cls_timeindex_trim(op, from_time, to_time, from_marker, to_marker); - int r = io_ctx.operate(oid, &op); - if (r == -ENODATA) { + + if (r == -ENODATA) done = true; - } else if (r < 0) { + else if (r < 0) return r; - } - } while (!done); return 0; } -class TimeindexListCtx : public ObjectOperationCompletion { - list *entries; - string *marker; - bool *truncated; - -public: - TimeindexListCtx(list *_entries, - string *_marker, - bool *_truncated) - : entries(_entries), marker(_marker), truncated(_truncated) {} - - void handle_completion(int r, bufferlist& outbl) override { - if (r >= 0) { - cls_timeindex_list_ret ret; - try { - bufferlist::iterator iter = outbl.begin(); - ::decode(ret, iter); - if (entries) { - *entries = ret.entries; - } - if (truncated) { - *truncated = ret.truncated; - } - if (marker) { - *marker = ret.marker; - } - } catch (buffer::error& err) { - // nothing we can do about it atm - } - } - } -}; - -void cls_timeindex_list(librados::ObjectReadOperation& op, - const utime_t& from, - const utime_t& to, - const string& in_marker, - const int max_entries, - list& entries, - string *out_marker, - bool *truncated) +void cls_timeindex_list( + librados::ObjectReadOperation& op, + const utime_t& from, + const utime_t& to, + const std::string& in_marker, + const int max_entries, + std::list& entries, + std::string *out_marker, + bool *truncated) { - bufferlist inbl; + librados::bufferlist in; cls_timeindex_list_op call; - call.from_time = from; call.to_time = to; call.marker = in_marker; call.max_entries = max_entries; - ::encode(call, inbl); + ::encode(call, in); - op.exec("timeindex", "list", inbl, + op.exec("timeindex", "list", in, new TimeindexListCtx(&entries, out_marker, truncated)); } diff --git a/src/cls/timeindex/cls_timeindex_client.h b/src/cls/timeindex/cls_timeindex_client.h index 09a420f4937a..71d71fea22ab 100644 --- a/src/cls/timeindex/cls_timeindex_client.h +++ b/src/cls/timeindex/cls_timeindex_client.h @@ -5,48 +5,90 @@ #define CEPH_CLS_TIMEINDEX_CLIENT_H #include "include/types.h" +#include "cls/timeindex/cls_timeindex_ops.h" #include "include/rados/librados.hpp" #include "cls_timeindex_types.h" -/* +/** * timeindex objclass */ +class TimeindexListCtx : public librados::ObjectOperationCompletion { + std::list *entries; + std::string *marker; + bool *truncated; -void cls_timeindex_add_prepare_entry(cls_timeindex_entry& entry, - const utime_t& key_timestamp, - const string& key_ext, - bufferlist& bl); - -void cls_timeindex_add(librados::ObjectWriteOperation& op, - const list& entry); - -void cls_timeindex_add(librados::ObjectWriteOperation& op, - const cls_timeindex_entry& entry); - -void cls_timeindex_add(librados::ObjectWriteOperation& op, - const utime_t& timestamp, - const string& name, - const bufferlist& bl); - -void cls_timeindex_list(librados::ObjectReadOperation& op, - const utime_t& from, - const utime_t& to, - const string& in_marker, - const int max_entries, - list& entries, - string *out_marker, - bool *truncated); - -void cls_timeindex_trim(librados::ObjectWriteOperation& op, - const utime_t& from_time, - const utime_t& to_time, - const string& from_marker = std::string(), - const string& to_marker = std::string()); - -int cls_timeindex_trim(librados::IoCtx& io_ctx, - const string& oid, - const utime_t& from_time, - const utime_t& to_time, - const string& from_marker = std::string(), - const string& to_marker = std::string()); +public: + ///* ctor + TimeindexListCtx( + std::list *_entries, + std::string *_marker, + bool *_truncated) + : entries(_entries), marker(_marker), truncated(_truncated) {} + + ///* dtor + ~TimeindexListCtx() {} + + void handle_completion(int r, bufferlist& bl) override { + if (r >= 0) { + cls_timeindex_list_ret ret; + try { + bufferlist::iterator iter = bl.begin(); + ::decode(ret, iter); + if (entries) + *entries = ret.entries; + if (truncated) + *truncated = ret.truncated; + if (marker) + *marker = ret.marker; + } catch (buffer::error& err) { + // nothing we can do about it atm + } + } + } +}; + +void cls_timeindex_add_prepare_entry( + cls_timeindex_entry& entry, + const utime_t& key_timestamp, + const std::string& key_ext, + bufferlist& bl); + +void cls_timeindex_add( + librados::ObjectWriteOperation& op, + const std::list& entry); + +void cls_timeindex_add( + librados::ObjectWriteOperation& op, + const cls_timeindex_entry& entry); + +void cls_timeindex_add( + librados::ObjectWriteOperation& op, + const utime_t& timestamp, + const std::string& name, + const bufferlist& bl); + +void cls_timeindex_list( + librados::ObjectReadOperation& op, + const utime_t& from, + const utime_t& to, + const std::string& in_marker, + const int max_entries, + std::list& entries, + std::string *out_marker, + bool *truncated); + +void cls_timeindex_trim( + librados::ObjectWriteOperation& op, + const utime_t& from_time, + const utime_t& to_time, + const std::string& from_marker = std::string(), + const std::string& to_marker = std::string()); + +int cls_timeindex_trim( + librados::IoCtx& io_ctx, + const std::string& oid, + const utime_t& from_time, + const utime_t& to_time, + const std::string& from_marker = std::string(), + const std::string& to_marker = std::string()); #endif