cf_options.h 8.9 KB
Newer Older
1
// Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
S
Siying Dong 已提交
2 3 4
//  This source code is licensed under both the GPLv2 (found in the
//  COPYING file in the root directory) and Apache 2.0 License
//  (found in the LICENSE.Apache file in the root directory).
5 6 7

#pragma once

8
#include <string>
9
#include <vector>
10

A
Andrew Kryczka 已提交
11
#include "db/dbformat.h"
12
#include "options/db_options.h"
A
Aaron Gao 已提交
13 14
#include "rocksdb/options.h"
#include "util/compression.h"
15

16
namespace ROCKSDB_NAMESPACE {
17

18 19 20
// ImmutableCFOptions is a data struct used by RocksDB internal. It contains a
// subset of Options that should not be changed during the entire lifetime
// of DB. Raw pointers defined in this struct do not have ownership to the data
21
// they point to. Options contains std::shared_ptr to these data.
22 23 24
struct ImmutableCFOptions {
  explicit ImmutableCFOptions(const Options& options);

25 26 27
  ImmutableCFOptions(const ImmutableDBOptions& db_options,
                     const ColumnFamilyOptions& cf_options);

28 29
  CompactionStyle compaction_style;

Y
Yi Wu 已提交
30 31
  CompactionPri compaction_pri;

32
  const Comparator* user_comparator;
A
Andrew Kryczka 已提交
33
  InternalKeyComparator internal_comparator;
34 35 36 37 38 39 40

  MergeOperator* merge_operator;

  const CompactionFilter* compaction_filter;

  CompactionFilterFactory* compaction_filter_factory;

41 42 43 44
  int min_write_buffer_number_to_merge;

  int max_write_buffer_number_to_maintain;

45 46
  int64_t max_write_buffer_size_to_maintain;

47 48 49 50 51 52 53 54 55 56 57
  bool inplace_update_support;

  UpdateStatus (*inplace_callback)(char* existing_value,
                                   uint32_t* existing_value_size,
                                   Slice delta_value,
                                   std::string* merged_value);

  Logger* info_log;

  Statistics* statistics;

58 59
  RateLimiter* rate_limiter;

60 61 62 63
  InfoLogLevel info_log_level;

  Env* env;

64 65
  FileSystem* fs;

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  // Allow the OS to mmap file for reading sst tables. Default: false
  bool allow_mmap_reads;

  // Allow the OS to mmap file for writing. Default: false
  bool allow_mmap_writes;

  std::vector<DbPath> db_paths;

  MemTableRepFactory* memtable_factory;

  TableFactory* table_factory;

  Options::TablePropertiesCollectorFactories
      table_properties_collector_factories;

  bool advise_random_on_open;

  // This options is required by PlainTableReader. May need to move it
F
follitude 已提交
84
  // to PlainTableOptions just like bloom_bits_per_key
85 86 87 88 89 90 91 92 93 94
  uint32_t bloom_locality;

  bool purge_redundant_kvs_while_flush;

  bool use_fsync;

  std::vector<CompressionType> compression_per_level;

  CompressionType bottommost_compression;

95 96
  CompressionOptions bottommost_compression_opts;

97 98 99 100 101 102 103 104 105 106 107 108
  CompressionOptions compression_opts;

  bool level_compaction_dynamic_level_bytes;

  Options::AccessHint access_hint_on_compaction_start;

  bool new_table_reader_for_compaction_inputs;

  int num_levels;

  bool optimize_filters_for_hits;

109 110
  bool force_consistency_checks;

111 112
  bool allow_ingest_behind;

113 114
  bool preserve_deletes;

Y
Yanqin Jin 已提交
115
  // A vector of EventListeners which callback functions will be called
116 117 118 119
  // when specific RocksDB event happens.
  std::vector<std::shared_ptr<EventListener>> listeners;

  std::shared_ptr<Cache> row_cache;
Y
Yi Wu 已提交
120 121

  uint32_t max_subcompactions;
122 123

  const SliceTransform* memtable_insert_with_hint_prefix_extractor;
S
Sagar Vemuri 已提交
124

125
  std::vector<DbPath> cf_paths;
126 127

