sst_dump: Add --output_hex option and output the same format as ldb dump
Summary: Now sst_dump has the same option --output_hex as "ldb dump" and also share the same output format. So we can do "sst_dump ... | ldb load ..." for an experiment. Test Plan: [zshao@dev485 ~/git/rocksdb] ./sst_dump --file=/data/users/zshao/test_leveldb/000005.sst --output_hex | head -n 2 0000027F4FBE00000101000000000000 ==> D901000000000000000057596F7520726563656976656420746F6461792773207370656369616C20676966742120436C69636B2041636365707420746F207669657720796F75722047696674206265666F72652069742064697361707065617273210000000000000000 000007F9C2D400000102000000000000 ==> D1010000000000000000544974277320676F6F6420746F206265204B696E67E280A6206F7220517565656E212048657265277320796F75722054756573646179204D79737465727920476966742066726F6D20436173746C6556696C6C65219B7B227A636F6465223A22633566306531633039663764222C227470223A22613275222C227A6B223A22663638663061343262666264303966383435666239626235366365396536643024246234506C345139382E734C4D33522169482D4F31315A64794C4B7A4F4653766D7863746534625F2A3968684E3433786521776C427636504A414355795F70222C227473223A313334343936313737357D0000000000000000 Reviewers: dhruba, sheki, emayanke Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D7587
This commit is contained in:
parent
70f0f50731
commit
01d57a33fe
@ -22,7 +22,9 @@ namespace leveldb {
|
||||
|
||||
class SstFileReader {
|
||||
public:
|
||||
SstFileReader(std::string file_name, bool verify_checksum = false);
|
||||
SstFileReader(std::string file_name,
|
||||
bool verify_checksum = false,
|
||||
bool output_hex = false);
|
||||
Status ReadSequential(bool print_kv, uint64_t read_num = -1);
|
||||
|
||||
uint64_t GetReadNumber() { return read_num_; }
|
||||
@ -31,10 +33,14 @@ private:
|
||||
std::string file_name_;
|
||||
uint64_t read_num_;
|
||||
bool verify_checksum_;
|
||||
bool output_hex_;
|
||||
};
|
||||
|
||||
SstFileReader::SstFileReader(std::string file_path, bool verify_checksum)
|
||||
:file_name_(file_path), read_num_(0), verify_checksum_(verify_checksum) {
|
||||
SstFileReader::SstFileReader(std::string file_path,
|
||||
bool verify_checksum,
|
||||
bool output_hex)
|
||||
:file_name_(file_path), read_num_(0), verify_checksum_(verify_checksum),
|
||||
output_hex_(output_hex) {
|
||||
}
|
||||
|
||||
Status SstFileReader::ReadSequential(bool print_kv, uint64_t read_num)
|
||||
@ -62,8 +68,9 @@ Status SstFileReader::ReadSequential(bool print_kv, uint64_t read_num)
|
||||
if (read_num > 0 && i > read_num)
|
||||
break;
|
||||
if (print_kv) {
|
||||
fprintf(stdout, "%s : %s\n",
|
||||
key.ToString().c_str(), value.ToString().c_str());
|
||||
fprintf(stdout, "%s ==> %s\n",
|
||||
key.ToString(output_hex_).c_str(),
|
||||
value.ToString(output_hex_).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,6 +87,7 @@ static void print_help() {
|
||||
fprintf(stderr,
|
||||
"sst_dump [--command=check|scan] [--verify_checksum] "
|
||||
"--file=data_dir_OR_sst_file"
|
||||
" [--output_hex]"
|
||||
" [--read_num=NUM]\n");
|
||||
}
|
||||
|
||||
@ -92,10 +100,13 @@ int main(int argc, char** argv) {
|
||||
char junk;
|
||||
uint64_t n;
|
||||
bool verify_checksum = false;
|
||||
bool output_hex = false;
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (strncmp(argv[i], "--file=", 7) == 0) {
|
||||
dir_or_file = argv[i] + 7;
|
||||
} else if (strncmp(argv[i], "--output_hex", 12) == 0) {
|
||||
output_hex = true;
|
||||
} else if (sscanf(argv[i], "--read_num=%ld%c", &n, &junk) == 1) {
|
||||
read_num = n;
|
||||
} else if (strncmp(argv[i], "--verify_checksum",
|
||||
@ -133,9 +144,10 @@ int main(int argc, char** argv) {
|
||||
continue;
|
||||
}
|
||||
if(dir) {
|
||||
filename = dir_or_file + filename;
|
||||
filename = std::string(dir_or_file) + "//" + filename;
|
||||
}
|
||||
leveldb::SstFileReader reader(filename, verify_checksum);
|
||||
leveldb::SstFileReader reader(filename, verify_checksum,
|
||||
output_hex);
|
||||
leveldb::Status st;
|
||||
// scan all files in give file path.
|
||||
if (command == "" || command == "scan" || command == "check") {
|
||||
|
Loading…
Reference in New Issue
Block a user