Generalize footer reading from file

Summary:

Generalizing this process will help us to re-use the code for plain table

Test Plan:

ran ./table_test
This commit is contained in:
Kai Liu
2013-12-04 16:35:48 -08:00
parent 5dec7acd91
commit 219b35be6a
4 changed files with 36 additions and 22 deletions

View File

@@ -29,7 +29,7 @@
namespace rocksdb {
extern uint64_t kBlockedBasedTableMagicNumber;
extern uint64_t kBlockBasedTableMagicNumber;
// The longest the prefix of the cache key used to identify blocks can be.
// We are using the fact that we know for Posix files the unique ID is three
@@ -228,24 +228,9 @@ Status BlockBasedTable::Open(const Options& options,
uint64_t size,
unique_ptr<TableReader>* table_reader) {
table_reader->reset();
if (size < Footer::kEncodedLength) {
return Status::InvalidArgument("file is too short to be an sstable");
}
char footer_space[Footer::kEncodedLength];
Slice footer_input;
Status s = file->Read(size - Footer::kEncodedLength, Footer::kEncodedLength,
&footer_input, footer_space);
if (!s.ok()) return s;
// Check that we actually read the whole footer from the file. It may be
// that size isn't correct.
if (footer_input.size() != Footer::kEncodedLength) {
return Status::InvalidArgument("file is too short to be an sstable");
}
Footer footer(kBlockedBasedTableMagicNumber);
s = footer.DecodeFrom(&footer_input);
Footer footer(kBlockBasedTableMagicNumber);
auto s = ReadFooterFromFile(file.get(), size, &footer);
if (!s.ok()) return s;
// We've successfully read the footer and the index block: we're