Fix two bugs in talbe format

Summary:
Previous code had two bugs:

* didn't initialize the table_magic_number_ explicitly -- as a
  result a random junk number is stored for table_magic_number_, making
  HasInitializedMagicNumber() always return true.
* if condition is inconrrect in set_table_magic_number(), and the return value is not checked.
  I replace if-else by a stronger requirement enforced by assert().

Test Plan:
Previous sst_dump failed to work.
After the fix, things back to normal.

Reviewers: yhchiang

CC: haobo, sdong, igor, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D17055
main
Kai Liu 11 years ago
parent e493f2f54e
commit 69f6cf431d
  1. 12
      table/format.h

@ -112,14 +112,10 @@ class Footer {
static const uint64_t kInvalidTableMagicNumber = 0; static const uint64_t kInvalidTableMagicNumber = 0;
private: private:
// Set the table_magic_number only when it was not previously // REQUIRES: magic number wasn't initialized.
// initialized. Return true on success. void set_table_magic_number(uint64_t magic_number) {
bool set_table_magic_number(uint64_t magic_number) { assert(!HasInitializedTableMagicNumber());
if (HasInitializedTableMagicNumber()) {
table_magic_number_ = magic_number; table_magic_number_ = magic_number;
return true;
}
return false;
} }
// return true if @table_magic_number_ is set to a value different // return true if @table_magic_number_ is set to a value different
@ -130,7 +126,7 @@ class Footer {
BlockHandle metaindex_handle_; BlockHandle metaindex_handle_;
BlockHandle index_handle_; BlockHandle index_handle_;
uint64_t table_magic_number_; uint64_t table_magic_number_ = 0;
}; };
// Read the footer from file // Read the footer from file

Loading…
Cancel
Save