/src/rocksdb/table/block_based/uncompression_dict_reader.cc
Line | Count | Source (jump to first uncovered line) |
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 | | #include "table/block_based/uncompression_dict_reader.h" |
8 | | |
9 | | #include "logging/logging.h" |
10 | | #include "monitoring/perf_context_imp.h" |
11 | | #include "table/block_based/block_based_table_reader.h" |
12 | | #include "util/compression.h" |
13 | | |
14 | | namespace ROCKSDB_NAMESPACE { |
15 | | |
16 | | Status UncompressionDictReader::Create( |
17 | | const BlockBasedTable* table, const ReadOptions& ro, |
18 | | FilePrefetchBuffer* prefetch_buffer, bool use_cache, bool prefetch, |
19 | | bool pin, BlockCacheLookupContext* lookup_context, |
20 | 0 | std::unique_ptr<UncompressionDictReader>* uncompression_dict_reader) { |
21 | 0 | assert(table); |
22 | 0 | assert(table->get_rep()); |
23 | 0 | assert(!pin || prefetch); |
24 | 0 | assert(uncompression_dict_reader); |
25 | |
|
26 | 0 | CachableEntry<UncompressionDict> uncompression_dict; |
27 | 0 | if (prefetch || !use_cache) { |
28 | 0 | const Status s = ReadUncompressionDictionary( |
29 | 0 | table, prefetch_buffer, ro, use_cache, nullptr /* get_context */, |
30 | 0 | lookup_context, &uncompression_dict); |
31 | 0 | if (!s.ok()) { |
32 | 0 | return s; |
33 | 0 | } |
34 | | |
35 | 0 | if (use_cache && !pin) { |
36 | 0 | uncompression_dict.Reset(); |
37 | 0 | } |
38 | 0 | } |
39 | | |
40 | 0 | uncompression_dict_reader->reset( |
41 | 0 | new UncompressionDictReader(table, std::move(uncompression_dict))); |
42 | |
|
43 | 0 | return Status::OK(); |
44 | 0 | } |
45 | | |
46 | | Status UncompressionDictReader::ReadUncompressionDictionary( |
47 | | const BlockBasedTable* table, FilePrefetchBuffer* prefetch_buffer, |
48 | | const ReadOptions& read_options, bool use_cache, GetContext* get_context, |
49 | | BlockCacheLookupContext* lookup_context, |
50 | 0 | CachableEntry<UncompressionDict>* uncompression_dict) { |
51 | | // TODO: add perf counter for compression dictionary read time |
52 | |
|
53 | 0 | assert(table); |
54 | 0 | assert(uncompression_dict); |
55 | 0 | assert(uncompression_dict->IsEmpty()); |
56 | |
|
57 | 0 | const BlockBasedTable::Rep* const rep = table->get_rep(); |
58 | 0 | assert(rep); |
59 | 0 | assert(!rep->compression_dict_handle.IsNull()); |
60 | |
|
61 | 0 | const Status s = table->RetrieveBlock( |
62 | 0 | prefetch_buffer, read_options, rep->compression_dict_handle, |
63 | 0 | UncompressionDict::GetEmptyDict(), uncompression_dict, get_context, |
64 | 0 | lookup_context, |
65 | 0 | /* for_compaction */ false, use_cache, |
66 | 0 | /* async_read */ false, /* use_block_cache_for_lookup */ true); |
67 | |
|
68 | 0 | if (!s.ok()) { |
69 | 0 | ROCKS_LOG_WARN( |
70 | 0 | rep->ioptions.logger, |
71 | 0 | "Encountered error while reading data from compression dictionary " |
72 | 0 | "block %s", |
73 | 0 | s.ToString().c_str()); |
74 | 0 | } |
75 | |
|
76 | 0 | return s; |
77 | 0 | } |
78 | | |
79 | | Status UncompressionDictReader::GetOrReadUncompressionDictionary( |
80 | | FilePrefetchBuffer* prefetch_buffer, const ReadOptions& ro, |
81 | | GetContext* get_context, BlockCacheLookupContext* lookup_context, |
82 | 0 | CachableEntry<UncompressionDict>* uncompression_dict) const { |
83 | 0 | assert(uncompression_dict); |
84 | |
|
85 | 0 | if (!uncompression_dict_.IsEmpty()) { |
86 | 0 | uncompression_dict->SetUnownedValue(uncompression_dict_.GetValue()); |
87 | 0 | return Status::OK(); |
88 | 0 | } |
89 | | |
90 | 0 | return ReadUncompressionDictionary(table_, prefetch_buffer, ro, |
91 | 0 | cache_dictionary_blocks(), get_context, |
92 | 0 | lookup_context, uncompression_dict); |
93 | 0 | } |
94 | | |
95 | 0 | size_t UncompressionDictReader::ApproximateMemoryUsage() const { |
96 | 0 | assert(!uncompression_dict_.GetOwnValue() || |
97 | 0 | uncompression_dict_.GetValue() != nullptr); |
98 | 0 | size_t usage = uncompression_dict_.GetOwnValue() |
99 | 0 | ? uncompression_dict_.GetValue()->ApproximateMemoryUsage() |
100 | 0 | : 0; |
101 | |
|
102 | 0 | #ifdef ROCKSDB_MALLOC_USABLE_SIZE |
103 | 0 | usage += malloc_usable_size(const_cast<UncompressionDictReader*>(this)); |
104 | | #else |
105 | | usage += sizeof(*this); |
106 | | #endif // ROCKSDB_MALLOC_USABLE_SIZE |
107 | |
|
108 | 0 | return usage; |
109 | 0 | } |
110 | | |
111 | 0 | bool UncompressionDictReader::cache_dictionary_blocks() const { |
112 | 0 | assert(table_); |
113 | 0 | assert(table_->get_rep()); |
114 | |
|
115 | 0 | return table_->get_rep()->table_options.cache_index_and_filter_blocks; |
116 | 0 | } |
117 | | |
118 | | } // namespace ROCKSDB_NAMESPACE |