mirror of https://github.com/facebook/rocksdb.git
fix_sst_dump_for_old_sst_format
Summary: 1. fix segment error when dumping old sst format (no properties nor stats) 2. Enable dumpping old sst format Test Plan: Generate block based sst file with "properties", and one with "stats" and one without neither. Read it using sst_dump Reviewers: ljin, igor, yhchiang, dhruba, sdong Reviewed By: sdong Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D21837
This commit is contained in:
parent
58c49466d2
commit
6c4c159b2c
|
@ -54,6 +54,7 @@ class SstFileReader {
|
|||
Status ReadTableProperties(uint64_t table_magic_number,
|
||||
RandomAccessFile* file, uint64_t file_size);
|
||||
Status SetTableOptionsByMagicNumber(uint64_t table_magic_number);
|
||||
Status SetOldTableOptions();
|
||||
|
||||
std::string file_name_;
|
||||
uint64_t read_num_;
|
||||
|
@ -112,9 +113,11 @@ Status SstFileReader::NewTableReader(const std::string& file_path) {
|
|||
options_.env->NewRandomAccessFile(file_path, &file_, soptions_);
|
||||
}
|
||||
options_.comparator = &internal_comparator_;
|
||||
s = ReadTableProperties(magic_number, file_.get(), file_size);
|
||||
if (s.ok()) {
|
||||
s = SetTableOptionsByMagicNumber(magic_number);
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,11 +132,15 @@ Status SstFileReader::NewTableReader(const std::string& file_path) {
|
|||
Status SstFileReader::ReadTableProperties(uint64_t table_magic_number,
|
||||
RandomAccessFile* file,
|
||||
uint64_t file_size) {
|
||||
TableProperties* table_properties;
|
||||
TableProperties* table_properties = nullptr;
|
||||
Status s = rocksdb::ReadTableProperties(file, file_size, table_magic_number,
|
||||
options_.env, options_.info_log.get(),
|
||||
&table_properties);
|
||||
table_properties_.reset(table_properties);
|
||||
if (s.ok()) {
|
||||
table_properties_.reset(table_properties);
|
||||
} else {
|
||||
fprintf(stdout, "Not able to read table properties\n");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -180,6 +187,14 @@ Status SstFileReader::SetTableOptionsByMagicNumber(
|
|||
return Status::OK();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Status SstFileReader::ReadSequential(bool print_kv,
|
||||
uint64_t read_num,
|
||||
bool has_from,
|
||||
|
|
Loading…
Reference in New Issue