Change order of parameters in adaptive table factory

Summary:
This is minor, but if we put the writing talbe factory as the third parameter, when we add a new table format, we'll have a situation:
1) block based factory
2) plain table factory
3) output factory
4) new format factory

I think it makes more sense to have output as the first parameter.

Also, fixed a NewAdaptiveTableFactory() call in unit test

Test Plan: unit test

Reviewers: sdong

Reviewed By: sdong

Subscribers: leveldb

Differential Revision: https://reviews.facebook.net/D19119
main
Igor Canadi 11 years ago
parent 8c265c08f1
commit 3525aac9e5
  1. 6
      db/plain_table_db_test.cc
  2. 6
      include/rocksdb/table.h
  3. 22
      table/adaptive_table_factory.cc
  4. 6
      table/adaptive_table_factory.h

@ -862,8 +862,10 @@ TEST(PlainTableDBTest, AdaptiveTable) {
options.create_if_missing = false; options.create_if_missing = false;
std::shared_ptr<TableFactory> dummy_factory; std::shared_ptr<TableFactory> dummy_factory;
options.table_factory.reset( std::shared_ptr<TableFactory> block_based_factory(
NewAdaptiveTableFactory(dummy_factory, dummy_factory, false)); NewBlockBasedTableFactory());
options.table_factory.reset(NewAdaptiveTableFactory(
block_based_factory, dummy_factory, dummy_factory));
Reopen(&options); Reopen(&options);
ASSERT_EQ("v3", Get("1000000000000foo")); ASSERT_EQ("v3", Get("1000000000000foo"));
ASSERT_EQ("v2", Get("0000000000000bar")); ASSERT_EQ("v2", Get("0000000000000bar"));

@ -207,14 +207,14 @@ class TableFactory {
// Create a special table factory that can open both of block based table format // Create a special table factory that can open both of block based table format
// and plain table, based on setting inside the SST files. It should be used to // and plain table, based on setting inside the SST files. It should be used to
// convert a DB from one table format to another. // convert a DB from one table format to another.
// @table_factory_to_write: the table factory used when writing to new files.
// @block_based_table_factory: block based table factory to use. If NULL, use // @block_based_table_factory: block based table factory to use. If NULL, use
// a default one. // a default one.
// @plain_table_factory: plain table factory to use. If NULL, use a default one. // @plain_table_factory: plain table factory to use. If NULL, use a default one.
// @table_factory_to_write: the table factory used when writing to new files.
extern TableFactory* NewAdaptiveTableFactory( extern TableFactory* NewAdaptiveTableFactory(
std::shared_ptr<TableFactory> table_factory_to_write = nullptr,
std::shared_ptr<TableFactory> block_based_table_factory = nullptr, std::shared_ptr<TableFactory> block_based_table_factory = nullptr,
std::shared_ptr<TableFactory> plain_table_factory = nullptr, std::shared_ptr<TableFactory> plain_table_factory = nullptr);
std::shared_ptr<TableFactory> table_factory_to_write = nullptr);
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE

@ -10,21 +10,21 @@
namespace rocksdb { namespace rocksdb {
AdaptiveTableFactory::AdaptiveTableFactory( AdaptiveTableFactory::AdaptiveTableFactory(
std::shared_ptr<TableFactory> table_factory_to_write,
std::shared_ptr<TableFactory> block_based_table_factory, std::shared_ptr<TableFactory> block_based_table_factory,
std::shared_ptr<TableFactory> plain_table_factory, std::shared_ptr<TableFactory> plain_table_factory)
std::shared_ptr<TableFactory> table_factory_to_write) : table_factory_to_write_(table_factory_to_write),
: block_based_table_factory_(block_based_table_factory), block_based_table_factory_(block_based_table_factory),
plain_table_factory_(plain_table_factory), plain_table_factory_(plain_table_factory) {
table_factory_to_write_(table_factory_to_write) { if (!table_factory_to_write_) {
table_factory_to_write_ = block_based_table_factory_;
}
if (!plain_table_factory_) { if (!plain_table_factory_) {
plain_table_factory_.reset(NewPlainTableFactory()); plain_table_factory_.reset(NewPlainTableFactory());
} }
if (!block_based_table_factory_) { if (!block_based_table_factory_) {
block_based_table_factory_.reset(NewBlockBasedTableFactory()); block_based_table_factory_.reset(NewBlockBasedTableFactory());
} }
if (!table_factory_to_write_) {
table_factory_to_write_ = block_based_table_factory_;
}
} }
extern const uint64_t kPlainTableMagicNumber; extern const uint64_t kPlainTableMagicNumber;
@ -62,11 +62,11 @@ TableBuilder* AdaptiveTableFactory::NewTableBuilder(
} }
extern TableFactory* NewAdaptiveTableFactory( extern TableFactory* NewAdaptiveTableFactory(
std::shared_ptr<TableFactory> table_factory_to_write,
std::shared_ptr<TableFactory> block_based_table_factory, std::shared_ptr<TableFactory> block_based_table_factory,
std::shared_ptr<TableFactory> plain_table_factory, std::shared_ptr<TableFactory> plain_table_factory) {
std::shared_ptr<TableFactory> table_factory_to_write) {
return new AdaptiveTableFactory( return new AdaptiveTableFactory(
block_based_table_factory, plain_table_factory, table_factory_to_write); table_factory_to_write, block_based_table_factory, plain_table_factory);
} }
} // namespace rocksdb } // namespace rocksdb

@ -26,9 +26,9 @@ class AdaptiveTableFactory : public TableFactory {
~AdaptiveTableFactory() {} ~AdaptiveTableFactory() {}
explicit AdaptiveTableFactory( explicit AdaptiveTableFactory(
std::shared_ptr<TableFactory> table_factory_to_write,
std::shared_ptr<TableFactory> block_based_table_factory, std::shared_ptr<TableFactory> block_based_table_factory,
std::shared_ptr<TableFactory> plain_table_factory, std::shared_ptr<TableFactory> plain_table_factory);
std::shared_ptr<TableFactory> table_factory_to_write);
const char* Name() const override { return "AdaptiveTableFactory"; } const char* Name() const override { return "AdaptiveTableFactory"; }
Status NewTableReader(const Options& options, const EnvOptions& soptions, Status NewTableReader(const Options& options, const EnvOptions& soptions,
const InternalKeyComparator& internal_comparator, const InternalKeyComparator& internal_comparator,
@ -41,9 +41,9 @@ class AdaptiveTableFactory : public TableFactory {
override; override;
private: private:
std::shared_ptr<TableFactory> table_factory_to_write_;
std::shared_ptr<TableFactory> block_based_table_factory_; std::shared_ptr<TableFactory> block_based_table_factory_;
std::shared_ptr<TableFactory> plain_table_factory_; std::shared_ptr<TableFactory> plain_table_factory_;
std::shared_ptr<TableFactory> table_factory_to_write_;
}; };
} // namespace rocksdb } // namespace rocksdb

Loading…
Cancel
Save