  std::shared_ptr<ConcurrentTaskLimiter> compaction_thread_limiter;
128

129
  FileChecksumGenFactory* file_checksum_gen_factory;
130 131
};

132
struct MutableCFOptions {
Y
Yi Wu 已提交
133
  explicit MutableCFOptions(const ColumnFamilyOptions& options)
134 135 136
      : write_buffer_size(options.write_buffer_size),
        max_write_buffer_number(options.max_write_buffer_number),
        arena_block_size(options.arena_block_size),
137 138
        memtable_prefix_bloom_size_ratio(
            options.memtable_prefix_bloom_size_ratio),
139
        memtable_whole_key_filtering(options.memtable_whole_key_filtering),
140
        memtable_huge_page_size(options.memtable_huge_page_size),
141 142
        max_successive_merges(options.max_successive_merges),
        inplace_update_num_locks(options.inplace_update_num_locks),
143
        prefix_extractor(options.prefix_extractor),
144
        disable_auto_compactions(options.disable_auto_compactions),
145 146
        soft_pending_compaction_bytes_limit(
            options.soft_pending_compaction_bytes_limit),
147 148
        hard_pending_compaction_bytes_limit(
            options.hard_pending_compaction_bytes_limit),
149 150 151 152
        level0_file_num_compaction_trigger(
            options.level0_file_num_compaction_trigger),
        level0_slowdown_writes_trigger(options.level0_slowdown_writes_trigger),
        level0_stop_writes_trigger(options.level0_stop_writes_trigger),
153
        max_compaction_bytes(options.max_compaction_bytes),
154 155 156 157
        target_file_size_base(options.target_file_size_base),
        target_file_size_multiplier(options.target_file_size_multiplier),
        max_bytes_for_level_base(options.max_bytes_for_level_base),
        max_bytes_for_level_multiplier(options.max_bytes_for_level_multiplier),
158
        ttl(options.ttl),
S
Sagar Vemuri 已提交
159
        periodic_compaction_seconds(options.periodic_compaction_seconds),
160 161
        max_bytes_for_level_multiplier_additional(
            options.max_bytes_for_level_multiplier_additional),
162
        compaction_options_fifo(options.compaction_options_fifo),
163
        compaction_options_universal(options.compaction_options_universal),
164 165 166
        max_sequential_skip_in_iterations(
            options.max_sequential_skip_in_iterations),
        paranoid_file_checks(options.paranoid_file_checks),
A
Aaron Gao 已提交
167
        report_bg_io_stats(options.report_bg_io_stats),
168 169
        compression(options.compression),
        sample_for_compression(options.sample_for_compression) {
Y
Yi Wu 已提交
170
    RefreshDerivedOptions(options.num_levels, options.compaction_style);
171
  }
Y
Yi Wu 已提交
172

173
  MutableCFOptions()
174 175 176
      : write_buffer_size(0),
        max_write_buffer_number(0),
        arena_block_size(0),
177
        memtable_prefix_bloom_size_ratio(0),
178
        memtable_whole_key_filtering(false),
179
        memtable_huge_page_size(0),
180 181
        max_successive_merges(0),
        inplace_update_num_locks(0),
182
        prefix_extractor(nullptr),
183
        disable_auto_compactions(false),
184
        soft_pending_compaction_bytes_limit(0),
185
        hard_pending_compaction_bytes_limit(0),
186 187 188
        level0_file_num_compaction_trigger(0),
        level0_slowdown_writes_trigger(0),
        level0_stop_writes_trigger(0),
189
        max_compaction_bytes(0),
190 191 192 193
        target_file_size_base(0),
        target_file_size_multiplier(0),
        max_bytes_for_level_base(0),
        max_bytes_for_level_multiplier(0),
194
        ttl(0),
S
Sagar Vemuri 已提交
195
        periodic_compaction_seconds(0),
196
        compaction_options_fifo(),
197 198
        max_sequential_skip_in_iterations(0),
        paranoid_file_checks(false),
A
Aaron Gao 已提交
199
        report_bg_io_stats(false),
200 201
        compression(Snappy_Supported() ? kSnappyCompression : kNoCompression),
        sample_for_compression(0) {}
202

203 204
  explicit MutableCFOptions(const Options& options);

205
  // Must be called after any change to MutableCFOptions
Y
Yi Wu 已提交
206 207 208 209 210
  void RefreshDerivedOptions(int num_levels, CompactionStyle compaction_style);

  void RefreshDerivedOptions(const ImmutableCFOptions& ioptions) {
    RefreshDerivedOptions(ioptions.num_levels, ioptions.compaction_style);
  }
211

S
sdong 已提交
212 213 214 215 216 217 218
  int MaxBytesMultiplerAdditional(int level) const {
    if (level >=
        static_cast<int>(max_bytes_for_level_multiplier_additional.size())) {
      return 1;
    }
    return max_bytes_for_level_multiplier_additional[level];
  }
219

L
Lei Jin 已提交
220 221
  void Dump(Logger* log) const;

222
  // Memtable related options
223
  size_t write_buffer_size;
L
Lei Jin 已提交
224
  int max_write_buffer_number;
225
  size_t arena_block_size;
226
  double memtable_prefix_bloom_size_ratio;
227
  bool memtable_whole_key_filtering;
228
  size_t memtable_huge_page_size;
229
  size_t max_successive_merges;
L
Lei Jin 已提交
230
  size_t inplace_update_num_locks;
231
  std::shared_ptr<const SliceTransform> prefix_extractor;
232 233

  // Compaction related options
L
Lei Jin 已提交
234
  bool disable_auto_compactions;
235
  uint64_t soft_pending_compaction_bytes_limit;
236
  uint64_t hard_pending_compaction_bytes_limit;
237 238 239
  int level0_file_num_compaction_trigger;
  int level0_slowdown_writes_trigger;
  int level0_stop_writes_trigger;
240
  uint64_t max_compaction_bytes;
241
  uint64_t target_file_size_base;
242 243
  int target_file_size_multiplier;
  uint64_t max_bytes_for_level_base;
244
  double max_bytes_for_level_multiplier;
245
  uint64_t ttl;
S
Sagar Vemuri 已提交
246
  uint64_t periodic_compaction_seconds;
247
  std::vector<int> max_bytes_for_level_multiplier_additional;
248
  CompactionOptionsFIFO compaction_options_fifo;
249
  CompactionOptionsUniversal compaction_options_universal;
250

251 252
  // Misc options
  uint64_t max_sequential_skip_in_iterations;
253
  bool paranoid_file_checks;
254
  bool report_bg_io_stats;
A
Aaron Gao 已提交
255
  CompressionType compression;
256
  uint64_t sample_for_compression;
257

258 259 260
  // Derived options
  // Per-level target file size.
  std::vector<uint64_t> max_file_size;
261 262
};

263
uint64_t MultiplyCheckOverflow(uint64_t op1, double op2);
264

265 266 267 268
// Get the max file size in a given level.
uint64_t MaxFileSizeForLevel(const MutableCFOptions& cf_options,
    int level, CompactionStyle compaction_style, int base_level = 1,
    bool level_compaction_dynamic_level_bytes = false);
269
}  // namespace ROCKSDB_NAMESPACE