cf_options.h 7.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 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 34
  const SliceTransform* prefix_extractor;

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

  MergeOperator* merge_operator;

  const CompactionFilter* compaction_filter;

  CompactionFilterFactory* compaction_filter_factory;

44 45 46 47
  int min_write_buffer_number_to_merge;

  int max_write_buffer_number_to_maintain;

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

59 60
  RateLimiter* rate_limiter;

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  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 已提交
83
  // to PlainTableOptions just like bloom_bits_per_key
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
  uint32_t bloom_locality;

  bool purge_redundant_kvs_while_flush;

  bool use_fsync;

  std::vector<CompressionType> compression_per_level;

  CompressionType bottommost_compression;

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

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

188
  // Must be called after any change to MutableCFOptions
Y
Yi Wu 已提交
189 190 191 192 193
  void RefreshDerivedOptions(int num_levels, CompactionStyle compaction_style);

  void RefreshDerivedOptions(const ImmutableCFOptions& ioptions) {
    RefreshDerivedOptions(ioptions.num_levels, ioptions.compaction_style);
  }
194 195 196

  // Get the max file size in a given level.
  uint64_t MaxFileSizeForLevel(int level) const;
S
sdong 已提交
197 198 199 200 201 202 203
  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];
  }
204

L
Lei Jin 已提交
205 206
  void Dump(Logger* log) const;

207
  // Memtable related options
208
  size_t write_buffer_size;
L
Lei Jin 已提交
209
  int max_write_buffer_number;
210
  size_t arena_block_size;
211
  double memtable_prefix_bloom_size_ratio;
212
  size_t memtable_huge_page_size;
213
  size_t max_successive_merges;
L
Lei Jin 已提交
214
  size_t inplace_update_num_locks;
215 216

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

232 233
  // Misc options
  uint64_t max_sequential_skip_in_iterations;
234
  bool paranoid_file_checks;
235
  bool report_bg_io_stats;
A
Aaron Gao 已提交
236
  CompressionType compression;
237

238 239 240
  // Derived options
  // Per-level target file size.
  std::vector<uint64_t> max_file_size;
241 242
};

243
uint64_t MultiplyCheckOverflow(uint64_t op1, double op2);
244

245
}  // namespace rocksdb