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/format.h"
12 
13 namespace ROCKSDB_NAMESPACE {
14 
15 class BlockBasedTable;
16 struct BlockCacheLookupContext;
17 class FilePrefetchBuffer;
18 class GetContext;
19 struct ReadOptions;
20 struct UncompressionDict;
21 
22 // Provides access to the uncompression dictionary regardless of whether
23 // it is owned by the reader or stored in the cache, or whether it is pinned
24 // in the cache or not.
25 class UncompressionDictReader {
26  public:
27   static Status Create(
28       const BlockBasedTable* table, FilePrefetchBuffer* prefetch_buffer,
29       bool use_cache, bool prefetch, bool pin,
30       BlockCacheLookupContext* lookup_context,
31       std::unique_ptr<UncompressionDictReader>* uncompression_dict_reader);
32 
33   Status GetOrReadUncompressionDictionary(
34       FilePrefetchBuffer* prefetch_buffer, bool no_io, GetContext* get_context,
35       BlockCacheLookupContext* lookup_context,
36       CachableEntry<UncompressionDict>* uncompression_dict) const;
37 
38   size_t ApproximateMemoryUsage() const;
39 
40  private:
UncompressionDictReader(const BlockBasedTable * t,CachableEntry<UncompressionDict> && uncompression_dict)41   UncompressionDictReader(const BlockBasedTable* t,
42                           CachableEntry<UncompressionDict>&& uncompression_dict)
43       : table_(t), uncompression_dict_(std::move(uncompression_dict)) {
44     assert(table_);
45   }
46 
47   bool cache_dictionary_blocks() const;
48 
49   static Status ReadUncompressionDictionary(
50       const BlockBasedTable* table, FilePrefetchBuffer* prefetch_buffer,
51       const ReadOptions& read_options, bool use_cache, GetContext* get_context,
52       BlockCacheLookupContext* lookup_context,
53       CachableEntry<UncompressionDict>* uncompression_dict);
54 
55   const BlockBasedTable* table_;
56   CachableEntry<UncompressionDict> uncompression_dict_;
57 };
58 
59 }  // namespace ROCKSDB_NAMESPACE
60