Fixed Factory construct just for calling .Name() (#7080)

Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/7080

Reviewed By: riversand963

Differential Revision: D22412352

Pulled By: ajkr

fbshipit-source-id: 1d7f4c1621040a0130245139b52c3f4d3deac865
main
rockeet 5 years ago committed by Facebook GitHub Bot
parent 226d1f9c73
commit b649d8cb97
  1. 6
      db/column_family.cc
  2. 4
      options/options_helper.cc
  3. 1
      table/plain/plain_table_factory.cc
  4. 4
      table/plain/plain_table_factory.h
  5. 2
      utilities/options/options_util.cc
  6. 2
      utilities/options/options_util_test.cc

@ -347,7 +347,7 @@ ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options,
} }
bool is_block_based_table = bool is_block_based_table =
(result.table_factory->Name() == BlockBasedTableFactory().Name()); (result.table_factory->Name() == BlockBasedTableFactory::kName);
const uint64_t kAdjustedTtl = 30 * 24 * 60 * 60; const uint64_t kAdjustedTtl = 30 * 24 * 60 * 60;
if (result.ttl == kDefaultTtl) { if (result.ttl == kDefaultTtl) {
@ -1300,7 +1300,7 @@ Status ColumnFamilyData::ValidateOptions(
} }
if (cf_options.ttl > 0 && cf_options.ttl != kDefaultTtl) { if (cf_options.ttl > 0 && cf_options.ttl != kDefaultTtl) {
if (cf_options.table_factory->Name() != BlockBasedTableFactory().Name()) { if (cf_options.table_factory->Name() != BlockBasedTableFactory::kName) {
return Status::NotSupported( return Status::NotSupported(
"TTL is only supported in Block-Based Table format. "); "TTL is only supported in Block-Based Table format. ");
} }
@ -1308,7 +1308,7 @@ Status ColumnFamilyData::ValidateOptions(
if (cf_options.periodic_compaction_seconds > 0 && if (cf_options.periodic_compaction_seconds > 0 &&
cf_options.periodic_compaction_seconds != kDefaultPeriodicCompSecs) { cf_options.periodic_compaction_seconds != kDefaultPeriodicCompSecs) {
if (cf_options.table_factory->Name() != BlockBasedTableFactory().Name()) { if (cf_options.table_factory->Name() != BlockBasedTableFactory::kName) {
return Status::NotSupported( return Status::NotSupported(
"Periodic Compaction is only supported in " "Periodic Compaction is only supported in "
"Block-Based Table format. "); "Block-Based Table format. ");

@ -930,7 +930,7 @@ Status GetTableFactoryFromMap(
const std::unordered_map<std::string, std::string>& opt_map, const std::unordered_map<std::string, std::string>& opt_map,
std::shared_ptr<TableFactory>* table_factory) { std::shared_ptr<TableFactory>* table_factory) {
Status s; Status s;
if (factory_name == BlockBasedTableFactory().Name()) { if (factory_name == BlockBasedTableFactory::kName) {
BlockBasedTableOptions bbt_opt; BlockBasedTableOptions bbt_opt;
s = GetBlockBasedTableOptionsFromMap( s = GetBlockBasedTableOptionsFromMap(
config_options, BlockBasedTableOptions(), opt_map, &bbt_opt); config_options, BlockBasedTableOptions(), opt_map, &bbt_opt);
@ -939,7 +939,7 @@ Status GetTableFactoryFromMap(
} }
table_factory->reset(new BlockBasedTableFactory(bbt_opt)); table_factory->reset(new BlockBasedTableFactory(bbt_opt));
return s; return s;
} else if (factory_name == PlainTableFactory().Name()) { } else if (factory_name == PlainTableFactory::kName) {
PlainTableOptions pt_opt; PlainTableOptions pt_opt;
s = GetPlainTableOptionsFromMap(config_options, PlainTableOptions(), s = GetPlainTableOptionsFromMap(config_options, PlainTableOptions(),
opt_map, &pt_opt); opt_map, &pt_opt);

@ -274,6 +274,7 @@ extern TableFactory* NewPlainTableFactory(const PlainTableOptions& options) {
return new PlainTableFactory(options); return new PlainTableFactory(options);
} }
const std::string PlainTableFactory::kName = "PlainTable";
const std::string PlainTablePropertyNames::kEncodingType = const std::string PlainTablePropertyNames::kEncodingType =
"rocksdb.plain.table.encoding.type"; "rocksdb.plain.table.encoding.type";

@ -159,7 +159,7 @@ class PlainTableFactory : public TableFactory {
const PlainTableOptions& _table_options = PlainTableOptions()) const PlainTableOptions& _table_options = PlainTableOptions())
: table_options_(_table_options) {} : table_options_(_table_options) {}
const char* Name() const override { return "PlainTable"; } const char* Name() const override { return kName.c_str(); }
using TableFactory::NewTableReader; using TableFactory::NewTableReader;
Status NewTableReader(const ReadOptions& ro, Status NewTableReader(const ReadOptions& ro,
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
@ -191,6 +191,8 @@ class PlainTableFactory : public TableFactory {
return Status::OK(); return Status::OK();
} }
static const std::string kName;
private: private:
PlainTableOptions table_options_; PlainTableOptions table_options_;
}; };

@ -48,7 +48,7 @@ Status LoadOptionsFromFile(const ConfigOptions& config_options,
if (cache != nullptr) { if (cache != nullptr) {
TableFactory* tf = cf_opts[i].table_factory.get(); TableFactory* tf = cf_opts[i].table_factory.get();
if (tf != nullptr && tf->GetOptions() != nullptr && if (tf != nullptr && tf->GetOptions() != nullptr &&
tf->Name() == BlockBasedTableFactory().Name()) { tf->Name() == BlockBasedTableFactory::kName) {
auto* loaded_bbt_opt = auto* loaded_bbt_opt =
reinterpret_cast<BlockBasedTableOptions*>(tf->GetOptions()); reinterpret_cast<BlockBasedTableOptions*>(tf->GetOptions());
loaded_bbt_opt->block_cache = *cache; loaded_bbt_opt->block_cache = *cache;

@ -44,7 +44,7 @@ class OptionsUtilTest : public testing::Test {
}; };
bool IsBlockBasedTableFactory(TableFactory* tf) { bool IsBlockBasedTableFactory(TableFactory* tf) {
return tf->Name() == BlockBasedTableFactory().Name(); return tf->Name() == BlockBasedTableFactory::kName;
} }
TEST_F(OptionsUtilTest, SaveAndLoad) { TEST_F(OptionsUtilTest, SaveAndLoad) {

Loading…
Cancel
Save