From 0b2cfb181c826c7b0eba701a190170150a16be48 Mon Sep 17 00:00:00 2001 From: Wu Tao Date: Mon, 2 Mar 2020 13:23:59 +0800 Subject: [PATCH] feat(shell): mlog_dump support parsing check_and_set (#485) --- src/base/idl_utils.h | 24 ++++++++++++++++++++++++ src/idl/recompile_thrift.sh | 2 +- src/idl/rrdb.thrift.annotations | 20 -------------------- src/shell/commands/data_operations.cpp | 4 ++-- src/shell/commands/debugger.cpp | 24 ++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 src/base/idl_utils.h delete mode 100644 src/idl/rrdb.thrift.annotations diff --git a/src/base/idl_utils.h b/src/base/idl_utils.h new file mode 100644 index 0000000..bf2840d --- /dev/null +++ b/src/base/idl_utils.h @@ -0,0 +1,24 @@ +// Copyright (c) 2017, Xiaomi, Inc. All rights reserved. +// This source code is licensed under the Apache License Version 2.0, which +// can be found in the LICENSE file in the root directory of this source tree. + +#pragma once + +namespace pegasus { + +inline std::string cas_check_type_to_string(dsn::apps::cas_check_type::type type) +{ + using namespace dsn::apps; + auto it = _cas_check_type_VALUES_TO_NAMES.find(type); + if (it == _cas_check_type_VALUES_TO_NAMES.end()) { + return std::string("INVALID=") + std::to_string(int(type)); + } + return it->second; +} + +inline bool cas_is_check_operand_needed(dsn::apps::cas_check_type::type type) +{ + return type >= dsn::apps::cas_check_type::CT_VALUE_MATCH_ANYWHERE; +} + +} // namespace pegasus diff --git a/src/idl/recompile_thrift.sh b/src/idl/recompile_thrift.sh index 82be9ec..39dc797 100755 --- a/src/idl/recompile_thrift.sh +++ b/src/idl/recompile_thrift.sh @@ -13,7 +13,7 @@ TMP_DIR=./tmp rm -rf $TMP_DIR mkdir -p $TMP_DIR -$DSN_ROOT/bin/Linux/thrift --gen cpp:moveable_types -out $TMP_DIR rrdb.thrift +$DSN_ROOT/thirdparty/output/bin/thrift --gen cpp:moveable_types -out $TMP_DIR rrdb.thrift sed 's/#include "dsn_types.h"/#include /' $TMP_DIR/rrdb_types.h > ../include/rrdb/rrdb_types.h sed 's/#include "rrdb_types.h"/#include /' $TMP_DIR/rrdb_types.cpp > ../base/rrdb_types.cpp diff --git a/src/idl/rrdb.thrift.annotations b/src/idl/rrdb.thrift.annotations deleted file mode 100644 index d91cb2a..0000000 --- a/src/idl/rrdb.thrift.annotations +++ /dev/null @@ -1,20 +0,0 @@ -[service.rrdb] -stateful = true - -[function.rrdb.put] -write = true - -[function.rrdb.remove] -write = true - -[function.rrdb.get] -write = false - -[function.rrdb.get_scanner] -write = false - -[function.rrdb.scan] -write = false - -[function.rrdb.clear_scanner] -write = false diff --git a/src/shell/commands/data_operations.cpp b/src/shell/commands/data_operations.cpp index e7711ec..b9dad86 100644 --- a/src/shell/commands/data_operations.cpp +++ b/src/shell/commands/data_operations.cpp @@ -3,6 +3,7 @@ // can be found in the LICENSE file in the root directory of this source tree. #include "shell/commands.h" +#include "idl_utils.h" static void print_current_scan_state(const std::vector> &contexts, @@ -737,8 +738,7 @@ bool check_and_set(command_executor *e, shell_context *sc, arguments args) fprintf(stderr, "ERROR: check_type not provided\n"); return false; } - if (!check_operand_provided && - check_type >= ::dsn::apps::cas_check_type::CT_VALUE_MATCH_ANYWHERE) { + if (!check_operand_provided && pegasus::cas_is_check_operand_needed(check_type)) { fprintf(stderr, "ERROR: check_operand not provided\n"); return false; } diff --git a/src/shell/commands/debugger.cpp b/src/shell/commands/debugger.cpp index d174643..78677ed 100644 --- a/src/shell/commands/debugger.cpp +++ b/src/shell/commands/debugger.cpp @@ -3,6 +3,7 @@ // can be found in the LICENSE file in the root directory of this source tree. #include "shell/commands.h" +#include "base/idl_utils.h" #include #include #include @@ -129,6 +130,29 @@ bool mlog_dump(command_executor *e, shell_context *sc, arguments args) << pegasus::utils::c_escape_string(hash_key, sc->escape_all) << "\" : \"" << pegasus::utils::c_escape_string(sort_key, sc->escape_all) << "\" => " << update.increment << std::endl; + } else if (msg->local_rpc_code == ::dsn::apps::RPC_RRDB_RRDB_CHECK_AND_SET) { + dsn::apps::check_and_set_request update; + dsn::unmarshall(request, update); + auto set_sort_key = + update.set_diff_sort_key ? update.set_sort_key : update.check_sort_key; + std::string check_operand; + if (pegasus::cas_is_check_operand_needed(update.check_type)) { + check_operand = fmt::format( + "\"{}\" ", + pegasus::utils::c_escape_string(update.check_operand, sc->escape_all)); + } + os << INDENT + << fmt::format( + "[CHECK_AND_SET] \"{}\" : IF SORT_KEY({}) {} {}" + "THEN SET SORT_KEY({}) => VALUE({}) [expire={}]\n", + pegasus::utils::c_escape_string(update.hash_key, sc->escape_all), + pegasus::utils::c_escape_string(update.check_sort_key, + sc->escape_all), + pegasus::cas_check_type_to_string(update.check_type), + check_operand, + pegasus::utils::c_escape_string(set_sort_key, sc->escape_all), + pegasus::utils::c_escape_string(update.set_value, sc->escape_all), + update.set_expire_ts_seconds); } else { os << INDENT << "ERROR: unsupported code " << ::dsn::task_code(msg->local_rpc_code).to_string() << "(" -- GitLab