Parameterize table magic number

Summary:

As we are having different types of tables and they all might share the same structure in block-based table:

[metaindex block]
[index block]
[Footer]

To be able to identify differnt types of tables, we need to parameterize the "magic number" in the `Footer`.

Test Plan:

make check
main
Kai Liu 11 years ago
parent f040e536e4
commit 3a0e98d558
  1. 10
      table/block_based_table_builder.cc
  2. 1
      table/block_based_table_builder.h
  3. 4
      table/block_based_table_reader.cc
  4. 13
      table/format.h

@ -77,6 +77,14 @@ void LogPropertiesCollectionError(
} // anonymous namespace } // anonymous namespace
// kBlockedBasedTableMagicNumber was picked by running
// echo http://code.google.com/p/leveldb/ | sha1sum
// and taking the leading 64 bits.
// Please note that kBlockedBasedTableMagicNumber may also be accessed by
// other .cc files so it have to be explicitly declared with "extern".
extern const uint64_t kBlockedBasedTableMagicNumber
= 0xdb4775248b80fb57ull;
struct BlockBasedTableBuilder::Rep { struct BlockBasedTableBuilder::Rep {
Options options; Options options;
WritableFile* file; WritableFile* file;
@ -503,7 +511,7 @@ Status BlockBasedTableBuilder::Finish() {
// Write footer // Write footer
if (ok()) { if (ok()) {
Footer footer; Footer footer(kBlockedBasedTableMagicNumber);
footer.set_metaindex_handle(metaindex_block_handle); footer.set_metaindex_handle(metaindex_block_handle);
footer.set_index_handle(index_block_handle); footer.set_index_handle(index_block_handle);
std::string footer_encoding; std::string footer_encoding;

@ -20,7 +20,6 @@ class BlockBuilder;
class BlockHandle; class BlockHandle;
class WritableFile; class WritableFile;
class BlockBasedTableBuilder : public TableBuilder { class BlockBasedTableBuilder : public TableBuilder {
public: public:
// Create a builder that will store the contents of the table it is // Create a builder that will store the contents of the table it is

@ -29,6 +29,8 @@
namespace rocksdb { namespace rocksdb {
extern uint64_t kBlockedBasedTableMagicNumber;
// The longest the prefix of the cache key used to identify blocks can be. // 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 // We are using the fact that we know for Posix files the unique ID is three
// varints. // varints.
@ -242,7 +244,7 @@ Status BlockBasedTable::Open(const Options& options,
return Status::InvalidArgument("file is too short to be an sstable"); return Status::InvalidArgument("file is too short to be an sstable");
} }
Footer footer; Footer footer(kBlockedBasedTableMagicNumber);
s = footer.DecodeFrom(&footer_input); s = footer.DecodeFrom(&footer_input);
if (!s.ok()) return s; if (!s.ok()) return s;

@ -50,7 +50,12 @@ class BlockHandle {
// end of every table file. // end of every table file.
class Footer { class Footer {
public: public:
Footer() { } // @table_magic_number serves two purposes:
// 1. Identify different types of the tables.
// 2. Help us to identify if a given file is a valid sst.
Footer(uint64_t table_magic_number) :
kTableMagicNumber(table_magic_number) {
}
// The block handle for the metaindex block of the table // The block handle for the metaindex block of the table
const BlockHandle& metaindex_handle() const { return metaindex_handle_; } const BlockHandle& metaindex_handle() const { return metaindex_handle_; }
@ -77,13 +82,9 @@ class Footer {
private: private:
BlockHandle metaindex_handle_; BlockHandle metaindex_handle_;
BlockHandle index_handle_; BlockHandle index_handle_;
const uint64_t kTableMagicNumber;
}; };
// kTableMagicNumber was picked by running
// echo http://code.google.com/p/leveldb/ | sha1sum
// and taking the leading 64 bits.
static const uint64_t kTableMagicNumber = 0xdb4775248b80fb57ull;
// 1-byte type + 32-bit crc // 1-byte type + 32-bit crc
static const size_t kBlockTrailerSize = 5; static const size_t kBlockTrailerSize = 5;

Loading…
Cancel
Save