ldb to display public unique id and dump work with key range (#10417)

Summary:
2 ldb command improvements:
1. `ldb manifest_dump --verbose` display both the internal unique id and public id. which is useful to manually check sst_unique_id between manifest and SST;
2. `ldb dump` has `--from/to` option, but not working. Add support for that.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10417

Test Plan:
run the command locally
```
$ ldb manifest_dump --path=MANIFEST-000026 --verbose
...
AddFile: 0 18 1023 'bar' seq:6, type:1 .. 'foo' seq:5, type:1 oldest_ancester_time:1658787615 file_creation_time:1658787615 file_checksum: file_checksum_func_name: Unknown unique_id(internal): {8800772265202404198,16149248642318466463} public_unique_id: F3E0A029B631D7D4-6E402DE08E771780
```
```
$ ldb dump --path=000036.sst --from=key000006 --to=key000009
Sst file format: block-based
'key000006' seq:2411, type:1 => value6
'key000007' seq:2412, type:1 => value7
'key000008' seq:2413, type:1 => value8
...
```

Reviewed By: ajkr

Differential Revision: D38136140

Pulled By: jay-zhuang

fbshipit-source-id: 8be6eeaa07ff9f089e33011ebe90fd0b69d33bf3
main
Jay Zhuang 2 years ago committed by Facebook GitHub Bot
parent c945a9a664
commit 6a0010eb46
  1. 3
      db/version_edit.cc
  2. 15
      tools/ldb_cmd.cc

@ -852,6 +852,9 @@ std::string VersionEdit::DebugString(bool hex_key) const {
r.append(" unique_id(internal): "); r.append(" unique_id(internal): ");
UniqueId64x2 id = f.unique_id; UniqueId64x2 id = f.unique_id;
r.append(InternalUniqueIdToHumanString(&id)); r.append(InternalUniqueIdToHumanString(&id));
r.append(" public_unique_id: ");
InternalUniqueIdToExternal(&id);
r.append(UniqueIdToHumanString(EncodeUniqueIdBytes(&id)));
} }
} }

@ -117,7 +117,8 @@ void DumpWalFile(Options options, std::string wal_file, bool print_header,
LDBCommandExecuteResult* exec_state); LDBCommandExecuteResult* exec_state);
void DumpSstFile(Options options, std::string filename, bool output_hex, void DumpSstFile(Options options, std::string filename, bool output_hex,
bool show_properties, bool decode_blob_index); bool show_properties, bool decode_blob_index,
std::string from_key = "", std::string to_key = "");
void DumpBlobFile(const std::string& filename, bool is_key_hex, void DumpBlobFile(const std::string& filename, bool is_key_hex,
bool is_value_hex, bool dump_uncompressed_blobs); bool is_value_hex, bool dump_uncompressed_blobs);
@ -2045,7 +2046,7 @@ void DBDumperCommand::DoCommand() {
break; break;
case kTableFile: case kTableFile:
DumpSstFile(options_, path_, is_key_hex_, /* show_properties */ true, DumpSstFile(options_, path_, is_key_hex_, /* show_properties */ true,
decode_blob_index_); decode_blob_index_, from_, to_);
break; break;
case kDescriptorFile: case kDescriptorFile:
DumpManifestFile(options_, path_, /* verbose_ */ false, is_key_hex_, DumpManifestFile(options_, path_, /* verbose_ */ false, is_key_hex_,
@ -3602,9 +3603,8 @@ void RestoreCommand::DoCommand() {
namespace { namespace {
void DumpSstFile(Options options, std::string filename, bool output_hex, void DumpSstFile(Options options, std::string filename, bool output_hex,
bool show_properties, bool decode_blob_index) { bool show_properties, bool decode_blob_index,
std::string from_key; std::string from_key, std::string to_key) {
std::string to_key;
if (filename.length() <= 4 || if (filename.length() <= 4 ||
filename.rfind(".sst") != filename.length() - 4) { filename.rfind(".sst") != filename.length() - 4) {
std::cout << "Invalid sst file name." << std::endl; std::cout << "Invalid sst file name." << std::endl;
@ -3616,9 +3616,8 @@ void DumpSstFile(Options options, std::string filename, bool output_hex,
2 * 1024 * 1024 /* readahead_size */, 2 * 1024 * 1024 /* readahead_size */,
/* verify_checksum */ false, output_hex, decode_blob_index); /* verify_checksum */ false, output_hex, decode_blob_index);
Status st = dumper.ReadSequential(true, std::numeric_limits<uint64_t>::max(), Status st = dumper.ReadSequential(true, std::numeric_limits<uint64_t>::max(),
false, // has_from !from_key.empty(), from_key,
from_key, false, // has_to !to_key.empty(), to_key);
to_key);
if (!st.ok()) { if (!st.ok()) {
std::cerr << "Error in reading SST file " << filename << st.ToString() std::cerr << "Error in reading SST file " << filename << st.ToString()
<< std::endl; << std::endl;

Loading…
Cancel
Save