Skip to content

Commit

Permalink
Fix bloom filter compatibility issue caused by naming (#365)
Browse files Browse the repository at this point in the history
* Fix bloom filter compatibility issue caused by namings

Signed-off-by: Yang Zhang <[email protected]>
  • Loading branch information
v01dstar authored Jul 25, 2024
1 parent 45509f0 commit 3fe3ffa
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions table/block_based/block_based_table_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ extern const uint64_t kBlockBasedTableMagicNumber;
extern const std::string kHashIndexPrefixesBlock;
extern const std::string kHashIndexPrefixesMetadataBlock;

BlockBasedTable::~BlockBasedTable() {
delete rep_;
}
BlockBasedTable::~BlockBasedTable() { delete rep_; }

namespace {
// Read the block identified by "handle" from "file".
Expand Down Expand Up @@ -900,29 +898,36 @@ Status BlockBasedTable::PrefetchIndexAndFilterBlocks(

// Find filter handle and filter type
if (rep_->filter_policy) {
for (auto filter_type :
{Rep::FilterType::kFullFilter, Rep::FilterType::kPartitionedFilter,
Rep::FilterType::kBlockFilter}) {
std::string prefix;
switch (filter_type) {
case Rep::FilterType::kFullFilter:
prefix = kFullFilterBlockPrefix;
break;
case Rep::FilterType::kPartitionedFilter:
prefix = kPartitionedFilterBlockPrefix;
break;
case Rep::FilterType::kBlockFilter:
prefix = kFilterBlockPrefix;
break;
default:
assert(0);
}
std::string filter_block_key = prefix;
filter_block_key.append(rep_->filter_policy->Name());
if (FindMetaBlock(meta_iter, filter_block_key, &rep_->filter_handle)
.ok()) {
rep_->filter_type = filter_type;
break;
for (const auto& pair :
{std::make_pair(Rep::FilterType::kFullFilter, kFullFilterBlockPrefix),
std::make_pair(Rep::FilterType::kPartitionedFilter,
kPartitionedFilterBlockPrefix),
std::make_pair(Rep::FilterType::kBlockFilter, kFilterBlockPrefix)}) {
auto filter_type = pair.first;
Slice prefix = pair.second;
meta_iter->Seek(prefix);
if (meta_iter->status().ok() && meta_iter->Valid()) {
Slice key = meta_iter->key();
if (key.starts_with(prefix)) {
key.remove_prefix(prefix.size());
Slice filter_policy_name_slice = Slice(rep_->filter_policy->Name());
// This is a temporary fix to handle the case where the filter
// policy name changes after the filter block is written.
// It was rocksdb.BuiltinBloomFilter and after TiKV 7.2 it is
// rocksdb.BuiltinBloomFilter.XXX where XXX is the built-in filter
// policy name, like FullBloom, Ribbon etc. Since TiKV only uses
// built-in filter policies, and built-in filter policies can be
// used interchangeably, we can just compare the prefix of the filter.
if (key.starts_with("rocksdb.BuiltinBloomFilter") ||
key.compare(filter_policy_name_slice) == 0) {
Slice v = meta_iter->value();
s = rep_->filter_handle.DecodeFrom(&v);
if (s.ok()) {
rep_->filter_type = filter_type;
break;
}
}
}
}
}
}
Expand Down

0 comments on commit 3fe3ffa

Please sign in to comment.