From 14c0380e78637df0e94b874907b1e86a32d134ca Mon Sep 17 00:00:00 2001 From: Anirban Rahut Date: Thu, 10 Nov 2016 10:06:06 -0800 Subject: [PATCH] Convenience option to parse an internal key on command line Summary: enhancing sst_dump to be able to parse internal key Closes https://github.com/facebook/rocksdb/pull/1482 Differential Revision: D4154175 Pulled By: siying fbshipit-source-id: b0e28b1 --- tools/sst_dump_tool.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/sst_dump_tool.cc b/tools/sst_dump_tool.cc index d2468e4d1..532120ab6 100644 --- a/tools/sst_dump_tool.cc +++ b/tools/sst_dump_tool.cc @@ -385,6 +385,10 @@ void print_help() { --set_block_size= Can be combined with --show_compression_sizes to set the block size that will be used when trying different compression algorithms + + --parse_internal_key=<0xKEY> + Convenience option to parse an internal key on the command line. Dumps the + internal key in hex format {'key' @ SN: type} )"); } @@ -443,6 +447,26 @@ int SSTDumpTool::Run(int argc, char** argv) { exit(1); } iss >> block_size; + } else if (strncmp(argv[i], "--parse_internal_key=", 21) == 0) { + std::string in_key(argv[i] + 21); + try { + in_key = rocksdb::LDBCommand::HexToString(in_key); + } catch (...) { + std::cerr << "ERROR: Invalid key input '" + << in_key + << "' Use 0x{hex representation of internal rocksdb key}" << std::endl; + return -1; + } + Slice sl_key = rocksdb::Slice(in_key); + ParsedInternalKey ikey; + int retc = 0; + if (!ParseInternalKey(sl_key, &ikey)) { + std::cerr << "Internal Key [" << sl_key.ToString(true /* in hex*/) + << "] parse error!\n"; + retc = -1; + } + fprintf(stdout, "key=%s\n", ikey.DebugString(true).c_str()); + return retc; } else { print_help(); exit(1);