cf_options.cc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. #include "options/cf_options.h"
  6. #include <cassert>
  7. #include <cinttypes>
  8. #include <limits>
  9. #include <string>
  10. #include "options/db_options.h"
  11. #include "port/port.h"
  12. #include "rocksdb/concurrent_task_limiter.h"
  13. #include "rocksdb/env.h"
  14. #include "rocksdb/file_system.h"
  15. #include "rocksdb/options.h"
  16. namespace ROCKSDB_NAMESPACE {
  17. ImmutableCFOptions::ImmutableCFOptions(const Options& options)
  18. : ImmutableCFOptions(ImmutableDBOptions(options), options) {}
  19. ImmutableCFOptions::ImmutableCFOptions(const ImmutableDBOptions& db_options,
  20. const ColumnFamilyOptions& cf_options)
  21. : compaction_style(cf_options.compaction_style),
  22. compaction_pri(cf_options.compaction_pri),
  23. user_comparator(cf_options.comparator),
  24. internal_comparator(InternalKeyComparator(cf_options.comparator)),
  25. merge_operator(cf_options.merge_operator.get()),
  26. compaction_filter(cf_options.compaction_filter),
  27. compaction_filter_factory(cf_options.compaction_filter_factory.get()),
  28. min_write_buffer_number_to_merge(
  29. cf_options.min_write_buffer_number_to_merge),
  30. max_write_buffer_number_to_maintain(
  31. cf_options.max_write_buffer_number_to_maintain),
  32. max_write_buffer_size_to_maintain(
  33. cf_options.max_write_buffer_size_to_maintain),
  34. inplace_update_support(cf_options.inplace_update_support),
  35. inplace_callback(cf_options.inplace_callback),
  36. info_log(db_options.info_log.get()),
  37. statistics(db_options.statistics.get()),
  38. rate_limiter(db_options.rate_limiter.get()),
  39. info_log_level(db_options.info_log_level),
  40. env(db_options.env),
  41. fs(db_options.fs.get()),
  42. allow_mmap_reads(db_options.allow_mmap_reads),
  43. allow_mmap_writes(db_options.allow_mmap_writes),
  44. db_paths(db_options.db_paths),
  45. memtable_factory(cf_options.memtable_factory.get()),
  46. table_factory(cf_options.table_factory.get()),
  47. table_properties_collector_factories(
  48. cf_options.table_properties_collector_factories),
  49. advise_random_on_open(db_options.advise_random_on_open),
  50. bloom_locality(cf_options.bloom_locality),
  51. purge_redundant_kvs_while_flush(
  52. cf_options.purge_redundant_kvs_while_flush),
  53. use_fsync(db_options.use_fsync),
  54. compression_per_level(cf_options.compression_per_level),
  55. bottommost_compression(cf_options.bottommost_compression),
  56. bottommost_compression_opts(cf_options.bottommost_compression_opts),
  57. compression_opts(cf_options.compression_opts),
  58. level_compaction_dynamic_level_bytes(
  59. cf_options.level_compaction_dynamic_level_bytes),
  60. access_hint_on_compaction_start(
  61. db_options.access_hint_on_compaction_start),
  62. new_table_reader_for_compaction_inputs(
  63. db_options.new_table_reader_for_compaction_inputs),
  64. num_levels(cf_options.num_levels),
  65. optimize_filters_for_hits(cf_options.optimize_filters_for_hits),
  66. force_consistency_checks(cf_options.force_consistency_checks),
  67. allow_ingest_behind(db_options.allow_ingest_behind),
  68. preserve_deletes(db_options.preserve_deletes),
  69. listeners(db_options.listeners),
  70. row_cache(db_options.row_cache),
  71. max_subcompactions(db_options.max_subcompactions),
  72. memtable_insert_with_hint_prefix_extractor(
  73. cf_options.memtable_insert_with_hint_prefix_extractor.get()),
  74. cf_paths(cf_options.cf_paths),
  75. compaction_thread_limiter(cf_options.compaction_thread_limiter),
  76. sst_file_checksum_func(db_options.sst_file_checksum_func.get()) {}
  77. // Multiple two operands. If they overflow, return op1.
  78. uint64_t MultiplyCheckOverflow(uint64_t op1, double op2) {
  79. if (op1 == 0 || op2 <= 0) {
  80. return 0;
  81. }
  82. if (port::kMaxUint64 / op1 < op2) {
  83. return op1;
  84. }
  85. return static_cast<uint64_t>(op1 * op2);
  86. }
  87. // when level_compaction_dynamic_level_bytes is true and leveled compaction
  88. // is used, the base level is not always L1, so precomupted max_file_size can
  89. // no longer be used. Recompute file_size_for_level from base level.
  90. uint64_t MaxFileSizeForLevel(const MutableCFOptions& cf_options,
  91. int level, CompactionStyle compaction_style, int base_level,
  92. bool level_compaction_dynamic_level_bytes) {
  93. if (!level_compaction_dynamic_level_bytes || level < base_level ||
  94. compaction_style != kCompactionStyleLevel) {
  95. assert(level >= 0);
  96. assert(level < (int)cf_options.max_file_size.size());
  97. return cf_options.max_file_size[level];
  98. } else {
  99. assert(level >= 0 && base_level >= 0);
  100. assert(level - base_level < (int)cf_options.max_file_size.size());
  101. return cf_options.max_file_size[level - base_level];
  102. }
  103. }
  104. void MutableCFOptions::RefreshDerivedOptions(int num_levels,
  105. CompactionStyle compaction_style) {
  106. max_file_size.resize(num_levels);
  107. for (int i = 0; i < num_levels; ++i) {
  108. if (i == 0 && compaction_style == kCompactionStyleUniversal) {
  109. max_file_size[i] = ULLONG_MAX;
  110. } else if (i > 1) {
  111. max_file_size[i] = MultiplyCheckOverflow(max_file_size[i - 1],
  112. target_file_size_multiplier);
  113. } else {
  114. max_file_size[i] = target_file_size_base;
  115. }
  116. }
  117. }
  118. void MutableCFOptions::Dump(Logger* log) const {
  119. // Memtable related options
  120. ROCKS_LOG_INFO(log,
  121. " write_buffer_size: %" ROCKSDB_PRIszt,
  122. write_buffer_size);
  123. ROCKS_LOG_INFO(log, " max_write_buffer_number: %d",
  124. max_write_buffer_number);
  125. ROCKS_LOG_INFO(log,
  126. " arena_block_size: %" ROCKSDB_PRIszt,
  127. arena_block_size);
  128. ROCKS_LOG_INFO(log, " memtable_prefix_bloom_ratio: %f",
  129. memtable_prefix_bloom_size_ratio);
  130. ROCKS_LOG_INFO(log, " memtable_whole_key_filtering: %d",
  131. memtable_whole_key_filtering);
  132. ROCKS_LOG_INFO(log,
  133. " memtable_huge_page_size: %" ROCKSDB_PRIszt,
  134. memtable_huge_page_size);
  135. ROCKS_LOG_INFO(log,
  136. " max_successive_merges: %" ROCKSDB_PRIszt,
  137. max_successive_merges);
  138. ROCKS_LOG_INFO(log,
  139. " inplace_update_num_locks: %" ROCKSDB_PRIszt,
  140. inplace_update_num_locks);
  141. ROCKS_LOG_INFO(
  142. log, " prefix_extractor: %s",
  143. prefix_extractor == nullptr ? "nullptr" : prefix_extractor->Name());
  144. ROCKS_LOG_INFO(log, " disable_auto_compactions: %d",
  145. disable_auto_compactions);
  146. ROCKS_LOG_INFO(log, " soft_pending_compaction_bytes_limit: %" PRIu64,
  147. soft_pending_compaction_bytes_limit);
  148. ROCKS_LOG_INFO(log, " hard_pending_compaction_bytes_limit: %" PRIu64,
  149. hard_pending_compaction_bytes_limit);
  150. ROCKS_LOG_INFO(log, " level0_file_num_compaction_trigger: %d",
  151. level0_file_num_compaction_trigger);
  152. ROCKS_LOG_INFO(log, " level0_slowdown_writes_trigger: %d",
  153. level0_slowdown_writes_trigger);
  154. ROCKS_LOG_INFO(log, " level0_stop_writes_trigger: %d",
  155. level0_stop_writes_trigger);
  156. ROCKS_LOG_INFO(log, " max_compaction_bytes: %" PRIu64,
  157. max_compaction_bytes);
  158. ROCKS_LOG_INFO(log, " target_file_size_base: %" PRIu64,
  159. target_file_size_base);
  160. ROCKS_LOG_INFO(log, " target_file_size_multiplier: %d",
  161. target_file_size_multiplier);
  162. ROCKS_LOG_INFO(log, " max_bytes_for_level_base: %" PRIu64,
  163. max_bytes_for_level_base);
  164. ROCKS_LOG_INFO(log, " max_bytes_for_level_multiplier: %f",
  165. max_bytes_for_level_multiplier);
  166. ROCKS_LOG_INFO(log, " ttl: %" PRIu64,
  167. ttl);
  168. ROCKS_LOG_INFO(log, " periodic_compaction_seconds: %" PRIu64,
  169. periodic_compaction_seconds);
  170. std::string result;
  171. char buf[10];
  172. for (const auto m : max_bytes_for_level_multiplier_additional) {
  173. snprintf(buf, sizeof(buf), "%d, ", m);
  174. result += buf;
  175. }
  176. if (result.size() >= 2) {
  177. result.resize(result.size() - 2);
  178. } else {
  179. result = "";
  180. }
  181. ROCKS_LOG_INFO(log, "max_bytes_for_level_multiplier_additional: %s",
  182. result.c_str());
  183. ROCKS_LOG_INFO(log, " max_sequential_skip_in_iterations: %" PRIu64,
  184. max_sequential_skip_in_iterations);
  185. ROCKS_LOG_INFO(log, " paranoid_file_checks: %d",
  186. paranoid_file_checks);
  187. ROCKS_LOG_INFO(log, " report_bg_io_stats: %d",
  188. report_bg_io_stats);
  189. ROCKS_LOG_INFO(log, " compression: %d",
  190. static_cast<int>(compression));
  191. // Universal Compaction Options
  192. ROCKS_LOG_INFO(log, "compaction_options_universal.size_ratio : %d",
  193. compaction_options_universal.size_ratio);
  194. ROCKS_LOG_INFO(log, "compaction_options_universal.min_merge_width : %d",
  195. compaction_options_universal.min_merge_width);
  196. ROCKS_LOG_INFO(log, "compaction_options_universal.max_merge_width : %d",
  197. compaction_options_universal.max_merge_width);
  198. ROCKS_LOG_INFO(
  199. log, "compaction_options_universal.max_size_amplification_percent : %d",
  200. compaction_options_universal.max_size_amplification_percent);
  201. ROCKS_LOG_INFO(log,
  202. "compaction_options_universal.compression_size_percent : %d",
  203. compaction_options_universal.compression_size_percent);
  204. ROCKS_LOG_INFO(log, "compaction_options_universal.stop_style : %d",
  205. compaction_options_universal.stop_style);
  206. ROCKS_LOG_INFO(
  207. log, "compaction_options_universal.allow_trivial_move : %d",
  208. static_cast<int>(compaction_options_universal.allow_trivial_move));
  209. // FIFO Compaction Options
  210. ROCKS_LOG_INFO(log, "compaction_options_fifo.max_table_files_size : %" PRIu64,
  211. compaction_options_fifo.max_table_files_size);
  212. ROCKS_LOG_INFO(log, "compaction_options_fifo.allow_compaction : %d",
  213. compaction_options_fifo.allow_compaction);
  214. }
  215. MutableCFOptions::MutableCFOptions(const Options& options)
  216. : MutableCFOptions(ColumnFamilyOptions(options)) {}
  217. } // namespace ROCKSDB_NAMESPACE