Skip to content

Commit

Permalink
fix_sst_dump_for_old_sst_format
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Feng Zhu committed Aug 14, 2014
1 parent 58c4946 commit 6c4c159
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions tools/sst_dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6c4c159

Please sign in to comment.