cf_options.h 8.5 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 17

namespace rocksdb {

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
struct ImmutableCFOptions {
23
  ImmutableCFOptions();
24 25
  explicit ImmutableCFOptions(const Options& options);

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

29 30
  CompactionStyle compaction_style;

Y
Yi Wu 已提交
31 32
  CompactionPri compaction_pri;

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

  MergeOperator* merge_operator;

  const CompactionFilter* compaction_filter;

  CompactionFilterFactory* compaction_filter_factory;

42 43 44 45
  int min_write_buffer_number_to_merge;

  int max_write_buffer_number_to_maintain;

46 47 48 49 50 51 52 53 54 55 56
  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;

57 58
  RateLimiter* rate_limiter;

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  InfoLogLevel info_log_level;

  Env* env;

  // 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 已提交
81
  // to PlainTableOptions just like bloom_bits_per_key
82 83 84 85 86 87 88 89 90 91
  uint32_t bloom_locality;

  bool purge_redundant_kvs_while_flush;

  bool use_fsync;

  std::vector<CompressionType> compression_per_level;

  CompressionType bottommost_compression;

92 93
  CompressionOptions bottommost_compression_opts;

94 95 96 97 98 99 100 101 102 103 104 105
  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;

106 107
  bool force_consistency_checks;

108 109
  bool allow_ingest_behind;

110 111
  bool preserve_deletes;

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

  std::shared_ptr<Cache> row_cache;
Y
Yi Wu 已提交
117 118

  uint32_t max_subcompactions;
119 120

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

122
  std::vector<DbPath> cf_paths;
123 124

  std::shared_ptr<ConcurrentTaskLimiter> compaction_thread_limiter;
125 126
};

127
struct MutableCFOptions {
Y
Yi Wu 已提交
128
  explicit MutableCFOptions(const ColumnFamilyOptions& options)
129 130 131
      : write_buffer_size(options.write_buffer_size),
        max_write_buffer_number(options.max_write_buffer_number),
        arena_block_size(options.arena_block_size),
132 133
        memtable_prefix_bloom_size_ratio(
            options.memtable_prefix_bloom_size_ratio),
134
        memtable_whole_key_filtering(options.memtable_whole_key_filtering),
135
        memtable_huge_page_size(options.memtable_huge_page_size),
136 137
        max_successive_merges(options.max_successive_merges),
        inplace_update_num_locks(options.inplace_update_num_locks),
138
        prefix_extractor(options.prefix_extractor),
139
        disable_auto_compactions(options.disable_auto_compactions),
140 141
        soft_pending_compaction_bytes_limit(
            options.soft_pending_compaction_bytes_limit),
142 143
        hard_pending_compaction_bytes_limit(
            options.hard_pending_compaction_bytes_limit),
144 145 146 147
        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),
148
        max_compaction_bytes(options.max_compaction_bytes),
149 150 151 152
        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),
153
        ttl(options.ttl),
154 155
        max_bytes_for_level_multiplier_additional(
            options.max_bytes_for_level_multiplier_additional),
156
        compaction_options_fifo(options.compaction_options_fifo),
157
        compaction_options_universal(options.compaction_options_universal),
158 159 160
        max_sequential_skip_in_iterations(
            options.max_sequential_skip_in_iterations),
        paranoid_file_checks(options.paranoid_file_checks),
A
Aaron Gao 已提交
161
        report_bg_io_stats(options.report_bg_io_stats),
162
        compression(options.compression) {
Y
Yi Wu 已提交
163
    RefreshDerivedOptions(options.num_levels, options.compaction_style);
164
  }
Y
Yi Wu 已提交
165

166
  MutableCFOptions()
167 168 169
      : write_buffer_size(0),
        max_write_buffer_number(0),
        arena_block_size(0),
170
        memtable_prefix_bloom_size_ratio(0),
171
        memtable_whole_key_filtering(false),
172
        memtable_huge_page_size(0),
173 174
        max_successive_merges(0),
        inplace_update_num_locks(0),
175
        prefix_extractor(nullptr),
176
        disable_auto_compactions(false),
177
        soft_pending_compaction_bytes_limit(0),
178
        hard_pending_compaction_bytes_limit(0),
179 180 181
        level0_file_num_compaction_trigger(0),
        level0_slowdown_writes_trigger(0),
        level0_stop_writes_trigger(0),
182
        max_compaction_bytes(0),
183 184 185 186
        target_file_size_base(0),
        target_file_size_multiplier(0),
        max_bytes_for_level_base(0),
        max_bytes_for_level_multiplier(0),
187
        ttl(0),
188
        compaction_options_fifo(),
189 190
        max_sequential_skip_in_iterations(0),
        paranoid_file_checks(false),
A
Aaron Gao 已提交
191
        report_bg_io_stats(false),
192
        compression(Snappy_Supported() ? kSnappyCompression : kNoCompression) {}
193

194 195
  explicit MutableCFOptions(const Options& options);

196
  // Must be called after any change to MutableCFOptions
Y
Yi Wu 已提交
197 198 199 200 201
  void RefreshDerivedOptions(int num_levels, CompactionStyle compaction_style);

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

S
sdong 已提交
203 204 205 206 207 208 209
  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];
  }
210

L
Lei Jin 已提交
211 212
  void Dump(Logger* log) const;

213
  // Memtable related options
214
  size_t write_buffer_size;
L
Lei Jin 已提交
215
  int max_write_buffer_number;
216
  size_t arena_block_size;
217
  double memtable_prefix_bloom_size_ratio;
218
  bool memtable_whole_key_filtering;
219
  size_t memtable_huge_page_size;
220
  size_t max_successive_merges;
L
Lei Jin 已提交
221
  size_t inplace_update_num_locks;
222
  std::shared_ptr<const SliceTransform> prefix_extractor;
223 224

  // Compaction related options
L
Lei Jin 已提交
225
  bool disable_auto_compactions;
226
  uint64_t soft_pending_compaction_bytes_limit;
227
  uint64_t hard_pending_compaction_bytes_limit;
228 229 230
  int level0_file_num_compaction_trigger;
  int level0_slowdown_writes_trigger;
  int level0_stop_writes_trigger;
231
  uint64_t max_compaction_bytes;
232
  uint64_t target_file_size_base;
233 234
  int target_file_size_multiplier;
  uint64_t max_bytes_for_level_base;
235
  double max_bytes_for_level_multiplier;
236
  uint64_t ttl;
237
  std::vector<int> max_bytes_for_level_multiplier_additional;
238
  CompactionOptionsFIFO compaction_options_fifo;
239
  CompactionOptionsUniversal compaction_options_universal;
240

241 242
  // Misc options
  uint64_t max_sequential_skip_in_iterations;
243
  bool paranoid_file_checks;
244
  bool report_bg_io_stats;
A
Aaron Gao 已提交
245
  CompressionType compression;
246

247 248 249
  // Derived options
  // Per-level target file size.
  std::vector<uint64_t> max_file_size;
250 251
};

252
uint64_t MultiplyCheckOverflow(uint64_t op1, double op2);
253

254 255 256 257
// 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);
258
}  // namespace rocksdb