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 "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" 19 20 namespace ROCKSDB_NAMESPACE { 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 29 #ifndef ROCKSDB_LITE 30 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); 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, 44 std::shared_ptr<TableFactory>* table_factory, 45 bool ignore_unknown_options = false); 46 47 enum class OptionType { 48 kBoolean, 49 kInt, 50 kInt32T, 51 kInt64T, 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, 68 kCompactionOptionsFIFO, 69 kCompactionOptionsUniversal, 70 kCompactionStopStyle, 71 kMergeOperator, 72 kMemTableRepFactory, 73 kBlockBasedTableIndexType, 74 kBlockBasedTableDataBlockIndexType, 75 kBlockBasedTableIndexShorteningMode, 76 kFilterPolicy, 77 kFlushBlockPolicyFactory, 78 kChecksumType, 79 kEncodingType, 80 kWALRecoveryMode, 81 kAccessHint, 82 kInfoLogLevel, 83 kLRUCacheOptions, 84 kEnv, 85 kUnknown, 86 }; 87 88 enum class OptionVerificationType { 89 kNormal, 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. 101 }; 102 103 // A struct for storing constant option information such as option name, 104 // option type, and offset. 105 struct 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. 115 bool 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". 121 Status 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, 125 std::vector<std::string>* unsupported_options_names = nullptr, 126 bool ignore_unknown_options = false); 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". 131 Status 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, 135 std::vector<std::string>* unsupported_options_names = nullptr, 136 bool ignore_unknown_options = false); 137 138 bool ParseSliceTransform( 139 const std::string& value, 140 std::shared_ptr<const SliceTransform>* slice_transform); 141 142 extern Status StringToMap( 143 const std::string& opts_str, 144 std::unordered_map<std::string, std::string>* opts_map); 145 146 extern bool ParseOptionHelper(char* opt_address, const OptionType& opt_type, 147 const std::string& value); 148 #endif // !ROCKSDB_LITE 149 150 struct 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; 174 static std::unordered_map<std::string, 175 BlockBasedTableOptions::IndexShorteningMode> 176 block_base_table_index_shortening_mode_string_map; 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 }; 194 195 // Some aliasing 196 static auto& compaction_style_to_string = 197 OptionsHelper::compaction_style_to_string; 198 static auto& compaction_pri_to_string = OptionsHelper::compaction_pri_to_string; 199 static auto& compaction_stop_style_to_string = 200 OptionsHelper::compaction_stop_style_to_string; 201 static auto& checksum_type_string_map = OptionsHelper::checksum_type_string_map; 202 #ifndef ROCKSDB_LITE 203 static auto& cf_options_type_info = OptionsHelper::cf_options_type_info; 204 static auto& fifo_compaction_options_type_info = 205 OptionsHelper::fifo_compaction_options_type_info; 206 static auto& universal_compaction_options_type_info = 207 OptionsHelper::universal_compaction_options_type_info; 208 static auto& compaction_stop_style_string_map = 209 OptionsHelper::compaction_stop_style_string_map; 210 static auto& db_options_type_info = OptionsHelper::db_options_type_info; 211 static auto& lru_cache_options_type_info = 212 OptionsHelper::lru_cache_options_type_info; 213 static auto& compression_type_string_map = 214 OptionsHelper::compression_type_string_map; 215 static auto& block_base_table_index_type_string_map = 216 OptionsHelper::block_base_table_index_type_string_map; 217 static auto& block_base_table_data_block_index_type_string_map = 218 OptionsHelper::block_base_table_data_block_index_type_string_map; 219 static auto& block_base_table_index_shortening_mode_string_map = 220 OptionsHelper::block_base_table_index_shortening_mode_string_map; 221 static auto& encoding_type_string_map = OptionsHelper::encoding_type_string_map; 222 static auto& compaction_style_string_map = 223 OptionsHelper::compaction_style_string_map; 224 static auto& compaction_pri_string_map = 225 OptionsHelper::compaction_pri_string_map; 226 static auto& wal_recovery_mode_string_map = 227 OptionsHelper::wal_recovery_mode_string_map; 228 static auto& access_hint_string_map = OptionsHelper::access_hint_string_map; 229 static auto& info_log_level_string_map = 230 OptionsHelper::info_log_level_string_map; 231 #endif // !ROCKSDB_LITE 232 233 } // namespace ROCKSDB_NAMESPACE 234