提交 2e0afc75 编写于 作者: W Wu Tao 提交者: neverchanje

feat(shell): mlog_dump support parsing check_and_set (#485)

上级 c5e98eb9
// 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
......@@ -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 <dsn\/service_api_cpp.h>/' $TMP_DIR/rrdb_types.h > ../include/rrdb/rrdb_types.h
sed 's/#include "rrdb_types.h"/#include <rrdb\/rrdb_types.h>/' $TMP_DIR/rrdb_types.cpp > ../base/rrdb_types.cpp
......
[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
......@@ -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<std::unique_ptr<scan_data_context>> &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;
}
......
......@@ -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 <rocksdb/sst_dump_tool.h>
#include <rocksdb/utilities/ldb_cmd.h>
#include <fmt/time.h>
......@@ -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() << "("
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册