]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/options/options_helper.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / options / options_helper.h
CommitLineData
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 19
f67539c2 20namespace ROCKSDB_NAMESPACE {
7c673cae
FG
21
22DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options,
23 const MutableDBOptions& mutable_db_options);
24
25ColumnFamilyOptions BuildColumnFamilyOptions(
26 const ColumnFamilyOptions& ioptions,
27 const MutableCFOptions& mutable_cf_options);
28
7c673cae
FG
29#ifndef ROCKSDB_LITE
30
31Status 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
36Status GetMutableDBOptionsFromStrings(
37 const MutableDBOptions& base_options,
38 const std::unordered_map<std::string, std::string>& options_map,
39 MutableDBOptions* new_options);
40
41Status 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
47enum 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,
f67539c2 75 kBlockBasedTableIndexShorteningMode,
7c673cae
FG
76 kFilterPolicy,
77 kFlushBlockPolicyFactory,
78 kChecksumType,
79 kEncodingType,
80 kWALRecoveryMode,
81 kAccessHint,
82 kInfoLogLevel,
11fdf7f2 83 kLRUCacheOptions,
f67539c2
TL
84 kEnv,
85 kUnknown,
7c673cae
FG
86};
87
88enum class OptionVerificationType {
89 kNormal,
11fdf7f2
TL
90 kByName, // The option is pointer typed so we can only verify
91 // based on it's name.
92 kByNameAllowNull, // Same as kByName, but it also allows the case
93 // where one of them is a nullptr.
94 kByNameAllowFromNull, // Same as kByName, but it also allows the case
95 // where the old option is nullptr.
96 kDeprecated // The option is no longer used in rocksdb. The RocksDB
97 // OptionsParser will still accept this option if it
98 // happen to exists in some Options file. However,
99 // the parser will not include it in serialization
100 // and verification processes.
7c673cae
FG
101};
102
103// A struct for storing constant option information such as option name,
104// option type, and offset.
105struct OptionTypeInfo {
106 int offset;
107 OptionType type;
108 OptionVerificationType verification;
109 bool is_mutable;
110 int mutable_offset;
111};
112
113// A helper function that converts "opt_address" to a std::string
114// based on the specified OptionType.
115bool SerializeSingleOptionHelper(const char* opt_address,
116 const OptionType opt_type, std::string* value);
117
118// In addition to its public version defined in rocksdb/convenience.h,
119// this further takes an optional output vector "unsupported_options_names",
120// which stores the name of all the unsupported options specified in "opts_map".
121Status GetDBOptionsFromMapInternal(
122 const DBOptions& base_options,
123 const std::unordered_map<std::string, std::string>& opts_map,
124 DBOptions* new_options, bool input_strings_escaped,
11fdf7f2
TL
125 std::vector<std::string>* unsupported_options_names = nullptr,
126 bool ignore_unknown_options = false);
7c673cae
FG
127
128// In addition to its public version defined in rocksdb/convenience.h,
129// this further takes an optional output vector "unsupported_options_names",
130// which stores the name of all the unsupported options specified in "opts_map".
131Status GetColumnFamilyOptionsFromMapInternal(
132 const ColumnFamilyOptions& base_options,
133 const std::unordered_map<std::string, std::string>& opts_map,
134 ColumnFamilyOptions* new_options, bool input_strings_escaped,
11fdf7f2
TL
135 std::vector<std::string>* unsupported_options_names = nullptr,
136 bool ignore_unknown_options = false);
7c673cae 137
11fdf7f2
TL
138bool ParseSliceTransform(
139 const std::string& value,
140 std::shared_ptr<const SliceTransform>* slice_transform);
7c673cae 141
11fdf7f2
TL
142extern Status StringToMap(
143 const std::string& opts_str,
144 std::unordered_map<std::string, std::string>* opts_map);
7c673cae 145
11fdf7f2
TL
146extern bool ParseOptionHelper(char* opt_address, const OptionType& opt_type,
147 const std::string& value);
148#endif // !ROCKSDB_LITE
7c673cae 149
11fdf7f2
TL
150struct OptionsHelper {
151 static std::map<CompactionStyle, std::string> compaction_style_to_string;
152 static std::map<CompactionPri, std::string> compaction_pri_to_string;
153 static std::map<CompactionStopStyle, std::string>
154 compaction_stop_style_to_string;
155 static std::unordered_map<std::string, ChecksumType> checksum_type_string_map;
156 static std::unordered_map<std::string, CompressionType>
157 compression_type_string_map;
158#ifndef ROCKSDB_LITE
159 static std::unordered_map<std::string, OptionTypeInfo> cf_options_type_info;
160 static std::unordered_map<std::string, OptionTypeInfo>
161 fifo_compaction_options_type_info;
162 static std::unordered_map<std::string, OptionTypeInfo>
163 universal_compaction_options_type_info;
164 static std::unordered_map<std::string, CompactionStopStyle>
165 compaction_stop_style_string_map;
166 static std::unordered_map<std::string, OptionTypeInfo> db_options_type_info;
167 static std::unordered_map<std::string, OptionTypeInfo>
168 lru_cache_options_type_info;
169 static std::unordered_map<std::string, BlockBasedTableOptions::IndexType>
170 block_base_table_index_type_string_map;
171 static std::unordered_map<std::string,
172 BlockBasedTableOptions::DataBlockIndexType>
173 block_base_table_data_block_index_type_string_map;
f67539c2
TL
174 static std::unordered_map<std::string,
175 BlockBasedTableOptions::IndexShorteningMode>
176 block_base_table_index_shortening_mode_string_map;
11fdf7f2
TL
177 static std::unordered_map<std::string, EncodingType> encoding_type_string_map;
178 static std::unordered_map<std::string, CompactionStyle>
179 compaction_style_string_map;
180 static std::unordered_map<std::string, CompactionPri>
181 compaction_pri_string_map;
182 static std::unordered_map<std::string, WALRecoveryMode>
183 wal_recovery_mode_string_map;
184 static std::unordered_map<std::string, DBOptions::AccessHint>
185 access_hint_string_map;
186 static std::unordered_map<std::string, InfoLogLevel>
187 info_log_level_string_map;
188 static ColumnFamilyOptions dummy_cf_options;
189 static CompactionOptionsFIFO dummy_comp_options;
190 static LRUCacheOptions dummy_lru_cache_options;
191 static CompactionOptionsUniversal dummy_comp_options_universal;
192#endif // !ROCKSDB_LITE
193};
7c673cae 194
11fdf7f2
TL
195// Some aliasing
196static auto& compaction_style_to_string =
197 OptionsHelper::compaction_style_to_string;
198static auto& compaction_pri_to_string = OptionsHelper::compaction_pri_to_string;
199static auto& compaction_stop_style_to_string =
200 OptionsHelper::compaction_stop_style_to_string;
201static auto& checksum_type_string_map = OptionsHelper::checksum_type_string_map;
202#ifndef ROCKSDB_LITE
203static auto& cf_options_type_info = OptionsHelper::cf_options_type_info;
204static auto& fifo_compaction_options_type_info =
205 OptionsHelper::fifo_compaction_options_type_info;
206static auto& universal_compaction_options_type_info =
207 OptionsHelper::universal_compaction_options_type_info;
208static auto& compaction_stop_style_string_map =
209 OptionsHelper::compaction_stop_style_string_map;
210static auto& db_options_type_info = OptionsHelper::db_options_type_info;
211static auto& lru_cache_options_type_info =
212 OptionsHelper::lru_cache_options_type_info;
213static auto& compression_type_string_map =
214 OptionsHelper::compression_type_string_map;
215static auto& block_base_table_index_type_string_map =
216 OptionsHelper::block_base_table_index_type_string_map;
217static auto& block_base_table_data_block_index_type_string_map =
218 OptionsHelper::block_base_table_data_block_index_type_string_map;
f67539c2
TL
219static auto& block_base_table_index_shortening_mode_string_map =
220 OptionsHelper::block_base_table_index_shortening_mode_string_map;
11fdf7f2
TL
221static auto& encoding_type_string_map = OptionsHelper::encoding_type_string_map;
222static auto& compaction_style_string_map =
223 OptionsHelper::compaction_style_string_map;
224static auto& compaction_pri_string_map =
225 OptionsHelper::compaction_pri_string_map;
226static auto& wal_recovery_mode_string_map =
227 OptionsHelper::wal_recovery_mode_string_map;
228static auto& access_hint_string_map = OptionsHelper::access_hint_string_map;
229static auto& info_log_level_string_map =
230 OptionsHelper::info_log_level_string_map;
7c673cae
FG
231#endif // !ROCKSDB_LITE
232
f67539c2 233} // namespace ROCKSDB_NAMESPACE