未验证 提交 e5fcffd5 编写于 作者: W Wu Tao 提交者: GitHub

feat(shell): add debugging commands for hex and escaped-string conversion (#395)

上级 da4bc679
......@@ -11,7 +11,6 @@
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <rocksdb/db.h>
#include <rocksdb/sst_dump_tool.h>
#include <dsn/utility/filesystem.h>
#include <dsn/utility/output_utils.h>
#include <dsn/utility/string_conv.h>
......@@ -206,3 +205,9 @@ bool sst_dump(command_executor *e, shell_context *sc, arguments args);
bool mlog_dump(command_executor *e, shell_context *sc, arguments args);
bool local_get(command_executor *e, shell_context *sc, arguments args);
bool rdb_key_hex2str(command_executor *e, shell_context *sc, arguments args);
bool rdb_key_str2hex(command_executor *e, shell_context *sc, arguments args);
bool rdb_value_hex2str(command_executor *e, shell_context *sc, arguments args);
......@@ -3,6 +3,9 @@
// can be found in the LICENSE file in the root directory of this source tree.
#include "shell/commands.h"
#include <rocksdb/sst_dump_tool.h>
#include <rocksdb/utilities/ldb_cmd.h>
#include <fmt/time.h>
bool sst_dump(command_executor *e, shell_context *sc, arguments args)
{
......@@ -189,3 +192,52 @@ bool local_get(command_executor *e, shell_context *sc, arguments args)
delete db;
return true;
}
bool rdb_key_str2hex(command_executor *e, shell_context *sc, arguments args)
{
if (args.argc != 3) {
return false;
}
std::string hash_key = sds_to_string(args.argv[1]);
std::string sort_key = sds_to_string(args.argv[2]);
::dsn::blob key;
pegasus::pegasus_generate_key(key, hash_key, sort_key);
rocksdb::Slice skey(key.data(), key.length());
fprintf(stderr, "\"%s\"\n", skey.ToString(true).c_str());
return true;
}
bool rdb_key_hex2str(command_executor *e, shell_context *sc, arguments args)
{
if (args.argc != 2) {
return false;
}
std::string hex_rdb_key = sds_to_string(args.argv[1]);
dsn::blob key = dsn::blob::create_from_bytes(rocksdb::LDBCommand::HexToString(hex_rdb_key));
std::string hash_key, sort_key;
pegasus::pegasus_restore_key(key, hash_key, sort_key);
fmt::print(
stderr, "\nhash key: \"{}\"\n", pegasus::utils::c_escape_string(hash_key, sc->escape_all));
fmt::print(
stderr, "\nsort key: \"{}\"\n", pegasus::utils::c_escape_string(sort_key, sc->escape_all));
return true;
}
bool rdb_value_hex2str(command_executor *e, shell_context *sc, arguments args)
{
if (args.argc != 2) {
return false;
}
std::string hex_rdb_value = sds_to_string(args.argv[1]);
std::string pegasus_value = rocksdb::LDBCommand::HexToString(hex_rdb_value);
auto expire_ts = static_cast<int64_t>(pegasus::pegasus_extract_expire_ts(0, pegasus_value)) +
pegasus::utils::epoch_begin; // TODO(wutao): pass user specified version
fmt::print(stderr, "\nWhen to expire:\n {:%Y-%m-%d %H:%M:%S}\n", *std::localtime(&expire_ts));
dsn::blob user_data;
pegasus::pegasus_extract_user_data(0, std::move(pegasus_value), user_data);
fprintf(stderr,
"user_data:\n \"%s\"\n",
pegasus::utils::c_escape_string(user_data.to_string(), sc->escape_all).c_str());
return true;
}
......@@ -325,6 +325,24 @@ static command_executor commands[] = {
{
"local_get", "get value from local db", "<db_path> <hash_key> <sort_key>", local_get,
},
{
"rdb_key_str2hex",
"transform the given hashkey and sortkey to rocksdb raw key in hex representation",
"<hash_key> <sort_key>",
rdb_key_str2hex,
},
{
"rdb_key_hex2str",
"transform the given rocksdb raw key in hex representation to hash key and sort key",
"<rdb_key_in_hex>",
rdb_key_hex2str,
},
{
"rdb_value_hex2str",
"parse the given rocksdb raw value in hex representation",
"<value_in_hex>",
rdb_value_hex2str,
},
{
"sst_dump",
"dump sstable dir or files",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册