cf_options.h 7.7 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 35 36
  CompactionOptionsUniversal compaction_options_universal;

  const SliceTransform* prefix_extractor;

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

  MergeOperator* merge_operator;

  const CompactionFilter* compaction_filter;

  CompactionFilterFactory* compaction_filter_factory;

46 47 48 49
  int min_write_buffer_number_to_merge;

  int max_write_buffer_number_to_maintain;

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

61 62
  RateLimiter* rate_limiter;

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

108 109
  bool force_consistency_checks;

110 111
  bool allow_ingest_behind;

112 113
  bool preserve_deletes;

114 115 116 117 118
  // A vector of EventListeners which call-back functions will be called
  // when specific RocksDB event happens.
  std::vector<std::shared_ptr<EventListener>> listeners;

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

  uint32_t max_subcompactions;
121 122

  const SliceTransform* memtable_insert_with_hint_prefix_extractor;
123 124
};

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

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

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

  void RefreshDerivedOptions(const ImmutableCFOptions& ioptions) {
    RefreshDerivedOptions(ioptions.num_levels, ioptions.compaction_style);
  }
191 192 193

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

L
Lei Jin 已提交
202 203
  void Dump(Logger* log) const;

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

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

228 229
  // Misc options
  uint64_t max_sequential_skip_in_iterations;
230
  bool paranoid_file_checks;
231
  bool report_bg_io_stats;
A
Aaron Gao 已提交
232
  CompressionType compression;
233

234 235 236
  // Derived options
  // Per-level target file size.
  std::vector<uint64_t> max_file_size;
237 238
};

239
uint64_t MultiplyCheckOverflow(uint64_t op1, double op2);
240

241
}  // namespace rocksdb