Skip to content

Commit

Permalink
feat(shell): mlog_dump support parsing check_and_set (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wu Tao authored and neverchanje committed Mar 31, 2020
1 parent c5e98eb commit 2e0afc7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
24 changes: 24 additions & 0 deletions src/base/idl_utils.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/idl/recompile_thrift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions src/idl/rrdb.thrift.annotations

This file was deleted.

4 changes: 2 additions & 2 deletions src/shell/commands/data_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions src/shell/commands/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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() << "("
Expand Down

0 comments on commit 2e0afc7

Please sign in to comment.