options_helper.h 9.0 KB

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