cf_options.h 7.7 KB
Newer Older
1
// Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 3 4 5 6 7
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.

#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 37
  CompactionOptionsUniversal compaction_options_universal;
  CompactionOptionsFIFO compaction_options_fifo;

  const SliceTransform* prefix_extractor;

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

  MergeOperator* merge_operator;

  const CompactionFilter* compaction_filter;

  CompactionFilterFactory* compaction_filter_factory;

47 48 49 50
  int min_write_buffer_number_to_merge;

  int max_write_buffer_number_to_maintain;

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

62 63
  RateLimiter* rate_limiter;

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

  size_t compaction_readahead_size;

  int num_levels;

  bool optimize_filters_for_hits;

111 112
  bool force_consistency_checks;

113 114
  bool allow_ingest_behind;

115 116 117 118 119
  // 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 已提交
120 121

  uint32_t max_subcompactions;
122 123

  const SliceTransform* memtable_insert_with_hint_prefix_extractor;
124 125
};

126
struct MutableCFOptions {
Y
Yi Wu 已提交
127
  explicit MutableCFOptions(const ColumnFamilyOptions& options)
128 129 130
      : write_buffer_size(options.write_buffer_size),
        max_write_buffer_number(options.max_write_buffer_number),
        arena_block_size(options.arena_block_size),
131 132
        memtable_prefix_bloom_size_ratio(
            options.memtable_prefix_bloom_size_ratio),
133
        memtable_huge_page_size(options.memtable_huge_page_size),
134 135 136
        max_successive_merges(options.max_successive_merges),
        inplace_update_num_locks(options.inplace_update_num_locks),
        disable_auto_compactions(options.disable_auto_compactions),
137 138
        soft_pending_compaction_bytes_limit(
            options.soft_pending_compaction_bytes_limit),
139 140
        hard_pending_compaction_bytes_limit(
            options.hard_pending_compaction_bytes_limit),
141 142 143 144
        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),
145
        max_compaction_bytes(options.max_compaction_bytes),
146 147 148 149 150 151 152 153 154
        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),
        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 179 180
        target_file_size_base(0),
        target_file_size_multiplier(0),
        max_bytes_for_level_base(0),
        max_bytes_for_level_multiplier(0),
        max_sequential_skip_in_iterations(0),
        paranoid_file_checks(false),
A
Aaron Gao 已提交
181
        report_bg_io_stats(false),
182
        compression(Snappy_Supported() ? kSnappyCompression : kNoCompression) {}
183

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

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

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

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

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

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

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

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

237
uint64_t MultiplyCheckOverflow(uint64_t op1, double op2);
238

239
}  // namespace rocksdb