]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
5 | |
6 | #pragma once | |
7 | ||
8 | #include <map> | |
9 | #include <stdexcept> | |
10 | #include <string> | |
11 | #include <vector> | |
12 | ||
13 | #include "options/cf_options.h" | |
14 | #include "options/db_options.h" | |
15 | #include "rocksdb/options.h" | |
16 | #include "rocksdb/status.h" | |
17 | #include "rocksdb/table.h" | |
11fdf7f2 | 18 | #include "rocksdb/universal_compaction.h" |
7c673cae FG |
19 | |
20 | namespace rocksdb { | |
21 | ||
22 | DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options, | |
23 | const MutableDBOptions& mutable_db_options); | |
24 | ||
25 | ColumnFamilyOptions BuildColumnFamilyOptions( | |
26 | const ColumnFamilyOptions& ioptions, | |
27 | const MutableCFOptions& mutable_cf_options); | |
28 | ||
7c673cae FG |
29 | #ifndef ROCKSDB_LITE |
30 | ||
31 | Status GetMutableOptionsFromStrings( | |
32 | const MutableCFOptions& base_options, | |
33 | const std::unordered_map<std::string, std::string>& options_map, | |
11fdf7f2 | 34 | Logger* info_log, MutableCFOptions* new_options); |
7c673cae FG |
35 | |
36 | Status GetMutableDBOptionsFromStrings( | |
37 | const MutableDBOptions& base_options, | |
38 | const std::unordered_map<std::string, std::string>& options_map, | |
39 | MutableDBOptions* new_options); | |
40 | ||
41 | Status GetTableFactoryFromMap( | |
42 | const std::string& factory_name, | |
43 | const std::unordered_map<std::string, std::string>& opt_map, | |
11fdf7f2 TL |
44 | std::shared_ptr<TableFactory>* table_factory, |
45 | bool ignore_unknown_options = false); | |
7c673cae FG |
46 | |
47 | enum class OptionType { | |
48 | kBoolean, | |
49 | kInt, | |
494da23a TL |
50 | kInt32T, |
51 | kInt64T, | |
7c673cae FG |
52 | kVectorInt, |
53 | kUInt, | |
54 | kUInt32T, | |
55 | kUInt64T, | |
56 | kSizeT, | |
57 | kString, | |
58 | kDouble, | |
59 | kCompactionStyle, | |
60 | kCompactionPri, | |
61 | kSliceTransform, | |
62 | kCompressionType, | |
63 | kVectorCompressionType, | |
64 | kTableFactory, | |
65 | kComparator, | |
66 | kCompactionFilter, | |
67 | kCompactionFilterFactory, | |
11fdf7f2 TL |
68 | kCompactionOptionsFIFO, |
69 | kCompactionOptionsUniversal, | |
70 | kCompactionStopStyle, | |
7c673cae FG |
71 | kMergeOperator, |
72 | kMemTableRepFactory, | |
73 | kBlockBasedTableIndexType, | |
11fdf7f2 | 74 | kBlockBasedTableDataBlockIndexType, |
7c673cae FG |
75 | kFilterPolicy, |
76 | kFlushBlockPolicyFactory, | |
77 | kChecksumType, | |
78 | kEncodingType, | |
79 | kWALRecoveryMode, | |
80 | kAccessHint, | |
81 | kInfoLogLevel, | |
11fdf7f2 | 82 | kLRUCacheOptions, |
7c673cae FG |
83 | kUnknown |
84 | }; | |
85 | ||
86 | enum class OptionVerificationType { | |
87 | kNormal, | |
11fdf7f2 TL |
88 | kByName, // The option is pointer typed so we can only verify |
89 | // based on it's name. | |
90 | kByNameAllowNull, // Same as kByName, but it also allows the case | |
91 | // where one of them is a nullptr. | |
92 | kByNameAllowFromNull, // Same as kByName, but it also allows the case | |
93 | // where the old option is nullptr. | |
94 | kDeprecated // The option is no longer used in rocksdb. The RocksDB | |
95 | // OptionsParser will still accept this option if it | |
96 | // happen to exists in some Options file. However, | |
97 | // the parser will not include it in serialization | |
98 | // and verification processes. | |
7c673cae FG |
99 | }; |
100 | ||
101 | // A struct for storing constant option information such as option name, | |
102 | // option type, and offset. | |
103 | struct OptionTypeInfo { | |
104 | int offset; | |
105 | OptionType type; | |
106 | OptionVerificationType verification; | |
107 | bool is_mutable; | |
108 | int mutable_offset; | |
109 | }; | |
110 | ||
111 | // A helper function that converts "opt_address" to a std::string | |
112 | // based on the specified OptionType. | |
113 | bool SerializeSingleOptionHelper(const char* opt_address, | |
114 | const OptionType opt_type, std::string* value); | |
115 | ||
116 | // In addition to its public version defined in rocksdb/convenience.h, | |
117 | // this further takes an optional output vector "unsupported_options_names", | |
118 | // which stores the name of all the unsupported options specified in "opts_map". | |
119 | Status GetDBOptionsFromMapInternal( | |
120 | const DBOptions& base_options, | |
121 | const std::unordered_map<std::string, std::string>& opts_map, | |
122 | DBOptions* new_options, bool input_strings_escaped, | |
11fdf7f2 TL |
123 | std::vector<std::string>* unsupported_options_names = nullptr, |
124 | bool ignore_unknown_options = false); | |
7c673cae FG |
125 | |
126 | // In addition to its public version defined in rocksdb/convenience.h, | |
127 | // this further takes an optional output vector "unsupported_options_names", | |
128 | // which stores the name of all the unsupported options specified in "opts_map". | |
129 | Status GetColumnFamilyOptionsFromMapInternal( | |
130 | const ColumnFamilyOptions& base_options, | |
131 | const std::unordered_map<std::string, std::string>& opts_map, | |
132 | ColumnFamilyOptions* new_options, bool input_strings_escaped, | |
11fdf7f2 TL |
133 | std::vector<std::string>* unsupported_options_names = nullptr, |
134 | bool ignore_unknown_options = false); | |
7c673cae | 135 | |
11fdf7f2 TL |
136 | bool ParseSliceTransform( |
137 | const std::string& value, | |
138 | std::shared_ptr<const SliceTransform>* slice_transform); | |
7c673cae | 139 | |
11fdf7f2 TL |
140 | extern Status StringToMap( |
141 | const std::string& opts_str, | |
142 | std::unordered_map<std::string, std::string>* opts_map); | |
7c673cae | 143 | |
11fdf7f2 TL |
144 | extern bool ParseOptionHelper(char* opt_address, const OptionType& opt_type, |
145 | const std::string& value); | |
146 | #endif // !ROCKSDB_LITE | |
7c673cae | 147 | |
11fdf7f2 TL |
148 | struct OptionsHelper { |
149 | static std::map<CompactionStyle, std::string> compaction_style_to_string; | |
150 | static std::map<CompactionPri, std::string> compaction_pri_to_string; | |
151 | static std::map<CompactionStopStyle, std::string> | |
152 | compaction_stop_style_to_string; | |
153 | static std::unordered_map<std::string, ChecksumType> checksum_type_string_map; | |
154 | static std::unordered_map<std::string, CompressionType> | |
155 | compression_type_string_map; | |
156 | #ifndef ROCKSDB_LITE | |
157 | static std::unordered_map<std::string, OptionTypeInfo> cf_options_type_info; | |
158 | static std::unordered_map<std::string, OptionTypeInfo> | |
159 | fifo_compaction_options_type_info; | |
160 | static std::unordered_map<std::string, OptionTypeInfo> | |
161 | universal_compaction_options_type_info; | |
162 | static std::unordered_map<std::string, CompactionStopStyle> | |
163 | compaction_stop_style_string_map; | |
164 | static std::unordered_map<std::string, OptionTypeInfo> db_options_type_info; | |
165 | static std::unordered_map<std::string, OptionTypeInfo> | |
166 | lru_cache_options_type_info; | |
167 | static std::unordered_map<std::string, BlockBasedTableOptions::IndexType> | |
168 | block_base_table_index_type_string_map; | |
169 | static std::unordered_map<std::string, | |
170 | BlockBasedTableOptions::DataBlockIndexType> | |
171 | block_base_table_data_block_index_type_string_map; | |
172 | static std::unordered_map<std::string, EncodingType> encoding_type_string_map; | |
173 | static std::unordered_map<std::string, CompactionStyle> | |
174 | compaction_style_string_map; | |
175 | static std::unordered_map<std::string, CompactionPri> | |
176 | compaction_pri_string_map; | |
177 | static std::unordered_map<std::string, WALRecoveryMode> | |
178 | wal_recovery_mode_string_map; | |
179 | static std::unordered_map<std::string, DBOptions::AccessHint> | |
180 | access_hint_string_map; | |
181 | static std::unordered_map<std::string, InfoLogLevel> | |
182 | info_log_level_string_map; | |
183 | static ColumnFamilyOptions dummy_cf_options; | |
184 | static CompactionOptionsFIFO dummy_comp_options; | |
185 | static LRUCacheOptions dummy_lru_cache_options; | |
186 | static CompactionOptionsUniversal dummy_comp_options_universal; | |
187 | #endif // !ROCKSDB_LITE | |
188 | }; | |
7c673cae | 189 | |
11fdf7f2 TL |
190 | // Some aliasing |
191 | static auto& compaction_style_to_string = | |
192 | OptionsHelper::compaction_style_to_string; | |
193 | static auto& compaction_pri_to_string = OptionsHelper::compaction_pri_to_string; | |
194 | static auto& compaction_stop_style_to_string = | |
195 | OptionsHelper::compaction_stop_style_to_string; | |
196 | static auto& checksum_type_string_map = OptionsHelper::checksum_type_string_map; | |
197 | #ifndef ROCKSDB_LITE | |
198 | static auto& cf_options_type_info = OptionsHelper::cf_options_type_info; | |
199 | static auto& fifo_compaction_options_type_info = | |
200 | OptionsHelper::fifo_compaction_options_type_info; | |
201 | static auto& universal_compaction_options_type_info = | |
202 | OptionsHelper::universal_compaction_options_type_info; | |
203 | static auto& compaction_stop_style_string_map = | |
204 | OptionsHelper::compaction_stop_style_string_map; | |
205 | static auto& db_options_type_info = OptionsHelper::db_options_type_info; | |
206 | static auto& lru_cache_options_type_info = | |
207 | OptionsHelper::lru_cache_options_type_info; | |
208 | static auto& compression_type_string_map = | |
209 | OptionsHelper::compression_type_string_map; | |
210 | static auto& block_base_table_index_type_string_map = | |
211 | OptionsHelper::block_base_table_index_type_string_map; | |
212 | static auto& block_base_table_data_block_index_type_string_map = | |
213 | OptionsHelper::block_base_table_data_block_index_type_string_map; | |
214 | static auto& encoding_type_string_map = OptionsHelper::encoding_type_string_map; | |
215 | static auto& compaction_style_string_map = | |
216 | OptionsHelper::compaction_style_string_map; | |
217 | static auto& compaction_pri_string_map = | |
218 | OptionsHelper::compaction_pri_string_map; | |
219 | static auto& wal_recovery_mode_string_map = | |
220 | OptionsHelper::wal_recovery_mode_string_map; | |
221 | static auto& access_hint_string_map = OptionsHelper::access_hint_string_map; | |
222 | static auto& info_log_level_string_map = | |
223 | OptionsHelper::info_log_level_string_map; | |
7c673cae FG |
224 | #endif // !ROCKSDB_LITE |
225 | ||
226 | } // namespace rocksdb |