Fix sst_dump for PlainTable

Summary: sst_dump now doesn't work well for PlainTable. Not sure when it started, but this should fix it.

Test Plan: Run sst_dump against a file that used to fail.

Reviewers: yhchiang, haobo, igor

Reviewed By: igor

Subscribers: dhruba, ljin, leveldb

Differential Revision: https://reviews.facebook.net/D19023
This commit is contained in:
sdong 2014-06-12 10:54:57 -07:00
parent c83b085770
commit 9202d9b625

View File

@ -82,7 +82,9 @@ SstFileReader::SstFileReader(const std::string& file_path,
}
extern uint64_t kBlockBasedTableMagicNumber;
extern uint64_t kLegacyBlockBasedTableMagicNumber;
extern uint64_t kPlainTableMagicNumber;
extern uint64_t kLegacyPlainTableMagicNumber;
Status SstFileReader::NewTableReader(const std::string& file_path) {
uint64_t magic_number;
@ -104,8 +106,10 @@ Status SstFileReader::NewTableReader(const std::string& file_path) {
}
if (s.ok()) {
if (magic_number == kPlainTableMagicNumber) {
if (magic_number == kPlainTableMagicNumber ||
magic_number == kLegacyPlainTableMagicNumber) {
soptions_.use_mmap_reads = true;
options_.env->NewRandomAccessFile(file_path, &file_, soptions_);
}
options_.comparator = &internal_comparator_;
s = ReadTableProperties(magic_number, file_.get(), file_size);
@ -136,7 +140,8 @@ Status SstFileReader::ReadTableProperties(uint64_t table_magic_number,
Status SstFileReader::SetTableOptionsByMagicNumber(
uint64_t table_magic_number) {
assert(table_properties_);
if (table_magic_number == kBlockBasedTableMagicNumber) {
if (table_magic_number == kBlockBasedTableMagicNumber ||
table_magic_number == kLegacyBlockBasedTableMagicNumber) {
options_.table_factory = std::make_shared<BlockBasedTableFactory>();
fprintf(stdout, "Sst file format: block-based\n");
auto& props = table_properties_->user_collected_properties;
@ -149,7 +154,8 @@ Status SstFileReader::SetTableOptionsByMagicNumber(
options_.prefix_extractor.reset(NewNoopTransform());
}
}
} else if (table_magic_number == kPlainTableMagicNumber) {
} else if (table_magic_number == kPlainTableMagicNumber ||
table_magic_number == kLegacyPlainTableMagicNumber) {
options_.allow_mmap_reads = true;
options_.table_factory = std::make_shared<PlainTableFactory>(
table_properties_->fixed_key_len, 2, 0.8);