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
This commit is contained in:
rockeet 2020-07-08 11:52:13 -07:00 committed by Facebook GitHub Bot
parent 226d1f9c73
commit b649d8cb97
6 changed files with 11 additions and 8 deletions

View File

@ -347,7 +347,7 @@ ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options,
}
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;
if (result.ttl == kDefaultTtl) {
@ -1300,7 +1300,7 @@ Status ColumnFamilyData::ValidateOptions(
}
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(
"TTL is only supported in Block-Based Table format. ");
}
@ -1308,7 +1308,7 @@ Status ColumnFamilyData::ValidateOptions(
if (cf_options.periodic_compaction_seconds > 0 &&
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(
"Periodic Compaction is only supported in "
"Block-Based Table format. ");

View File

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

View File

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

View File

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

View File

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

View File

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