/src/rocksdb/options/options_helper.h
Line | Count | Source |
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 | | #pragma once |
7 | | |
8 | | #include <map> |
9 | | #include <stdexcept> |
10 | | #include <string> |
11 | | #include <vector> |
12 | | |
13 | | #include "rocksdb/advanced_options.h" |
14 | | #include "rocksdb/compaction_filter.h" |
15 | | #include "rocksdb/options.h" |
16 | | #include "rocksdb/status.h" |
17 | | #include "rocksdb/table.h" |
18 | | |
19 | | namespace ROCKSDB_NAMESPACE { |
20 | | struct ColumnFamilyOptions; |
21 | | struct ConfigOptions; |
22 | | struct DBOptions; |
23 | | struct ImmutableCFOptions; |
24 | | struct ImmutableDBOptions; |
25 | | struct MutableDBOptions; |
26 | | struct MutableCFOptions; |
27 | | struct Options; |
28 | | |
29 | | const std::vector<CompressionType>& GetSupportedCompressions(); |
30 | | |
31 | | const std::vector<CompressionType>& GetSupportedDictCompressions(); |
32 | | |
33 | | const std::vector<ChecksumType>& GetSupportedChecksums(); |
34 | | |
35 | 86.5k | inline bool IsSupportedChecksumType(ChecksumType type) { |
36 | | // Avoid annoying compiler warning-as-error (-Werror=type-limits) |
37 | 86.5k | auto min = kNoChecksum; |
38 | 86.5k | auto max = kXXH3; |
39 | 86.5k | return type >= min && type <= max; |
40 | 86.5k | } |
41 | | |
42 | | // Returns true if read_options has an active table filter, i.e. a non-null |
43 | | // pointer to a non-empty std::function. A null pointer, or a pointer to an |
44 | | // empty std::function, means no filtering. |
45 | 72.8k | inline bool HasTableFilter(const ReadOptions& read_options) { |
46 | 72.8k | return read_options.table_filter != nullptr && *read_options.table_filter; |
47 | 72.8k | } |
48 | | |
49 | | // How an iterator created with `read_options` uses the prefix extractor, with |
50 | | // the precedence prefix_same_as_start > auto_prefix_mode > total_order_seek > |
51 | | // implicit prefix seek. DBIter uses it so that it never assumes its inner |
52 | | // iterator is in total order while a child iterator may filter by prefix. |
53 | | // Some layers (the MergingIterator prefix flag, LevelIterator prefix |
54 | | // exhaustion, the SST auto_prefix_mode upper bound check and the hash index) |
55 | | // keep their own conditions. |
56 | | enum class IteratorPrefixMode { |
57 | | // No prefix seek. The iterator returns all keys in order. |
58 | | kTotalOrder, |
59 | | // auto_prefix_mode: results as in total order. Prefix filters are only used |
60 | | // where iterate_upper_bound shows that a seek stays within one prefix. |
61 | | kAuto, |
62 | | // Prefix seek. Child iterators may skip keys outside the seek key's prefix |
63 | | // (prefix filters, prefix indexes), so only keys within that prefix are |
64 | | // reliable. |
65 | | kPrefix, |
66 | | }; |
67 | | |
68 | | // prefix_same_as_start and auto_prefix_mode are explicit requests and take |
69 | | // precedence over total_order_seek. total_order_seek only turns off the |
70 | | // implicit prefix seek of iterators with default ReadOptions (and is forced on |
71 | | // by DBOptions::prefix_seek_opt_in_only). |
72 | | inline IteratorPrefixMode GetIteratorPrefixMode(const ReadOptions& read_options, |
73 | 65.7k | bool has_prefix_extractor) { |
74 | 65.7k | if (!has_prefix_extractor) { |
75 | 65.7k | return IteratorPrefixMode::kTotalOrder; |
76 | 65.7k | } |
77 | 0 | if (read_options.prefix_same_as_start) { |
78 | 0 | return IteratorPrefixMode::kPrefix; |
79 | 0 | } |
80 | 0 | if (read_options.auto_prefix_mode) { |
81 | 0 | return IteratorPrefixMode::kAuto; |
82 | 0 | } |
83 | 0 | if (read_options.total_order_seek) { |
84 | 0 | return IteratorPrefixMode::kTotalOrder; |
85 | 0 | } |
86 | 0 | return IteratorPrefixMode::kPrefix; |
87 | 0 | } |
88 | | |
89 | | // Checks that the combination of DBOptions and ColumnFamilyOptions are valid |
90 | | Status ValidateOptions(const DBOptions& db_opts, |
91 | | const ColumnFamilyOptions& cf_opts); |
92 | | |
93 | | // Configuration queries: callers must not hold the DB mutex. |
94 | | Status GetCompactionFilterMergeOrder(const CompactionFilter* filter, |
95 | | const CompactionFilterFactory* factory, |
96 | | TableFileCreationReason reason, |
97 | | CompactionFilter::MergeOrder* order); |
98 | | Status ValidateCompactionFilterOptions(const ColumnFamilyOptions& cf_opts); |
99 | | // Whether the direct filter or the factory declares merge-before-filter. |
100 | | bool DeclaresMergeBeforeFilter(const ColumnFamilyOptions& cf_opts); |
101 | | Status MergeBeforeFilterTransactionError(); |
102 | | |
103 | | DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options, |
104 | | const MutableDBOptions& mutable_db_options); |
105 | | // Overwrites `options` |
106 | | void BuildDBOptions(const ImmutableDBOptions& immutable_db_options, |
107 | | const MutableDBOptions& mutable_db_options, |
108 | | DBOptions& options); |
109 | | |
110 | | ColumnFamilyOptions BuildColumnFamilyOptions( |
111 | | const ColumnFamilyOptions& ioptions, |
112 | | const MutableCFOptions& mutable_cf_options); |
113 | | |
114 | | void UpdateColumnFamilyOptions(const ImmutableCFOptions& ioptions, |
115 | | ColumnFamilyOptions* cf_opts); |
116 | | void UpdateColumnFamilyOptions(const MutableCFOptions& moptions, |
117 | | ColumnFamilyOptions* cf_opts); |
118 | | |
119 | | std::unique_ptr<Configurable> DBOptionsAsConfigurable( |
120 | | const MutableDBOptions& opts); |
121 | | std::unique_ptr<Configurable> DBOptionsAsConfigurable( |
122 | | const DBOptions& opts, |
123 | | const std::unordered_map<std::string, std::string>* opt_map = nullptr); |
124 | | std::unique_ptr<Configurable> CFOptionsAsConfigurable( |
125 | | const MutableCFOptions& opts); |
126 | | std::unique_ptr<Configurable> CFOptionsAsConfigurable( |
127 | | const ColumnFamilyOptions& opts, |
128 | | const std::unordered_map<std::string, std::string>* opt_map = nullptr); |
129 | | |
130 | | Status StringToMap(const std::string& opts_str, |
131 | | std::unordered_map<std::string, std::string>* opts_map); |
132 | | |
133 | | Status GetStringFromCompressionType(std::string* compression_str, |
134 | | CompressionType compression_type); |
135 | | |
136 | | struct OptionsHelper { |
137 | | static const std::string kCFOptionsName /*= "ColumnFamilyOptions"*/; |
138 | | static const std::string kDBOptionsName /*= "DBOptions" */; |
139 | | static std::map<CompactionStyle, std::string> compaction_style_to_string; |
140 | | static std::map<CompactionPri, std::string> compaction_pri_to_string; |
141 | | static std::map<CompactionStopStyle, std::string> |
142 | | compaction_stop_style_to_string; |
143 | | static std::map<Temperature, std::string> temperature_to_string; |
144 | | static std::unordered_map<std::string, ChecksumType> checksum_type_string_map; |
145 | | static std::unordered_map<std::string, CompressionType> |
146 | | compression_type_string_map; |
147 | | static std::unordered_map<std::string, PrepopulateBlobCache> |
148 | | prepopulate_blob_cache_string_map; |
149 | | static std::unordered_map<std::string, CompactionStopStyle> |
150 | | compaction_stop_style_string_map; |
151 | | static std::unordered_map<std::string, EncodingType> encoding_type_string_map; |
152 | | static std::unordered_map<std::string, CompactionStyle> |
153 | | compaction_style_string_map; |
154 | | static std::unordered_map<std::string, CompactionPri> |
155 | | compaction_pri_string_map; |
156 | | static std::unordered_map<std::string, Temperature> temperature_string_map; |
157 | | }; |
158 | | |
159 | | // Some aliasing |
160 | | static auto& compaction_style_to_string = |
161 | | OptionsHelper::compaction_style_to_string; |
162 | | static auto& compaction_pri_to_string = OptionsHelper::compaction_pri_to_string; |
163 | | static auto& compaction_stop_style_to_string = |
164 | | OptionsHelper::compaction_stop_style_to_string; |
165 | | static auto& temperature_to_string = OptionsHelper::temperature_to_string; |
166 | | static auto& checksum_type_string_map = OptionsHelper::checksum_type_string_map; |
167 | | static auto& compaction_stop_style_string_map = |
168 | | OptionsHelper::compaction_stop_style_string_map; |
169 | | static auto& compression_type_string_map = |
170 | | OptionsHelper::compression_type_string_map; |
171 | | static auto& encoding_type_string_map = OptionsHelper::encoding_type_string_map; |
172 | | static auto& compaction_style_string_map = |
173 | | OptionsHelper::compaction_style_string_map; |
174 | | static auto& compaction_pri_string_map = |
175 | | OptionsHelper::compaction_pri_string_map; |
176 | | static auto& temperature_string_map = OptionsHelper::temperature_string_map; |
177 | | static auto& prepopulate_blob_cache_string_map = |
178 | | OptionsHelper::prepopulate_blob_cache_string_map; |
179 | | |
180 | | } // namespace ROCKSDB_NAMESPACE |