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).
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"
18 #include "rocksdb/universal_compaction.h"
22 DBOptions
BuildDBOptions(const ImmutableDBOptions
& immutable_db_options
,
23 const MutableDBOptions
& mutable_db_options
);
25 ColumnFamilyOptions
BuildColumnFamilyOptions(
26 const ColumnFamilyOptions
& ioptions
,
27 const MutableCFOptions
& mutable_cf_options
);
31 Status
GetMutableOptionsFromStrings(
32 const MutableCFOptions
& base_options
,
33 const std::unordered_map
<std::string
, std::string
>& options_map
,
34 Logger
* info_log
, MutableCFOptions
* new_options
);
36 Status
GetMutableDBOptionsFromStrings(
37 const MutableDBOptions
& base_options
,
38 const std::unordered_map
<std::string
, std::string
>& options_map
,
39 MutableDBOptions
* new_options
);
41 Status
GetTableFactoryFromMap(
42 const std::string
& factory_name
,
43 const std::unordered_map
<std::string
, std::string
>& opt_map
,
44 std::shared_ptr
<TableFactory
>* table_factory
,
45 bool ignore_unknown_options
= false);
47 enum class OptionType
{
63 kVectorCompressionType
,
67 kCompactionFilterFactory
,
68 kCompactionOptionsFIFO
,
69 kCompactionOptionsUniversal
,
73 kBlockBasedTableIndexType
,
74 kBlockBasedTableDataBlockIndexType
,
76 kFlushBlockPolicyFactory
,
86 enum class OptionVerificationType
{
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.
101 // A struct for storing constant option information such as option name,
102 // option type, and offset.
103 struct OptionTypeInfo
{
106 OptionVerificationType verification
;
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
);
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
,
123 std::vector
<std::string
>* unsupported_options_names
= nullptr,
124 bool ignore_unknown_options
= false);
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
,
133 std::vector
<std::string
>* unsupported_options_names
= nullptr,
134 bool ignore_unknown_options
= false);
136 bool ParseSliceTransform(
137 const std::string
& value
,
138 std::shared_ptr
<const SliceTransform
>* slice_transform
);
140 extern Status
StringToMap(
141 const std::string
& opts_str
,
142 std::unordered_map
<std::string
, std::string
>* opts_map
);
144 extern bool ParseOptionHelper(char* opt_address
, const OptionType
& opt_type
,
145 const std::string
& value
);
146 #endif // !ROCKSDB_LITE
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
;
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
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
;
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
;
224 #endif // !ROCKSDB_LITE
226 } // namespace rocksdb