Skip to content

Commit

Permalink
Fix FilterPolicy Serialization and test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykorean committed Nov 15, 2024
1 parent ee8dd79 commit f2b0514
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
22 changes: 21 additions & 1 deletion db/db_bloom_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "rocksdb/perf_context.h"
#include "rocksdb/statistics.h"
#include "rocksdb/table.h"
#include "rocksdb/utilities/object_registry.h"
#include "table/block_based/block_based_table_reader.h"
#include "table/block_based/filter_policy_internal.h"
#include "table/format.h"
Expand Down Expand Up @@ -1839,7 +1840,26 @@ class TestingContextCustomFilterPolicy
} // anonymous namespace

TEST_F(DBBloomFilterTest, ContextCustomFilterPolicy) {
auto policy = std::make_shared<TestingContextCustomFilterPolicy>(15, 8, 5);
int bpk_fifo = 15;
int bpk_l0_other = 8;
int bpk_otherwise = 5;
auto policy = std::make_shared<TestingContextCustomFilterPolicy>(
bpk_fifo, bpk_l0_other, bpk_otherwise);

// Little hack to make PersistRocksDBOptions work
ObjectRegistry::Default()
->AddLibrary("db_bloom_filter_test")
->AddFactory<FilterPolicy>(
policy->Name(),
[&bpk_fifo, &bpk_l0_other, &bpk_otherwise](
const std::string& /*uri*/, std::unique_ptr<FilterPolicy>* guard,
std::string* /* errmsg */) {
std::unordered_map<std::string, std::string> map;
guard->reset(new LevelAndStyleCustomFilterPolicy(
bpk_fifo, bpk_l0_other, bpk_otherwise));
return guard->get();
});

Options options;
for (bool fifo : {true, false}) {
options = CurrentOptions();
Expand Down
38 changes: 29 additions & 9 deletions options/cf_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ static Status TableFactoryParseFn(const ConfigOptions& opts,
return s;
}

static bool TableFactoryEqualsFn(const ConfigOptions& opts,
const std::string& /*name*/, const void* addr1,
const void* addr2, std::string* mismatch) {
auto table_factory1 =
static_cast<const std::shared_ptr<TableFactory>*>(addr1);
auto table_factory2 =
static_cast<const std::shared_ptr<TableFactory>*>(addr2);
return table_factory1->get()->AreEquivalent(opts, table_factory2->get(),
mismatch);
}

const std::string kOptNameBMCompOpts = "bottommost_compression_opts";
const std::string kOptNameCompOpts = "compression_opts";

Expand Down Expand Up @@ -355,23 +366,32 @@ static std::unordered_map<std::string, OptionTypeInfo>
OptionTypeFlags::kMutable}},
{"table_factory",
{offsetof(struct MutableCFOptions, table_factory),
OptionType::kCustomizable, OptionVerificationType::kByName,
OptionTypeFlags::kShared | OptionTypeFlags::kCompareLoose |
OptionType::kCustomizable,
OptionVerificationType::kByName,
OptionTypeFlags::kShared | OptionTypeFlags::kCompareDefault |
OptionTypeFlags::kStringNameOnly | OptionTypeFlags::kDontPrepare |
OptionTypeFlags::kMutable,
TableFactoryParseFn}},
TableFactoryParseFn,
{} /* SerializeFn */,
TableFactoryEqualsFn}},
{"block_based_table_factory",
{offsetof(struct MutableCFOptions, table_factory),
OptionType::kCustomizable, OptionVerificationType::kAlias,
OptionTypeFlags::kShared | OptionTypeFlags::kCompareLoose |
OptionType::kCustomizable,
OptionVerificationType::kAlias,
OptionTypeFlags::kShared | OptionTypeFlags::kCompareDefault |
OptionTypeFlags::kMutable,
TableFactoryParseFn}},
TableFactoryParseFn,
{} /* SerializeFn */,
TableFactoryEqualsFn}},
{"plain_table_factory",
{offsetof(struct MutableCFOptions, table_factory),
OptionType::kCustomizable, OptionVerificationType::kAlias,
OptionTypeFlags::kShared | OptionTypeFlags::kCompareLoose |
OptionType::kCustomizable,
OptionVerificationType::kAlias,
OptionTypeFlags::kShared | OptionTypeFlags::kCompareDefault |
OptionTypeFlags::kMutable,
TableFactoryParseFn}},
TableFactoryParseFn,
{} /* SerializeFn */,
TableFactoryEqualsFn}},
{"filter_deletes",
{0, OptionType::kBoolean, OptionVerificationType::kDeprecated,
OptionTypeFlags::kMutable}},
Expand Down
2 changes: 1 addition & 1 deletion table/block_based/block_based_table_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ static struct BlockBasedTableTypeInfo {
{"filter_policy",
OptionTypeInfo::AsCustomSharedPtr<const FilterPolicy>(
offsetof(struct BlockBasedTableOptions, filter_policy),
OptionVerificationType::kByNameAllowFromNull)},
OptionVerificationType::kByName, OptionTypeFlags::kAllowNull)},
{"whole_key_filtering",
{offsetof(struct BlockBasedTableOptions, whole_key_filtering),
OptionType::kBoolean, OptionVerificationType::kNormal}},
Expand Down

0 comments on commit f2b0514

Please sign in to comment.