cf_options.h 8.2 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 21 22
// 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
// they point to. Options contains shared_ptr to these data.
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

  uint64_t ttl;
123 124

  std::vector<DbPath> cf_paths;
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_huge_page_size(options.memtable_huge_page_size),
135 136
        max_successive_merges(options.max_successive_merges),
        inplace_update_num_locks(options.inplace_update_num_locks),
137
        prefix_extractor(options.prefix_extractor),
138
        disable_auto_compactions(options.disable_auto_compactions),
139 140
        soft_pending_compaction_bytes_limit(
            options.soft_pending_compaction_bytes_limit),
141 142
        hard_pending_compaction_bytes_limit(
            options.hard_pending_compaction_bytes_limit),
143 144 145 146
        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),
147
        max_compaction_bytes(options.max_compaction_bytes),
148 149 150 151 152 153
        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),
        max_bytes_for_level_multiplier_additional(
            options.max_bytes_for_level_multiplier_additional),
154
        compaction_options_fifo(options.compaction_options_fifo),
155
        compaction_options_universal(options.compaction_options_universal),
156 157 158
        max_sequential_skip_in_iterations(
            options.max_sequential_skip_in_iterations),
        paranoid_file_checks(options.paranoid_file_checks),
A
Aaron Gao 已提交
159
        report_bg_io_stats(options.report_bg_io_stats),
160
        compression(options.compression) {
Y
Yi Wu 已提交
161
    RefreshDerivedOptions(options.num_levels, options.compaction_style);
162
  }
Y
Yi Wu 已提交
163

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

190 191
  explicit MutableCFOptions(const Options& options);

192
  // Must be called after any change to MutableCFOptions
Y
Yi Wu 已提交
193 194 195 196 197
  void RefreshDerivedOptions(int num_levels, CompactionStyle compaction_style);

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

S
sdong 已提交
199 200 201 202 203 204 205
  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];
  }
206

L
Lei Jin 已提交
207 208
  void Dump(Logger* log) const;

209
  // Memtable related options
210
  size_t write_buffer_size;
L
Lei Jin 已提交
211
  int max_write_buffer_number;
212
  size_t arena_block_size;
213
  double memtable_prefix_bloom_size_ratio;
214
  size_t memtable_huge_page_size;
215
  size_t max_successive_merges;
L
Lei Jin 已提交
216
  size_t inplace_update_num_locks;
217
  std::shared_ptr<const SliceTransform> prefix_extractor;
218 219

  // Compaction related options
L
Lei Jin 已提交
220
  bool disable_auto_compactions;
221
  uint64_t soft_pending_compaction_bytes_limit;
222
  uint64_t hard_pending_compaction_bytes_limit;
223 224 225
  int level0_file_num_compaction_trigger;
  int level0_slowdown_writes_trigger;
  int level0_stop_writes_trigger;
226
  uint64_t max_compaction_bytes;
227
  uint64_t target_file_size_base;
228 229
  int target_file_size_multiplier;
  uint64_t max_bytes_for_level_base;
230
  double max_bytes_for_level_multiplier;
231
  std::vector<int> max_bytes_for_level_multiplier_additional;
232
  CompactionOptionsFIFO compaction_options_fifo;
233
  CompactionOptionsUniversal compaction_options_universal;
234

235 236
  // Misc options
  uint64_t max_sequential_skip_in_iterations;
237
  bool paranoid_file_checks;
238
  bool report_bg_io_stats;
A
Aaron Gao 已提交
239
  CompressionType compression;
240

241 242 243
  // Derived options
  // Per-level target file size.
  std::vector<uint64_t> max_file_size;
244 245
};

246
uint64_t MultiplyCheckOverflow(uint64_t op1, double op2);
247

248 249 250 251
// 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);
252
}  // namespace rocksdb