From dd5e9cde276c9db598f3fe6f6d0c990ff98053dc Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 12 Sep 2018 09:42:40 -0400 Subject: [PATCH] cls: remove cls_statelog and tests Signed-off-by: Casey Bodley --- src/cls/CMakeLists.txt | 14 - src/cls/statelog/cls_statelog.cc | 297 --------------------- src/cls/statelog/cls_statelog_client.cc | 125 --------- src/cls/statelog/cls_statelog_client.h | 33 --- src/cls/statelog/cls_statelog_ops.h | 143 ---------- src/cls/statelog/cls_statelog_types.h | 49 ---- src/test/CMakeLists.txt | 1 - src/test/cls_statelog/CMakeLists.txt | 16 -- src/test/cls_statelog/test_cls_statelog.cc | 211 --------------- 9 files changed, 889 deletions(-) delete mode 100644 src/cls/statelog/cls_statelog.cc delete mode 100644 src/cls/statelog/cls_statelog_client.cc delete mode 100644 src/cls/statelog/cls_statelog_client.h delete mode 100644 src/cls/statelog/cls_statelog_ops.h delete mode 100644 src/cls/statelog/cls_statelog_types.h delete mode 100644 src/test/cls_statelog/CMakeLists.txt delete mode 100644 src/test/cls_statelog/test_cls_statelog.cc diff --git a/src/cls/CMakeLists.txt b/src/cls/CMakeLists.txt index fa0c05d9acfb3..d62273d4c4a24 100644 --- a/src/cls/CMakeLists.txt +++ b/src/cls/CMakeLists.txt @@ -138,20 +138,6 @@ set(cls_log_client_srcs log/cls_log_client.cc) add_library(cls_log_client STATIC ${cls_log_client_srcs}) -# cls_statelog -set(cls_statelog_srcs statelog/cls_statelog.cc) -add_library(cls_statelog SHARED ${cls_statelog_srcs}) -set_target_properties(cls_statelog PROPERTIES - VERSION "1.0.0" - SOVERSION "1" - INSTALL_RPATH "" - CXX_VISIBILITY_PRESET hidden) -install(TARGETS cls_statelog DESTINATION ${cls_dir}) - -set(cls_statelog_client_srcs statelog/cls_statelog_client.cc) -add_library(cls_statelog_client STATIC ${cls_statelog_client_srcs}) - - # cls_timeindex set(cls_timeindex_srcs timeindex/cls_timeindex.cc) add_library(cls_timeindex SHARED ${cls_timeindex_srcs}) diff --git a/src/cls/statelog/cls_statelog.cc b/src/cls/statelog/cls_statelog.cc deleted file mode 100644 index 199d22e0e7c27..0000000000000 --- a/src/cls/statelog/cls_statelog.cc +++ /dev/null @@ -1,297 +0,0 @@ -// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab - -#include - -#include "objclass/objclass.h" - -#include "cls_statelog_ops.h" - - -CLS_VER(1,0) -CLS_NAME(statelog) - -static string statelog_index_by_client_prefix = "1_"; -static string statelog_index_by_object_prefix = "2_"; - - -static int write_statelog_entry(cls_method_context_t hctx, const string& index, const cls_statelog_entry& entry) -{ - bufferlist bl; - encode(entry, bl); - - int ret = cls_cxx_map_set_val(hctx, index, &bl); - if (ret < 0) - return ret; - - return 0; -} - -static void get_index_by_client(const string& client_id, const string& op_id, string& index) -{ - index = statelog_index_by_client_prefix; - index.append(client_id + "_" + op_id); -} - -static void get_index_by_client(cls_statelog_entry& entry, string& index) -{ - get_index_by_client(entry.client_id, entry.op_id, index); -} - -static void get_index_by_object(const string& object, const string& op_id, string& index) -{ - char buf[16]; - snprintf(buf, sizeof(buf), "%d_", (int)object.size()); - - index = statelog_index_by_object_prefix + buf; /* append object length to ensure uniqueness */ - index.append(object + "_" + op_id); -} - -static void get_index_by_object(cls_statelog_entry& entry, string& index) -{ - get_index_by_object(entry.object, entry.op_id, index); -} - -static int get_existing_entry(cls_method_context_t hctx, const string& client_id, - const string& op_id, const string& object, - cls_statelog_entry& entry) -{ - if ((object.empty() && client_id.empty()) || op_id.empty()) { - return -EINVAL; - } - - string obj_index; - if (!object.empty()) { - get_index_by_object(object, op_id, obj_index); - } else { - get_index_by_client(client_id, op_id, obj_index); - } - - bufferlist bl; - int rc = cls_cxx_map_get_val(hctx, obj_index, &bl); - if (rc < 0) { - CLS_LOG(0, "could not find entry %s", obj_index.c_str()); - return rc; - } - try { - auto iter = bl.cbegin(); - decode(entry, iter); - } catch (buffer::error& err) { - CLS_LOG(0, "ERROR: failed to decode entry %s", obj_index.c_str()); - return -EIO; - } - - if ((!object.empty() && entry.object != object) || - (!client_id.empty() && entry.client_id != client_id)){ - /* ouch, we were passed inconsistent client_id / object */ - CLS_LOG(0, "data mismatch: object=%s client_id=%s entry: object=%s client_id=%s", - object.c_str(), client_id.c_str(), entry.object.c_str(), entry.client_id.c_str()); - return -EINVAL; - } - - return 0; -} - -static int cls_statelog_add(cls_method_context_t hctx, bufferlist *in, bufferlist *out) -{ - auto in_iter = in->cbegin(); - - cls_statelog_add_op op; - try { - decode(op, in_iter); - } catch (buffer::error& err) { - CLS_LOG(1, "ERROR: cls_statelog_add_op(): failed to decode op"); - return -EINVAL; - } - - for (list::iterator iter = op.entries.begin(); - iter != op.entries.end(); ++iter) { - cls_statelog_entry& entry = *iter; - - string index_by_client; - - get_index_by_client(entry, index_by_client); - - CLS_LOG(0, "storing entry by client/op at %s", index_by_client.c_str()); - - int ret = write_statelog_entry(hctx, index_by_client, entry); - if (ret < 0) - return ret; - - string index_by_obj; - - get_index_by_object(entry, index_by_obj); - - CLS_LOG(0, "storing entry by object at %s", index_by_obj.c_str()); - ret = write_statelog_entry(hctx, index_by_obj, entry); - if (ret < 0) - return ret; - - } - - return 0; -} - -static int cls_statelog_list(cls_method_context_t hctx, bufferlist *in, bufferlist *out) -{ - auto in_iter = in->cbegin(); - - cls_statelog_list_op op; - try { - decode(op, in_iter); - } catch (buffer::error& err) { - CLS_LOG(1, "ERROR: cls_statelog_list_op(): failed to decode op"); - return -EINVAL; - } - - map keys; - - string from_index; - string match_prefix; - - if (!op.client_id.empty()) { - get_index_by_client(op.client_id, op.op_id, match_prefix); - } else if (!op.object.empty()) { - get_index_by_object(op.object, op.op_id, match_prefix); - } else { - match_prefix = statelog_index_by_object_prefix; - } - - if (op.marker.empty()) { - from_index = match_prefix; - } else { - from_index = op.marker; - } - -#define MAX_ENTRIES 1000 - size_t max_entries = op.max_entries; - if (!max_entries || max_entries > MAX_ENTRIES) - max_entries = MAX_ENTRIES; - - cls_statelog_list_ret ret; - - int rc = cls_cxx_map_get_vals(hctx, from_index, match_prefix, max_entries, &keys, &ret.truncated); - if (rc < 0) - return rc; - - CLS_LOG(20, "from_index=%s match_prefix=%s", from_index.c_str(), match_prefix.c_str()); - - list& entries = ret.entries; - map::iterator iter = keys.begin(); - - string marker; - - for (; iter != keys.end(); ++iter) { - const string& index = iter->first; - marker = index; - - bufferlist& bl = iter->second; - auto biter = bl.cbegin(); - try { - cls_statelog_entry e; - decode(e, biter); - entries.push_back(e); - } catch (buffer::error& err) { - CLS_LOG(0, "ERROR: cls_statelog_list: could not decode entry, index=%s", index.c_str()); - } - } - - if (ret.truncated) { - ret.marker = marker; - } - - encode(ret, *out); - - return 0; -} - -static int cls_statelog_remove(cls_method_context_t hctx, bufferlist *in, bufferlist *out) -{ - auto in_iter = in->cbegin(); - - cls_statelog_remove_op op; - try { - decode(op, in_iter); - } catch (buffer::error& err) { - CLS_LOG(1, "ERROR: cls_statelog_remove_op(): failed to decode op"); - return -EINVAL; - } - - cls_statelog_entry entry; - - int rc = get_existing_entry(hctx, op.client_id, op.op_id, op.object, entry); - if (rc < 0) - return rc; - - string obj_index; - get_index_by_object(entry.object, entry.op_id, obj_index); - - rc = cls_cxx_map_remove_key(hctx, obj_index); - if (rc < 0) { - CLS_LOG(0, "ERROR: failed to remove key"); - return rc; - } - - string client_index; - get_index_by_client(entry.client_id, entry.op_id, client_index); - - rc = cls_cxx_map_remove_key(hctx, client_index); - if (rc < 0) { - CLS_LOG(0, "ERROR: failed to remove key"); - return rc; - } - - return 0; -} - -static int cls_statelog_check_state(cls_method_context_t hctx, bufferlist *in, bufferlist *out) -{ - auto in_iter = in->cbegin(); - - cls_statelog_check_state_op op; - try { - decode(op, in_iter); - } catch (buffer::error& err) { - CLS_LOG(1, "ERROR: cls_statelog_check_state_op(): failed to decode op"); - return -EINVAL; - } - - if (op.object.empty() || op.op_id.empty()) { - CLS_LOG(0, "object name or op id not specified"); - return -EINVAL; - } - - - cls_statelog_entry entry; - - int rc = get_existing_entry(hctx, op.client_id, op.op_id, op.object, entry); - if (rc < 0) - return rc; - - if (entry.state != op.state) - return -ECANCELED; - - return 0; -} - -CLS_INIT(statelog) -{ - CLS_LOG(1, "Loaded log class!"); - - cls_handle_t h_class; - cls_method_handle_t h_statelog_add; - cls_method_handle_t h_statelog_list; - cls_method_handle_t h_statelog_remove; - cls_method_handle_t h_statelog_check_state; - - cls_register("statelog", &h_class); - - /* log */ - cls_register_cxx_method(h_class, "add", CLS_METHOD_RD | CLS_METHOD_WR, cls_statelog_add, &h_statelog_add); - cls_register_cxx_method(h_class, "list", CLS_METHOD_RD, cls_statelog_list, &h_statelog_list); - cls_register_cxx_method(h_class, "remove", CLS_METHOD_RD | CLS_METHOD_WR, cls_statelog_remove, &h_statelog_remove); - cls_register_cxx_method(h_class, "check_state", CLS_METHOD_RD, cls_statelog_check_state, &h_statelog_check_state); - - return; -} - diff --git a/src/cls/statelog/cls_statelog_client.cc b/src/cls/statelog/cls_statelog_client.cc deleted file mode 100644 index c867f26c99b57..0000000000000 --- a/src/cls/statelog/cls_statelog_client.cc +++ /dev/null @@ -1,125 +0,0 @@ -#include - -#include "cls/statelog/cls_statelog_client.h" -#include "include/rados/librados.hpp" - - -using namespace librados; - - -void cls_statelog_add(librados::ObjectWriteOperation& op, list& entries) -{ - bufferlist in; - cls_statelog_add_op call; - call.entries = entries; - encode(call, in); - op.exec("statelog", "add", in); -} - -void cls_statelog_add(librados::ObjectWriteOperation& op, cls_statelog_entry& entry) -{ - bufferlist in; - cls_statelog_add_op call; - call.entries.push_back(entry); - encode(call, in); - op.exec("statelog", "add", in); -} - -void cls_statelog_add_prepare_entry(cls_statelog_entry& entry, const string& client_id, const string& op_id, - const string& object, const utime_t& timestamp, uint32_t state, bufferlist& bl) -{ - entry.client_id = client_id; - entry.op_id = op_id; - entry.object = object; - entry.timestamp = timestamp; - entry.state = state; - entry.data = bl; -} - -void cls_statelog_add(librados::ObjectWriteOperation& op, const string& client_id, const string& op_id, - const string& object, const utime_t& timestamp, uint32_t state, bufferlist& bl) - -{ - cls_statelog_entry entry; - - cls_statelog_add_prepare_entry(entry, client_id, op_id, object, timestamp, state, bl); - cls_statelog_add(op, entry); -} - -void cls_statelog_remove_by_client(librados::ObjectWriteOperation& op, const string& client_id, const string& op_id) -{ - bufferlist in; - cls_statelog_remove_op call; - call.client_id = client_id; - call.op_id = op_id; - encode(call, in); - op.exec("statelog", "remove", in); -} - -void cls_statelog_remove_by_object(librados::ObjectWriteOperation& op, const string& object, const string& op_id) -{ - bufferlist in; - cls_statelog_remove_op call; - call.object = object; - call.op_id = op_id; - encode(call, in); - op.exec("statelog", "remove", in); -} - -class StateLogListCtx : public ObjectOperationCompletion { - list *entries; - string *marker; - bool *truncated; -public: - StateLogListCtx(list *_entries, string *_marker, bool *_truncated) : - entries(_entries), marker(_marker), truncated(_truncated) {} - void handle_completion(int r, bufferlist& outbl) override { - if (r >= 0) { - cls_statelog_list_ret ret; - try { - auto iter = outbl.cbegin(); - 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_statelog_list(librados::ObjectReadOperation& op, - const string& client_id, const string& op_id, const string& object, /* op_id may be empty, also one of client_id, object*/ - const string& in_marker, int max_entries, list& entries, - string *out_marker, bool *truncated) -{ - bufferlist inbl; - cls_statelog_list_op call; - call.client_id = client_id; - call.op_id = op_id; - call.object = object; - call.marker = in_marker; - call.max_entries = max_entries; - - encode(call, inbl); - - op.exec("statelog", "list", inbl, new StateLogListCtx(&entries, out_marker, truncated)); -} - -void cls_statelog_check_state(librados::ObjectOperation& op, const string& client_id, const string& op_id, const string& object, uint32_t state) -{ - bufferlist inbl; - cls_statelog_check_state_op call; - call.client_id = client_id; - call.op_id = op_id; - call.object = object; - call.state = state; - - encode(call, inbl); - - op.exec("statelog", "check_state", inbl, NULL); -} diff --git a/src/cls/statelog/cls_statelog_client.h b/src/cls/statelog/cls_statelog_client.h deleted file mode 100644 index 514c307be70c1..0000000000000 --- a/src/cls/statelog/cls_statelog_client.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef CEPH_CLS_STATELOG_CLIENT_H -#define CEPH_CLS_STATELOG_CLIENT_H - -#include "cls_statelog_ops.h" - -namespace librados { - class ObjectWriteOperation; - class ObjectReadOperation; - class ObjectOperation; -} - -/* - * log objclass - */ - -void cls_statelog_add_prepare_entry(cls_statelog_entry& entry, const string& client_id, const string& op_id, - const string& object, const utime_t& timestamp, uint32_t state, bufferlist& bl); - -void cls_statelog_add(librados::ObjectWriteOperation& op, list& entry); -void cls_statelog_add(librados::ObjectWriteOperation& op, cls_statelog_entry& entry); -void cls_statelog_add(librados::ObjectWriteOperation& op, const string& client_id, const string& op_id, - const string& object, const utime_t& timestamp, uint32_t state, bufferlist& bl); - -void cls_statelog_list(librados::ObjectReadOperation& op, - const string& client_id, const string& op_id, const string& object, /* op_id may be empty, also one of client_id, object*/ - const string& in_marker, int max_entries, list& entries, - string *out_marker, bool *truncated); - -void cls_statelog_remove_by_client(librados::ObjectWriteOperation& op, const string& client_id, const string& op_id); -void cls_statelog_remove_by_object(librados::ObjectWriteOperation& op, const string& object, const string& op_id); - -void cls_statelog_check_state(librados::ObjectOperation& op, const string& client_id, const string& op_id, const string& object, uint32_t state); -#endif diff --git a/src/cls/statelog/cls_statelog_ops.h b/src/cls/statelog/cls_statelog_ops.h deleted file mode 100644 index 404ae463b50ff..0000000000000 --- a/src/cls/statelog/cls_statelog_ops.h +++ /dev/null @@ -1,143 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab - -#ifndef CEPH_CLS_STATELOG_OPS_H -#define CEPH_CLS_STATELOG_OPS_H - -#include "cls_statelog_types.h" - -struct cls_statelog_add_op { - list entries; - - cls_statelog_add_op() {} - - void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - encode(entries, bl); - ENCODE_FINISH(bl); - } - - void decode(bufferlist::const_iterator& bl) { - DECODE_START(1, bl); - decode(entries, bl); - DECODE_FINISH(bl); - } -}; -WRITE_CLASS_ENCODER(cls_statelog_add_op) - -struct cls_statelog_list_op { - string object; - string client_id; - string op_id; - string marker; /* if not empty, overrides from_time */ - int max_entries; /* upperbound to returned num of entries - might return less than that and still be truncated */ - - cls_statelog_list_op() : max_entries(0) {} - - void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - encode(object, bl); - encode(client_id, bl); - encode(op_id, bl); - encode(marker, bl); - encode(max_entries, bl); - ENCODE_FINISH(bl); - } - - void decode(bufferlist::const_iterator& bl) { - DECODE_START(1, bl); - decode(object, bl); - decode(client_id, bl); - decode(op_id, bl); - decode(marker, bl); - decode(max_entries, bl); - DECODE_FINISH(bl); - } -}; -WRITE_CLASS_ENCODER(cls_statelog_list_op) - -struct cls_statelog_list_ret { - list entries; - string marker; - bool truncated; - - cls_statelog_list_ret() : truncated(false) {} - - void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - encode(entries, bl); - encode(marker, bl); - encode(truncated, bl); - ENCODE_FINISH(bl); - } - - void decode(bufferlist::const_iterator& bl) { - DECODE_START(1, bl); - decode(entries, bl); - decode(marker, bl); - decode(truncated, bl); - DECODE_FINISH(bl); - } -}; -WRITE_CLASS_ENCODER(cls_statelog_list_ret) - - -/* - * operation will return 0 when successfully removed but not done. Will return - * -ENODATA when done, so caller needs to repeat sending request until that. - */ -struct cls_statelog_remove_op { - string client_id; - string op_id; - string object; - - cls_statelog_remove_op() {} - - void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - encode(client_id, bl); - encode(op_id, bl); - encode(object, bl); - ENCODE_FINISH(bl); - } - - void decode(bufferlist::const_iterator& bl) { - DECODE_START(1, bl); - decode(client_id, bl); - decode(op_id, bl); - decode(object, bl); - DECODE_FINISH(bl); - } -}; -WRITE_CLASS_ENCODER(cls_statelog_remove_op) - -struct cls_statelog_check_state_op { - string client_id; - string op_id; - string object; - uint32_t state; - - cls_statelog_check_state_op() : state(0) {} - - void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - encode(client_id, bl); - encode(op_id, bl); - encode(object, bl); - encode(state, bl); - ENCODE_FINISH(bl); - } - - void decode(bufferlist::const_iterator& bl) { - DECODE_START(1, bl); - decode(client_id, bl); - decode(op_id, bl); - decode(object, bl); - decode(state, bl); - DECODE_FINISH(bl); - } -}; -WRITE_CLASS_ENCODER(cls_statelog_check_state_op) - -#endif diff --git a/src/cls/statelog/cls_statelog_types.h b/src/cls/statelog/cls_statelog_types.h deleted file mode 100644 index 939acd157a6c0..0000000000000 --- a/src/cls/statelog/cls_statelog_types.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef CEPH_CLS_STATELOG_TYPES_H -#define CEPH_CLS_STATELOG_TYPES_H - -#include "include/encoding.h" -#include "include/types.h" - -#include "include/utime.h" - -class JSONObj; - -struct cls_statelog_entry { - string client_id; - string op_id; - string object; - utime_t timestamp; - bufferlist data; - uint32_t state; /* user defined state */ - - cls_statelog_entry() : state(0) {} - - void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - encode(client_id, bl); - encode(op_id, bl); - encode(object, bl); - encode(timestamp, bl); - encode(data, bl); - encode(state, bl); - ENCODE_FINISH(bl); - } - - void decode(bufferlist::const_iterator& bl) { - DECODE_START(1, bl); - decode(client_id, bl); - decode(op_id, bl); - decode(object, bl); - decode(timestamp, bl); - decode(data, bl); - decode(state, bl); - DECODE_FINISH(bl); - } - - void dump(Formatter *f) const; - void decode_json(JSONObj *obj); -}; -WRITE_CLASS_ENCODER(cls_statelog_entry) - - -#endif diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index bc06de68aac75..4592520bad2e0 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -17,7 +17,6 @@ if(WITH_RBD) endif(WITH_RBD) add_subdirectory(cls_refcount) add_subdirectory(cls_rgw) -add_subdirectory(cls_statelog) add_subdirectory(cls_version) add_subdirectory(cls_lua) add_subdirectory(common) diff --git a/src/test/cls_statelog/CMakeLists.txt b/src/test/cls_statelog/CMakeLists.txt deleted file mode 100644 index 91e7861005f49..0000000000000 --- a/src/test/cls_statelog/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# ceph_test_cls_statelog -add_executable(ceph_test_cls_statelog - test_cls_statelog.cc - ) -target_link_libraries(ceph_test_cls_statelog - librados - cls_statelog_client - global - ${UNITTEST_LIBS} - ${BLKID_LIBRARIES} - ${CMAKE_DL_LIBS} - ${CRYPTO_LIBS} - ${EXTRALIBS} - radostest - ) - diff --git a/src/test/cls_statelog/test_cls_statelog.cc b/src/test/cls_statelog/test_cls_statelog.cc deleted file mode 100644 index 18b9b95c96965..0000000000000 --- a/src/test/cls_statelog/test_cls_statelog.cc +++ /dev/null @@ -1,211 +0,0 @@ -// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab - -#include "include/types.h" -#include "cls/statelog/cls_statelog_types.h" -#include "cls/statelog/cls_statelog_client.h" - -#include "include/utime.h" -#include "common/Clock.h" -#include "global/global_context.h" - -#include "gtest/gtest.h" -#include "test/librados/test.h" - -#include -#include -#include - -static librados::ObjectWriteOperation *new_op() { - return new librados::ObjectWriteOperation(); -} - -static librados::ObjectReadOperation *new_rop() { - return new librados::ObjectReadOperation(); -} - -static void reset_op(librados::ObjectWriteOperation **pop) { - delete *pop; - *pop = new_op(); -} -static void reset_rop(librados::ObjectReadOperation **pop) { - delete *pop; - *pop = new_rop(); -} - -void add_log(librados::ObjectWriteOperation *op, const string& client_id, const string& op_id, string& obj, uint32_t state) -{ - bufferlist bl; - encode(state, bl); - - utime_t ts = ceph_clock_now(); - - cls_statelog_add(*op, client_id, op_id, obj, ts, state, bl); -} - -void next_op_id(string& op_id, int *id) -{ - char buf[16]; - snprintf(buf, sizeof(buf), "%d", *id); - op_id = buf; - (*id)++; -} - -static string get_obj_name(int num) -{ - char buf[16]; - snprintf(buf, sizeof(buf), "obj-%d", num); - return string(buf); -} - -static void get_entries_by_object(librados::IoCtx& ioctx, string& oid, - list& entries, string& object, string& op_id, int expected) -{ - /* search everything */ - string empty_str, marker; - - librados::ObjectReadOperation *rop = new_rop(); - bufferlist obl; - bool truncated; - cls_statelog_list(*rop, empty_str, op_id, object, marker, 0, entries, &marker, &truncated); - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); - ASSERT_EQ(expected, (int)entries.size()); - delete rop; -} - -static void get_entries_by_client_id(librados::IoCtx& ioctx, string& oid, - list& entries, string& client_id, string& op_id, int expected) -{ - /* search everything */ - string empty_str, marker; - - librados::ObjectReadOperation *rop = new_rop(); - bufferlist obl; - bool truncated; - cls_statelog_list(*rop, client_id, op_id, empty_str, marker, 0, entries, &marker, &truncated); - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); - ASSERT_EQ(expected, (int)entries.size()); - delete rop; -} - -static void get_all_entries(librados::IoCtx& ioctx, string& oid, list& entries, int expected) -{ - /* search everything */ - string object, op_id; - get_entries_by_object(ioctx, oid, entries, object, op_id, expected); -} - -TEST(cls_rgw, test_statelog_basic) -{ - librados::Rados rados; - librados::IoCtx ioctx; - string pool_name = get_temp_pool_name(); - - /* create pool */ - ASSERT_EQ("", create_one_pool_pp(pool_name, rados)); - ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx)); - - string oid = "obj"; - - /* create object */ - ASSERT_EQ(0, ioctx.create(oid, true)); - - int id = 0; - string client_id[] = { "client-1", "client-2" }; - - const int num_ops = 10; - string op_ids[num_ops]; - - librados::ObjectWriteOperation *op = new_op(); - - for (int i = 0; i < num_ops; i++) { - next_op_id(op_ids[i], &id); - string obj = get_obj_name(i / 2); - string cid = client_id[i / (num_ops / 2)]; - add_log(op, cid, op_ids[i], obj, i /* just for testing */); - } - ASSERT_EQ(0, ioctx.operate(oid, op)); - - librados::ObjectReadOperation *rop = new_rop(); - - list entries; - bool truncated; - - /* check list by client_id */ - - int total_count = 0; - for (int j = 0; j < 2; j++) { - string marker; - string obj; - string cid = client_id[j]; - string op_id; - - bufferlist obl; - - cls_statelog_list(*rop, cid, op_id, obj, marker, 1, entries, &marker, &truncated); - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); - ASSERT_EQ(1, (int)entries.size()); - - reset_rop(&rop); - marker.clear(); - cls_statelog_list(*rop, cid, op_id, obj, marker, 0, entries, &marker, &truncated); - obl.clear(); - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); - - ASSERT_EQ(5, (int)entries.size()); - ASSERT_EQ(0, (int)truncated); - - map emap; - for (list::iterator iter = entries.begin(); iter != entries.end(); ++iter) { - ASSERT_EQ(cid, iter->client_id); - emap[iter->op_id] = iter->object; - } - ASSERT_EQ(5, (int)emap.size()); - /* verify correct object */ - for (int i = 0; i < num_ops / 2; i++, total_count++) { - string ret_obj = emap[op_ids[total_count]]; - string obj = get_obj_name(total_count / 2); - ASSERT_EQ(0, ret_obj.compare(obj)); - } - } - - entries.clear(); - /* now search by object */ - total_count = 0; - for (int i = 0; i < num_ops; i++) { - string marker; - string obj = get_obj_name(i / 2); - string cid; - string op_id; - bufferlist obl; - - reset_rop(&rop); - cls_statelog_list(*rop, cid, op_id, obj, marker, 0, entries, &marker, &truncated); - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); - ASSERT_EQ(2, (int)entries.size()); - } - - /* search everything */ - - get_all_entries(ioctx, oid, entries, 10); - - /* now remove an entry */ - cls_statelog_entry e = entries.front(); - entries.pop_front(); - - reset_op(&op); - cls_statelog_remove_by_client(*op, e.client_id, e.op_id); - ASSERT_EQ(0, ioctx.operate(oid, op)); - - get_all_entries(ioctx, oid, entries, 9); - - get_entries_by_object(ioctx, oid, entries, e.object, e.op_id, 0); - get_entries_by_client_id(ioctx, oid, entries, e.client_id, e.op_id, 0); - - string empty_str; - get_entries_by_client_id(ioctx, oid, entries, e.client_id, empty_str, 4); - get_entries_by_object(ioctx, oid, entries, e.object, empty_str, 1); - delete op; - delete rop; -} - -- 2.39.5