options_helper.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "rocksdb/advanced_options.h"
  11. #include "rocksdb/options.h"
  12. #include "rocksdb/status.h"
  13. #include "rocksdb/table.h"
  14. namespace ROCKSDB_NAMESPACE {
  15. struct ColumnFamilyOptions;
  16. struct ConfigOptions;
  17. struct DBOptions;
  18. struct ImmutableCFOptions;
  19. struct ImmutableDBOptions;
  20. struct MutableDBOptions;
  21. struct MutableCFOptions;
  22. struct Options;
  23. const std::vector<CompressionType>& GetSupportedCompressions();
  24. const std::vector<CompressionType>& GetSupportedDictCompressions();
  25. const std::vector<ChecksumType>& GetSupportedChecksums();
  26. inline bool IsSupportedChecksumType(ChecksumType type) {
  27. // Avoid annoying compiler warning-as-error (-Werror=type-limits)
  28. auto min = kNoChecksum;
  29. auto max = kXXH3;
  30. return type >= min && type <= max;
  31. }
  32. // Checks that the combination of DBOptions and ColumnFamilyOptions are valid
  33. Status ValidateOptions(const DBOptions& db_opts,
  34. const ColumnFamilyOptions& cf_opts);
  35. DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options,
  36. const MutableDBOptions& mutable_db_options);
  37. // Overwrites `options`
  38. void BuildDBOptions(const ImmutableDBOptions& immutable_db_options,
  39. const MutableDBOptions& mutable_db_options,
  40. DBOptions& options);
  41. ColumnFamilyOptions BuildColumnFamilyOptions(
  42. const ColumnFamilyOptions& ioptions,
  43. const MutableCFOptions& mutable_cf_options);
  44. void UpdateColumnFamilyOptions(const ImmutableCFOptions& ioptions,
  45. ColumnFamilyOptions* cf_opts);
  46. void UpdateColumnFamilyOptions(const MutableCFOptions& moptions,
  47. ColumnFamilyOptions* cf_opts);
  48. std::unique_ptr<Configurable> DBOptionsAsConfigurable(
  49. const MutableDBOptions& opts);
  50. std::unique_ptr<Configurable> DBOptionsAsConfigurable(
  51. const DBOptions& opts,
  52. const std::unordered_map<std::string, std::string>* opt_map = nullptr);
  53. std::unique_ptr<Configurable> CFOptionsAsConfigurable(
  54. const MutableCFOptions& opts);
  55. std::unique_ptr<Configurable> CFOptionsAsConfigurable(
  56. const ColumnFamilyOptions& opts,
  57. const std::unordered_map<std::string, std::string>* opt_map = nullptr);
  58. Status StringToMap(const std::string& opts_str,
  59. std::unordered_map<std::string, std::string>* opts_map);
  60. Status GetStringFromCompressionType(std::string* compression_str,
  61. CompressionType compression_type);
  62. struct OptionsHelper {
  63. static const std::string kCFOptionsName /*= "ColumnFamilyOptions"*/;
  64. static const std::string kDBOptionsName /*= "DBOptions" */;
  65. static std::map<CompactionStyle, std::string> compaction_style_to_string;
  66. static std::map<CompactionPri, std::string> compaction_pri_to_string;
  67. static std::map<CompactionStopStyle, std::string>
  68. compaction_stop_style_to_string;
  69. static std::map<Temperature, std::string> temperature_to_string;
  70. static std::unordered_map<std::string, ChecksumType> checksum_type_string_map;
  71. static std::unordered_map<std::string, CompressionType>
  72. compression_type_string_map;
  73. static std::unordered_map<std::string, PrepopulateBlobCache>
  74. prepopulate_blob_cache_string_map;
  75. static std::unordered_map<std::string, CompactionStopStyle>
  76. compaction_stop_style_string_map;
  77. static std::unordered_map<std::string, EncodingType> encoding_type_string_map;
  78. static std::unordered_map<std::string, CompactionStyle>
  79. compaction_style_string_map;
  80. static std::unordered_map<std::string, CompactionPri>
  81. compaction_pri_string_map;
  82. static std::unordered_map<std::string, Temperature> temperature_string_map;
  83. };
  84. // Some aliasing
  85. static auto& compaction_style_to_string =
  86. OptionsHelper::compaction_style_to_string;
  87. static auto& compaction_pri_to_string = OptionsHelper::compaction_pri_to_string;
  88. static auto& compaction_stop_style_to_string =
  89. OptionsHelper::compaction_stop_style_to_string;
  90. static auto& temperature_to_string = OptionsHelper::temperature_to_string;
  91. static auto& checksum_type_string_map = OptionsHelper::checksum_type_string_map;
  92. static auto& compaction_stop_style_string_map =
  93. OptionsHelper::compaction_stop_style_string_map;
  94. static auto& compression_type_string_map =
  95. OptionsHelper::compression_type_string_map;
  96. static auto& encoding_type_string_map = OptionsHelper::encoding_type_string_map;
  97. static auto& compaction_style_string_map =
  98. OptionsHelper::compaction_style_string_map;
  99. static auto& compaction_pri_string_map =
  100. OptionsHelper::compaction_pri_string_map;
  101. static auto& temperature_string_map = OptionsHelper::temperature_string_map;
  102. static auto& prepopulate_blob_cache_string_map =
  103. OptionsHelper::prepopulate_blob_cache_string_map;
  104. } // namespace ROCKSDB_NAMESPACE