diff --git a/table/block_based/block_based_table_reader.cc b/table/block_based/block_based_table_reader.cc index 099064e373b..e66023d60f3 100644 --- a/table/block_based/block_based_table_reader.cc +++ b/table/block_based/block_based_table_reader.cc @@ -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". @@ -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; + } + } + } } } }