2013-10-16 23:59:46 +02:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
2012-08-24 20:28:59 +02:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2014-02-08 04:26:49 +01:00
|
|
|
#include <inttypes.h>
|
2012-08-24 20:28:59 +02:00
|
|
|
|
|
|
|
#include "db/dbformat.h"
|
|
|
|
#include "db/memtable.h"
|
|
|
|
#include "db/write_batch_internal.h"
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include "rocksdb/iterator.h"
|
2014-02-05 01:21:47 +01:00
|
|
|
#include "rocksdb/slice_transform.h"
|
2013-10-29 01:54:09 +01:00
|
|
|
#include "rocksdb/table.h"
|
2014-01-27 21:45:08 +01:00
|
|
|
#include "rocksdb/table_properties.h"
|
2014-02-05 01:21:47 +01:00
|
|
|
#include "table/block_based_table_factory.h"
|
|
|
|
#include "table/plain_table_factory.h"
|
2014-05-01 20:09:32 +02:00
|
|
|
#include "table/meta_blocks.h"
|
2012-08-24 20:28:59 +02:00
|
|
|
#include "table/block.h"
|
|
|
|
#include "table/block_builder.h"
|
|
|
|
#include "table/format.h"
|
2014-04-15 20:28:52 +02:00
|
|
|
#include "util/ldb_cmd.h"
|
2012-08-24 20:28:59 +02:00
|
|
|
#include "util/random.h"
|
|
|
|
#include "util/testharness.h"
|
|
|
|
#include "util/testutil.h"
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2012-08-24 20:28:59 +02:00
|
|
|
|
|
|
|
class SstFileReader {
|
2013-08-07 22:36:26 +02:00
|
|
|
public:
|
|
|
|
explicit SstFileReader(const std::string& file_name,
|
|
|
|
bool verify_checksum,
|
|
|
|
bool output_hex);
|
|
|
|
|
|
|
|
Status ReadSequential(bool print_kv,
|
|
|
|
uint64_t read_num,
|
|
|
|
bool has_from,
|
|
|
|
const std::string& from_key,
|
|
|
|
bool has_to,
|
|
|
|
const std::string& to_key);
|
2012-08-24 20:28:59 +02:00
|
|
|
|
2014-02-08 04:26:49 +01:00
|
|
|
Status ReadTableProperties(
|
|
|
|
std::shared_ptr<const TableProperties>* table_properties);
|
2012-08-24 20:28:59 +02:00
|
|
|
uint64_t GetReadNumber() { return read_num_; }
|
2014-06-07 02:17:12 +02:00
|
|
|
TableProperties* GetInitTableProperties() { return table_properties_.get(); }
|
2012-08-24 20:28:59 +02:00
|
|
|
|
2014-01-27 21:45:08 +01:00
|
|
|
private:
|
|
|
|
Status NewTableReader(const std::string& file_path);
|
2014-06-07 02:17:12 +02:00
|
|
|
Status ReadTableProperties(uint64_t table_magic_number,
|
|
|
|
RandomAccessFile* file, uint64_t file_size);
|
|
|
|
Status SetTableOptionsByMagicNumber(uint64_t table_magic_number);
|
2014-08-14 18:59:41 +02:00
|
|
|
Status SetOldTableOptions();
|
2014-01-27 21:45:08 +01:00
|
|
|
|
2012-08-24 20:28:59 +02:00
|
|
|
std::string file_name_;
|
|
|
|
uint64_t read_num_;
|
2012-08-25 01:28:06 +02:00
|
|
|
bool verify_checksum_;
|
2012-12-21 08:49:32 +01:00
|
|
|
bool output_hex_;
|
2013-06-08 00:35:17 +02:00
|
|
|
EnvOptions soptions_;
|
2014-01-27 21:45:08 +01:00
|
|
|
|
|
|
|
Status init_result_;
|
|
|
|
unique_ptr<TableReader> table_reader_;
|
|
|
|
unique_ptr<RandomAccessFile> file_;
|
2014-02-05 01:21:47 +01:00
|
|
|
// options_ and internal_comparator_ will also be used in
|
2014-01-27 21:45:08 +01:00
|
|
|
// ReadSequential internally (specifically, seek-related operations)
|
2014-02-05 01:21:47 +01:00
|
|
|
Options options_;
|
2014-01-27 21:45:08 +01:00
|
|
|
InternalKeyComparator internal_comparator_;
|
2014-06-07 02:17:12 +02:00
|
|
|
unique_ptr<TableProperties> table_properties_;
|
2012-08-24 20:28:59 +02:00
|
|
|
};
|
|
|
|
|
2013-08-07 22:36:26 +02:00
|
|
|
SstFileReader::SstFileReader(const std::string& file_path,
|
2012-12-21 08:49:32 +01:00
|
|
|
bool verify_checksum,
|
|
|
|
bool output_hex)
|
2014-01-27 21:45:08 +01:00
|
|
|
:file_name_(file_path), read_num_(0), verify_checksum_(verify_checksum),
|
|
|
|
output_hex_(output_hex), internal_comparator_(BytewiseComparator()) {
|
|
|
|
fprintf(stdout, "Process %s\n", file_path.c_str());
|
|
|
|
|
|
|
|
init_result_ = NewTableReader(file_name_);
|
|
|
|
}
|
|
|
|
|
2014-02-05 01:21:47 +01:00
|
|
|
extern uint64_t kBlockBasedTableMagicNumber;
|
2014-06-12 19:54:57 +02:00
|
|
|
extern uint64_t kLegacyBlockBasedTableMagicNumber;
|
2014-02-05 01:21:47 +01:00
|
|
|
extern uint64_t kPlainTableMagicNumber;
|
2014-06-12 19:54:57 +02:00
|
|
|
extern uint64_t kLegacyPlainTableMagicNumber;
|
2014-02-05 01:21:47 +01:00
|
|
|
|
2014-01-27 21:45:08 +01:00
|
|
|
Status SstFileReader::NewTableReader(const std::string& file_path) {
|
2014-02-05 01:21:47 +01:00
|
|
|
uint64_t magic_number;
|
2014-05-01 20:09:32 +02:00
|
|
|
|
|
|
|
// read table magic number
|
|
|
|
Footer footer;
|
|
|
|
|
|
|
|
unique_ptr<RandomAccessFile> file;
|
|
|
|
uint64_t file_size;
|
|
|
|
Status s = options_.env->NewRandomAccessFile(file_path, &file_, soptions_);
|
|
|
|
if (s.ok()) {
|
|
|
|
s = options_.env->GetFileSize(file_path, &file_size);
|
2014-02-05 01:21:47 +01:00
|
|
|
}
|
2014-05-01 20:09:32 +02:00
|
|
|
if (s.ok()) {
|
|
|
|
s = ReadFooterFromFile(file_.get(), file_size, &footer);
|
2014-02-05 01:21:47 +01:00
|
|
|
}
|
2014-05-01 20:09:32 +02:00
|
|
|
if (s.ok()) {
|
|
|
|
magic_number = footer.table_magic_number();
|
2014-01-27 21:45:08 +01:00
|
|
|
}
|
2014-05-01 20:09:32 +02:00
|
|
|
|
|
|
|
if (s.ok()) {
|
2014-06-12 19:54:57 +02:00
|
|
|
if (magic_number == kPlainTableMagicNumber ||
|
|
|
|
magic_number == kLegacyPlainTableMagicNumber) {
|
2014-05-01 20:09:32 +02:00
|
|
|
soptions_.use_mmap_reads = true;
|
2014-06-12 19:54:57 +02:00
|
|
|
options_.env->NewRandomAccessFile(file_path, &file_, soptions_);
|
2014-05-01 20:09:32 +02:00
|
|
|
}
|
|
|
|
options_.comparator = &internal_comparator_;
|
2014-08-14 18:59:41 +02:00
|
|
|
// For old sst format, ReadTableProperties might fail but file can be read
|
|
|
|
if (ReadTableProperties(magic_number, file_.get(), file_size).ok()) {
|
|
|
|
SetTableOptionsByMagicNumber(magic_number);
|
|
|
|
} else {
|
|
|
|
SetOldTableOptions();
|
2014-06-07 02:17:12 +02:00
|
|
|
}
|
2014-02-05 01:21:47 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 20:09:32 +02:00
|
|
|
if (s.ok()) {
|
|
|
|
s = options_.table_factory->NewTableReader(
|
|
|
|
options_, soptions_, internal_comparator_, std::move(file_), file_size,
|
|
|
|
&table_reader_);
|
|
|
|
}
|
2014-01-27 21:45:08 +01:00
|
|
|
return s;
|
2012-08-24 20:28:59 +02:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:17:12 +02:00
|
|
|
Status SstFileReader::ReadTableProperties(uint64_t table_magic_number,
|
|
|
|
RandomAccessFile* file,
|
|
|
|
uint64_t file_size) {
|
2014-08-14 18:59:41 +02:00
|
|
|
TableProperties* table_properties = nullptr;
|
2014-02-05 01:21:47 +01:00
|
|
|
Status s = rocksdb::ReadTableProperties(file, file_size, table_magic_number,
|
|
|
|
options_.env, options_.info_log.get(),
|
|
|
|
&table_properties);
|
2014-08-14 18:59:41 +02:00
|
|
|
if (s.ok()) {
|
|
|
|
table_properties_.reset(table_properties);
|
|
|
|
} else {
|
|
|
|
fprintf(stdout, "Not able to read table properties\n");
|
|
|
|
}
|
2014-06-07 02:17:12 +02:00
|
|
|
return s;
|
|
|
|
}
|
2014-02-05 01:21:47 +01:00
|
|
|
|
2014-06-07 02:17:12 +02:00
|
|
|
Status SstFileReader::SetTableOptionsByMagicNumber(
|
|
|
|
uint64_t table_magic_number) {
|
|
|
|
assert(table_properties_);
|
2014-06-12 19:54:57 +02:00
|
|
|
if (table_magic_number == kBlockBasedTableMagicNumber ||
|
|
|
|
table_magic_number == kLegacyBlockBasedTableMagicNumber) {
|
2014-02-05 01:21:47 +01:00
|
|
|
options_.table_factory = std::make_shared<BlockBasedTableFactory>();
|
|
|
|
fprintf(stdout, "Sst file format: block-based\n");
|
2014-06-07 02:17:12 +02:00
|
|
|
auto& props = table_properties_->user_collected_properties;
|
2014-06-06 00:12:32 +02:00
|
|
|
auto pos = props.find(BlockBasedTablePropertyNames::kIndexType);
|
|
|
|
if (pos != props.end()) {
|
|
|
|
auto index_type_on_file = static_cast<BlockBasedTableOptions::IndexType>(
|
|
|
|
DecodeFixed32(pos->second.c_str()));
|
|
|
|
if (index_type_on_file ==
|
|
|
|
BlockBasedTableOptions::IndexType::kHashSearch) {
|
|
|
|
options_.prefix_extractor.reset(NewNoopTransform());
|
|
|
|
}
|
|
|
|
}
|
2014-06-12 19:54:57 +02:00
|
|
|
} else if (table_magic_number == kPlainTableMagicNumber ||
|
|
|
|
table_magic_number == kLegacyPlainTableMagicNumber) {
|
2014-02-05 01:21:47 +01:00
|
|
|
options_.allow_mmap_reads = true;
|
2014-07-18 09:08:38 +02:00
|
|
|
|
|
|
|
PlainTableOptions plain_table_options;
|
|
|
|
plain_table_options.user_key_len = kPlainTableVariableLength;
|
|
|
|
plain_table_options.bloom_bits_per_key = 0;
|
|
|
|
plain_table_options.hash_table_ratio = 0;
|
|
|
|
plain_table_options.index_sparseness = 1;
|
|
|
|
plain_table_options.huge_page_tlb_size = 0;
|
|
|
|
plain_table_options.encoding_type = kPlain;
|
|
|
|
plain_table_options.full_scan_mode = true;
|
|
|
|
|
|
|
|
options_.table_factory.reset(NewPlainTableFactory(plain_table_options));
|
2014-02-05 01:21:47 +01:00
|
|
|
fprintf(stdout, "Sst file format: plain table\n");
|
|
|
|
} else {
|
|
|
|
char error_msg_buffer[80];
|
|
|
|
snprintf(error_msg_buffer, sizeof(error_msg_buffer) - 1,
|
2014-02-08 04:47:48 +01:00
|
|
|
"Unsupported table magic number --- %lx",
|
|
|
|
(long)table_magic_number);
|
2014-02-05 01:21:47 +01:00
|
|
|
return Status::InvalidArgument(error_msg_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2014-08-14 18:59:41 +02:00
|
|
|
Status SstFileReader::SetOldTableOptions() {
|
|
|
|
assert(table_properties_ == nullptr);
|
|
|
|
options_.table_factory = std::make_shared<BlockBasedTableFactory>();
|
|
|
|
fprintf(stdout, "Sst file format: block-based(old version)\n");
|
|
|
|
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2013-08-07 22:36:26 +02:00
|
|
|
Status SstFileReader::ReadSequential(bool print_kv,
|
|
|
|
uint64_t read_num,
|
|
|
|
bool has_from,
|
|
|
|
const std::string& from_key,
|
|
|
|
bool has_to,
|
2014-01-27 21:45:08 +01:00
|
|
|
const std::string& to_key) {
|
|
|
|
if (!table_reader_) {
|
|
|
|
return init_result_;
|
2012-08-24 20:28:59 +02:00
|
|
|
}
|
|
|
|
|
2014-01-27 21:45:08 +01:00
|
|
|
Iterator* iter = table_reader_->NewIterator(ReadOptions(verify_checksum_,
|
2013-10-30 18:52:33 +01:00
|
|
|
false));
|
2012-08-29 21:29:43 +02:00
|
|
|
uint64_t i = 0;
|
2013-08-07 22:36:26 +02:00
|
|
|
if (has_from) {
|
|
|
|
InternalKey ikey(from_key, kMaxSequenceNumber, kValueTypeForSeek);
|
|
|
|
iter->Seek(ikey.Encode());
|
|
|
|
} else {
|
|
|
|
iter->SeekToFirst();
|
|
|
|
}
|
|
|
|
for (; iter->Valid(); iter->Next()) {
|
2012-08-24 20:28:59 +02:00
|
|
|
Slice key = iter->key();
|
|
|
|
Slice value = iter->value();
|
|
|
|
++i;
|
2012-08-25 01:28:06 +02:00
|
|
|
if (read_num > 0 && i > read_num)
|
2012-08-24 20:28:59 +02:00
|
|
|
break;
|
2013-08-07 22:36:26 +02:00
|
|
|
|
|
|
|
ParsedInternalKey ikey;
|
|
|
|
if (!ParseInternalKey(key, &ikey)) {
|
|
|
|
std::cerr << "Internal Key ["
|
|
|
|
<< key.ToString(true /* in hex*/)
|
|
|
|
<< "] parse error!\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If end marker was specified, we stop before it
|
|
|
|
if (has_to && BytewiseComparator()->Compare(ikey.user_key, to_key) >= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-24 20:28:59 +02:00
|
|
|
if (print_kv) {
|
2014-01-27 21:45:08 +01:00
|
|
|
fprintf(stdout, "%s => %s\n",
|
|
|
|
ikey.DebugString(output_hex_).c_str(),
|
|
|
|
value.ToString(output_hex_).c_str());
|
2012-08-24 20:28:59 +02:00
|
|
|
}
|
2014-01-27 21:45:08 +01:00
|
|
|
}
|
2013-08-07 22:36:26 +02:00
|
|
|
|
2014-01-27 21:45:08 +01:00
|
|
|
read_num_ += i;
|
|
|
|
|
|
|
|
Status ret = iter->status();
|
|
|
|
delete iter;
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-24 20:28:59 +02:00
|
|
|
|
2014-02-08 04:26:49 +01:00
|
|
|
Status SstFileReader::ReadTableProperties(
|
|
|
|
std::shared_ptr<const TableProperties>* table_properties) {
|
2014-01-27 21:45:08 +01:00
|
|
|
if (!table_reader_) {
|
|
|
|
return init_result_;
|
|
|
|
}
|
2012-08-24 20:28:59 +02:00
|
|
|
|
2014-01-27 21:45:08 +01:00
|
|
|
*table_properties = table_reader_->GetTableProperties();
|
|
|
|
return init_result_;
|
2012-08-24 20:28:59 +02:00
|
|
|
}
|
|
|
|
|
2014-01-27 21:45:08 +01:00
|
|
|
} // namespace rocksdb
|
2012-08-24 20:28:59 +02:00
|
|
|
|
|
|
|
static void print_help() {
|
|
|
|
fprintf(stderr,
|
2014-06-07 02:17:12 +02:00
|
|
|
"sst_dump [--command=check|scan|none] [--verify_checksum] "
|
|
|
|
"--file=data_dir_OR_sst_file"
|
|
|
|
" [--output_hex]"
|
|
|
|
" [--input_key_hex]"
|
|
|
|
" [--from=<user_key>]"
|
|
|
|
" [--to=<user_key>]"
|
|
|
|
" [--read_num=NUM]"
|
|
|
|
" [--show_properties]\n");
|
2012-08-24 20:28:59 +02:00
|
|
|
}
|
|
|
|
|
2014-04-10 06:17:14 +02:00
|
|
|
namespace {
|
2013-08-07 22:36:26 +02:00
|
|
|
string HexToString(const string& str) {
|
|
|
|
string parsed;
|
|
|
|
if (str[0] != '0' || str[1] != 'x') {
|
|
|
|
fprintf(stderr, "Invalid hex input %s. Must start with 0x\n",
|
|
|
|
str.c_str());
|
|
|
|
throw "Invalid hex input";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 2; i < str.length();) {
|
|
|
|
int c;
|
|
|
|
sscanf(str.c_str() + i, "%2X", &c);
|
|
|
|
parsed.push_back(c);
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
return parsed;
|
|
|
|
}
|
2014-04-10 06:17:14 +02:00
|
|
|
} // namespace
|
2013-08-07 22:36:26 +02:00
|
|
|
|
2012-08-24 20:28:59 +02:00
|
|
|
int main(int argc, char** argv) {
|
2013-03-21 18:45:57 +01:00
|
|
|
const char* dir_or_file = nullptr;
|
2012-08-24 20:28:59 +02:00
|
|
|
uint64_t read_num = -1;
|
|
|
|
std::string command;
|
|
|
|
|
|
|
|
char junk;
|
|
|
|
uint64_t n;
|
2012-08-25 01:28:06 +02:00
|
|
|
bool verify_checksum = false;
|
2012-12-21 08:49:32 +01:00
|
|
|
bool output_hex = false;
|
2013-08-07 22:36:26 +02:00
|
|
|
bool input_key_hex = false;
|
|
|
|
bool has_from = false;
|
|
|
|
bool has_to = false;
|
2014-01-27 21:45:08 +01:00
|
|
|
bool show_properties = false;
|
2013-08-07 22:36:26 +02:00
|
|
|
std::string from_key;
|
|
|
|
std::string to_key;
|
2014-01-27 21:45:08 +01:00
|
|
|
for (int i = 1; i < argc; i++) {
|
2012-08-24 20:28:59 +02:00
|
|
|
if (strncmp(argv[i], "--file=", 7) == 0) {
|
|
|
|
dir_or_file = argv[i] + 7;
|
2012-12-26 02:33:15 +01:00
|
|
|
} else if (strcmp(argv[i], "--output_hex") == 0) {
|
2012-12-21 08:49:32 +01:00
|
|
|
output_hex = true;
|
2013-08-07 22:36:26 +02:00
|
|
|
} else if (strcmp(argv[i], "--input_key_hex") == 0) {
|
|
|
|
input_key_hex = true;
|
2013-11-13 06:15:49 +01:00
|
|
|
} else if (sscanf(argv[i],
|
|
|
|
"--read_num=%lu%c",
|
|
|
|
(unsigned long*)&n, &junk) == 1) {
|
2012-08-24 20:28:59 +02:00
|
|
|
read_num = n;
|
2012-12-26 02:33:15 +01:00
|
|
|
} else if (strcmp(argv[i], "--verify_checksum") == 0) {
|
2012-08-25 01:28:06 +02:00
|
|
|
verify_checksum = true;
|
2012-08-24 20:28:59 +02:00
|
|
|
} else if (strncmp(argv[i], "--command=", 10) == 0) {
|
|
|
|
command = argv[i] + 10;
|
2013-08-07 22:36:26 +02:00
|
|
|
} else if (strncmp(argv[i], "--from=", 7) == 0) {
|
|
|
|
from_key = argv[i] + 7;
|
|
|
|
has_from = true;
|
|
|
|
} else if (strncmp(argv[i], "--to=", 5) == 0) {
|
|
|
|
to_key = argv[i] + 5;
|
|
|
|
has_to = true;
|
2014-01-27 21:45:08 +01:00
|
|
|
} else if (strcmp(argv[i], "--show_properties") == 0) {
|
|
|
|
show_properties = true;
|
|
|
|
} else {
|
2012-08-24 20:28:59 +02:00
|
|
|
print_help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-07 22:36:26 +02:00
|
|
|
if (input_key_hex) {
|
|
|
|
if (has_from) {
|
|
|
|
from_key = HexToString(from_key);
|
|
|
|
}
|
|
|
|
if (has_to) {
|
|
|
|
to_key = HexToString(to_key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 21:45:08 +01:00
|
|
|
if (dir_or_file == nullptr) {
|
2012-08-24 20:28:59 +02:00
|
|
|
print_help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> filenames;
|
2013-10-04 06:49:15 +02:00
|
|
|
rocksdb::Env* env = rocksdb::Env::Default();
|
|
|
|
rocksdb::Status st = env->GetChildren(dir_or_file, &filenames);
|
2012-08-24 20:28:59 +02:00
|
|
|
bool dir = true;
|
|
|
|
if (!st.ok()) {
|
|
|
|
filenames.clear();
|
|
|
|
filenames.push_back(dir_or_file);
|
|
|
|
dir = false;
|
|
|
|
}
|
|
|
|
|
2014-01-27 21:45:08 +01:00
|
|
|
fprintf(stdout, "from [%s] to [%s]\n",
|
|
|
|
rocksdb::Slice(from_key).ToString(true).c_str(),
|
|
|
|
rocksdb::Slice(to_key).ToString(true).c_str());
|
2013-08-07 22:36:26 +02:00
|
|
|
|
2012-08-29 21:29:43 +02:00
|
|
|
uint64_t total_read = 0;
|
|
|
|
for (size_t i = 0; i < filenames.size(); i++) {
|
2012-08-24 20:28:59 +02:00
|
|
|
std::string filename = filenames.at(i);
|
|
|
|
if (filename.length() <= 4 ||
|
|
|
|
filename.rfind(".sst") != filename.length() - 4) {
|
2014-01-27 21:45:08 +01:00
|
|
|
// ignore
|
2012-08-24 20:28:59 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-01-27 21:45:08 +01:00
|
|
|
if (dir) {
|
2013-08-07 22:36:26 +02:00
|
|
|
filename = std::string(dir_or_file) + "/" + filename;
|
2012-08-24 20:28:59 +02:00
|
|
|
}
|
2013-10-04 06:49:15 +02:00
|
|
|
rocksdb::SstFileReader reader(filename, verify_checksum,
|
2012-12-21 08:49:32 +01:00
|
|
|
output_hex);
|
2013-10-04 06:49:15 +02:00
|
|
|
rocksdb::Status st;
|
2012-08-24 20:28:59 +02:00
|
|
|
// scan all files in give file path.
|
|
|
|
if (command == "" || command == "scan" || command == "check") {
|
2012-08-25 01:28:06 +02:00
|
|
|
st = reader.ReadSequential(command != "check",
|
2013-08-07 22:36:26 +02:00
|
|
|
read_num > 0 ? (read_num - total_read) :
|
|
|
|
read_num,
|
|
|
|
has_from, from_key, has_to, to_key);
|
2012-08-24 20:28:59 +02:00
|
|
|
if (!st.ok()) {
|
|
|
|
fprintf(stderr, "%s: %s\n", filename.c_str(),
|
|
|
|
st.ToString().c_str());
|
|
|
|
}
|
|
|
|
total_read += reader.GetReadNumber();
|
2012-08-25 01:28:06 +02:00
|
|
|
if (read_num > 0 && total_read > read_num) {
|
2012-08-24 20:28:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-27 21:45:08 +01:00
|
|
|
if (show_properties) {
|
2014-06-07 02:17:12 +02:00
|
|
|
const rocksdb::TableProperties* table_properties;
|
|
|
|
|
|
|
|
std::shared_ptr<const rocksdb::TableProperties>
|
|
|
|
table_properties_from_reader;
|
|
|
|
st = reader.ReadTableProperties(&table_properties_from_reader);
|
2014-01-27 21:45:08 +01:00
|
|
|
if (!st.ok()) {
|
|
|
|
fprintf(stderr, "%s: %s\n", filename.c_str(), st.ToString().c_str());
|
2014-06-07 02:17:12 +02:00
|
|
|
fprintf(stderr, "Try to use initial table properties\n");
|
|
|
|
table_properties = reader.GetInitTableProperties();
|
2014-01-27 21:45:08 +01:00
|
|
|
} else {
|
2014-06-07 02:17:12 +02:00
|
|
|
table_properties = table_properties_from_reader.get();
|
|
|
|
}
|
|
|
|
if (table_properties != nullptr) {
|
2014-01-27 21:45:08 +01:00
|
|
|
fprintf(stdout,
|
2014-02-08 04:26:49 +01:00
|
|
|
"Table Properties:\n"
|
|
|
|
"------------------------------\n"
|
|
|
|
" %s",
|
|
|
|
table_properties->ToString("\n ", ": ").c_str());
|
2014-01-31 02:18:17 +01:00
|
|
|
fprintf(stdout, "# deleted keys: %zd\n",
|
|
|
|
rocksdb::GetDeletedKeys(
|
2014-02-08 04:26:49 +01:00
|
|
|
table_properties->user_collected_properties));
|
2014-01-27 21:45:08 +01:00
|
|
|
}
|
|
|
|
}
|
2012-08-24 20:28:59 +02:00
|
|
|
}
|
|
|
|
}
|