Skip to content

Commit 69f6cf4

Browse files
author
Kai Liu
committed
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
1 parent e493f2f commit 69f6cf4

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

table/format.h

+5-9
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,10 @@ class Footer {
112112
static const uint64_t kInvalidTableMagicNumber = 0;
113113

114114
private:
115-
// Set the table_magic_number only when it was not previously
116-
// initialized. Return true on success.
117-
bool set_table_magic_number(uint64_t magic_number) {
118-
if (HasInitializedTableMagicNumber()) {
119-
table_magic_number_ = magic_number;
120-
return true;
121-
}
122-
return false;
115+
// REQUIRES: magic number wasn't initialized.
116+
void set_table_magic_number(uint64_t magic_number) {
117+
assert(!HasInitializedTableMagicNumber());
118+
table_magic_number_ = magic_number;
123119
}
124120

125121
// return true if @table_magic_number_ is set to a value different
@@ -130,7 +126,7 @@ class Footer {
130126

131127
BlockHandle metaindex_handle_;
132128
BlockHandle index_handle_;
133-
uint64_t table_magic_number_;
129+
uint64_t table_magic_number_ = 0;
134130
};
135131

136132
// Read the footer from file

0 commit comments

Comments
 (0)