1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 2 // This source code is licensed under both the GPLv2 (found in the 3 // COPYING file in the root directory) and Apache 2.0 License 4 // (found in the LICENSE.Apache file in the root directory). 5 // 6 7 #pragma once 8 9 #include <cassert> 10 #include "table/block_based/cachable_entry.h" 11 #include "table/block_based/filter_block.h" 12 13 namespace ROCKSDB_NAMESPACE { 14 15 class BlockBasedTable; 16 class FilePrefetchBuffer; 17 18 // Encapsulates common functionality for the various filter block reader 19 // implementations. Provides access to the filter block regardless of whether 20 // it is owned by the reader or stored in the cache, or whether it is pinned 21 // in the cache or not. 22 template <typename TBlocklike> 23 class FilterBlockReaderCommon : public FilterBlockReader { 24 public: FilterBlockReaderCommon(const BlockBasedTable * t,CachableEntry<TBlocklike> && filter_block)25 FilterBlockReaderCommon(const BlockBasedTable* t, 26 CachableEntry<TBlocklike>&& filter_block) 27 : table_(t), filter_block_(std::move(filter_block)) { 28 assert(table_); 29 } 30 31 protected: 32 static Status ReadFilterBlock(const BlockBasedTable* table, 33 FilePrefetchBuffer* prefetch_buffer, 34 const ReadOptions& read_options, bool use_cache, 35 GetContext* get_context, 36 BlockCacheLookupContext* lookup_context, 37 CachableEntry<TBlocklike>* filter_block); 38 table()39 const BlockBasedTable* table() const { return table_; } 40 const SliceTransform* table_prefix_extractor() const; 41 bool whole_key_filtering() const; 42 bool cache_filter_blocks() const; 43 44 Status GetOrReadFilterBlock(bool no_io, GetContext* get_context, 45 BlockCacheLookupContext* lookup_context, 46 CachableEntry<TBlocklike>* filter_block) const; 47 48 size_t ApproximateFilterBlockMemoryUsage() const; 49 50 private: 51 const BlockBasedTable* table_; 52 CachableEntry<TBlocklike> filter_block_; 53 }; 54 55 } // namespace ROCKSDB_NAMESPACE 56