options.h 34.9 KB
Newer Older
1 2 3 4
// Copyright (c) 2013, Facebook, Inc.  All rights reserved.
// 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.
J
jorlow@chromium.org 已提交
5 6 7 8
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

9 10
#ifndef STORAGE_ROCKSDB_INCLUDE_OPTIONS_H_
#define STORAGE_ROCKSDB_INCLUDE_OPTIONS_H_
J
jorlow@chromium.org 已提交
11 12

#include <stddef.h>
H
heyongqiang 已提交
13
#include <string>
14
#include <memory>
15
#include <vector>
16
#include <stdint.h>
17

18
#include "rocksdb/universal_compaction.h"
T
Tyler Harter 已提交
19

20
namespace rocksdb {
J
jorlow@chromium.org 已提交
21 22

class Cache;
23 24
class CompactionFilter;
class CompactionFilterFactory;
J
jorlow@chromium.org 已提交
25 26
class Comparator;
class Env;
S
Sanjay Ghemawat 已提交
27
class FilterPolicy;
28
class Logger;
29
class MergeOperator;
J
jorlow@chromium.org 已提交
30
class Snapshot;
S
Siying Dong 已提交
31
class TableFactory;
32 33 34 35 36
class MemTableRepFactory;
class TablePropertiesCollector;
class Slice;
class SliceTransform;
class Statistics;
37
class InternalKeyComparator;
J
jorlow@chromium.org 已提交
38

39 40
using std::shared_ptr;

J
jorlow@chromium.org 已提交
41 42 43 44
// DB contents are stored in a set of blocks, each of which holds a
// sequence of key,value pairs.  Each block may be compressed before
// being stored in a file.  The following enum describes which
// compression method (if any) is used to compress a block.
45
enum CompressionType : char {
J
jorlow@chromium.org 已提交
46 47
  // NOTE: do not change the values of existing entries, as these are
  // part of the persistent format on disk.
48
  kNoCompression = 0x0,
H
heyongqiang 已提交
49
  kSnappyCompression = 0x1,
H
heyongqiang 已提交
50 51
  kZlibCompression = 0x2,
  kBZip2Compression = 0x3
J
jorlow@chromium.org 已提交
52 53
};

54
enum CompactionStyle : char {
55 56
  kCompactionStyleLevel = 0x0,     // level based compaction style
  kCompactionStyleUniversal = 0x1  // Universal compaction style
57 58
};

59 60 61 62 63
// Compression options for different compression algorithms like Zlib
struct CompressionOptions {
  int window_bits;
  int level;
  int strategy;
64 65 66
  CompressionOptions() : window_bits(-14), level(-1), strategy(0) {}
  CompressionOptions(int wbits, int lev, int strategy)
      : window_bits(wbits), level(lev), strategy(strategy) {}
67 68
};

69 70 71 72 73 74
enum UpdateStatus {    // Return status For inplace update callback
  UPDATE_FAILED   = 0, // Nothing to update
  UPDATED_INPLACE = 1, // Value updated inplace
  UPDATED         = 2, // No inplace update. Merged value set
};

75 76
struct Options;

77
struct ColumnFamilyOptions {
J
jorlow@chromium.org 已提交
78 79 80 81 82 83 84 85 86 87 88
  // -------------------
  // Parameters that affect behavior

  // Comparator used to define the order of keys in the table.
  // Default: a comparator that uses lexicographic byte-wise ordering
  //
  // REQUIRES: The client must ensure that the comparator supplied
  // here has the same name and orders keys *exactly* the same as the
  // comparator provided to previous open calls on the same DB.
  const Comparator* comparator;

89 90 91 92 93 94 95 96 97 98
  // REQUIRES: The client must provide a merge operator if Merge operation
  // needs to be accessed. Calling Merge on a DB without a merge operator
  // would result in Status::NotSupported. The client must ensure that the
  // merge operator supplied here has the same name and *exactly* the same
  // semantics as the merge operator provided to previous open calls on
  // the same DB. The only exception is reserved for upgrade, where a DB
  // previously without a merge operator is introduced to Merge operation
  // for the first time. It's necessary to specify a merge operator when
  // openning the DB in this case.
  // Default: nullptr
99
  shared_ptr<MergeOperator> merge_operator;
100

101
  // A single CompactionFilter instance to call into during compaction.
102 103
  // Allows an application to modify/delete a key-value during background
  // compaction.
104 105 106 107
  //
  // If the client requires a new compaction filter to be used for different
  // compaction runs, it can specify compaction_filter_factory instead of this
  // option.  The client should specify only one of the two.
108 109
  // compaction_filter takes precedence over compaction_filter_factory if
  // client specifies both.
110 111 112 113 114
  //
  // If multithreaded compaction is being used, the supplied CompactionFilter
  // instance may be used from different threads concurrently and so should be
  // thread-safe.
  //
115 116 117
  // Default: nullptr
  const CompactionFilter* compaction_filter;

118 119 120 121 122 123 124 125 126 127
  // This is a factory that provides compaction filter objects which allow
  // an application to modify/delete a key-value during background compaction.
  //
  // A new filter will be created on each compaction run.  If multithreaded
  // compaction is being used, each created CompactionFilter will only be used
  // from a single thread and so does not need to be thread-safe.
  //
  // Default: a factory that doesn't provide any object
  std::shared_ptr<CompactionFilterFactory> compaction_filter_factory;

J
jorlow@chromium.org 已提交
128 129 130
  // -------------------
  // Parameters that affect performance

131 132
  // Amount of data to build up in memory (backed by an unsorted log
  // on disk) before converting to a sorted on-disk file.
J
jorlow@chromium.org 已提交
133
  //
134
  // Larger values increase performance, especially during bulk loads.
A
Abhishek Kona 已提交
135
  // Up to max_write_buffer_number write buffers may be held in memory
136
  // at the same time,
137
  // so you may wish to adjust this parameter to control memory usage.
138 139
  // Also, a larger write buffer will result in a longer recovery time
  // the next time the database is opened.
J
jorlow@chromium.org 已提交
140
  //
141
  // Default: 4MB
J
jorlow@chromium.org 已提交
142 143
  size_t write_buffer_size;

144
  // The maximum number of write buffers that are built up in memory.
A
Abhishek Kona 已提交
145
  // The default is 2, so that when 1 write buffer is being flushed to
146 147 148 149
  // storage, new writes can continue to the other write buffer.
  // Default: 2
  int max_write_buffer_number;

150
  // The minimum number of write buffers that will be merged together
151
  // before writing to storage.  If set to 1, then
152 153 154 155 156 157 158
  // all write buffers are fushed to L0 as individual files and this increases
  // read amplification because a get request has to check in all of these
  // files. Also, an in-memory merge may result in writing lesser
  // data to storage if there are duplicate records in each of these
  // individual write buffers.  Default: 1
  int min_write_buffer_number_to_merge;

J
jorlow@chromium.org 已提交
159 160 161
  // Control over blocks (user data is stored in a set of blocks, and
  // a block is the unit of reading from disk).

A
Abhishek Kona 已提交
162
  // If non-NULL use the specified cache for blocks.
163
  // If NULL, rocksdb will automatically create and use an 8MB internal cache.
A
Abhishek Kona 已提交
164
  // Default: nullptr
165
  shared_ptr<Cache> block_cache;
J
jorlow@chromium.org 已提交
166

167 168 169 170 171
  // If non-NULL use the specified cache for compressed blocks.
  // If NULL, rocksdb will not use a compressed block cache.
  // Default: nullptr
  shared_ptr<Cache> block_cache_compressed;

J
jorlow@chromium.org 已提交
172 173 174 175 176
  // Approximate size of user data packed per block.  Note that the
  // block size specified here corresponds to uncompressed data.  The
  // actual size of the unit read from disk may be smaller if
  // compression is enabled.  This parameter can be changed dynamically.
  //
177
  // Default: 4K
D
dgrogan@chromium.org 已提交
178
  size_t block_size;
J
jorlow@chromium.org 已提交
179 180 181 182 183 184 185 186

  // Number of keys between restart points for delta encoding of keys.
  // This parameter can be changed dynamically.  Most clients should
  // leave this parameter alone.
  //
  // Default: 16
  int block_restart_interval;

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
  // Compress blocks using the specified compression algorithm.  This
  // parameter can be changed dynamically.
  //
  // Default: kSnappyCompression, which gives lightweight but fast
  // compression.
  //
  // Typical speeds of kSnappyCompression on an Intel(R) Core(TM)2 2.4GHz:
  //    ~200-500MB/s compression
  //    ~400-800MB/s decompression
  // Note that these speeds are significantly faster than most
  // persistent storage speeds, and therefore it is typically never
  // worth switching to kNoCompression.  Even if the input data is
  // incompressible, the kSnappyCompression implementation will
  // efficiently detect that and will switch to uncompressed mode.
  CompressionType compression;

203 204 205 206
  // Different levels can have different compression policies. There
  // are cases where most lower levels would like to quick compression
  // algorithm while the higher levels (which have more data) use
  // compression algorithms that have better compression but could
A
Abhishek Kona 已提交
207 208
  // be slower. This array, if non nullptr, should have an entry for
  // each level of the database. This array, if non nullptr, overides the
209 210 211 212
  // value specified in the previous field 'compression'. The caller is
  // reponsible for allocating memory and initializing the values in it
  // before invoking Open(). The caller is responsible for freeing this
  // array and it could be freed anytime after the return from Open().
213
  // This could have been a std::vector but that makes the equivalent
214
  // java/C api hard to construct.
215
  std::vector<CompressionType> compression_per_level;
216

217
  // different options for compression algorithms
218 219
  CompressionOptions compression_opts;

A
Abhishek Kona 已提交
220
  // If non-nullptr, use the specified filter policy to reduce disk reads.
221 222 223
  // Many applications will benefit from passing the result of
  // NewBloomFilterPolicy() here.
  //
A
Abhishek Kona 已提交
224
  // Default: nullptr
225 226
  const FilterPolicy* filter_policy;

T
Tyler Harter 已提交
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
  // If non-nullptr, use the specified function to determine the
  // prefixes for keys.  These prefixes will be placed in the filter.
  // Depending on the workload, this can reduce the number of read-IOP
  // cost for scans when a prefix is passed via ReadOptions to
  // db.NewIterator().  For prefix filtering to work properly,
  // "prefix_extractor" and "comparator" must be such that the following
  // properties hold:
  //
  // 1) key.starts_with(prefix(key))
  // 2) Compare(prefix(key), key) <= 0.
  // 3) If Compare(k1, k2) <= 0, then Compare(prefix(k1), prefix(k2)) <= 0
  // 4) prefix(prefix(key)) == prefix(key)
  //
  // Default: nullptr
  const SliceTransform* prefix_extractor;

  // If true, place whole keys in the filter (not just prefixes).
  // This must generally be true for gets to be efficient.
  //
  // Default: true
  bool whole_key_filtering;

249 250 251 252 253 254 255
  // Number of levels for this database
  int num_levels;

  // Number of files to trigger level-0 compaction. A value <0 means that
  // level-0 compaction will not be triggered by number of files at all.
  int level0_file_num_compaction_trigger;

256 257 258
  // Soft limit on number of level-0 files. We start slowing down writes at this
  // point. A value <0 means that no writing slow down will be triggered by
  // number of files in level-0.
259 260 261 262 263 264 265 266 267 268 269 270 271
  int level0_slowdown_writes_trigger;

  // Maximum number of level-0 files.  We stop writes at this point.
  int level0_stop_writes_trigger;

  // Maximum level to which a new compacted memtable is pushed if it
  // does not create overlap.  We try to push to level 2 to avoid the
  // relatively expensive level 0=>1 compactions and to avoid some
  // expensive manifest file operations.  We do not push all the way to
  // the largest level since that can generate a lot of wasted disk
  // space if the same key space is being repeatedly overwritten.
  int max_mem_compaction_level;

272 273 274 275 276 277 278 279 280 281
  // Target file size for compaction.
  // target_file_size_base is per-file size for level-1.
  // Target file size for level L can be calculated by
  // target_file_size_base * (target_file_size_multiplier ^ (L-1))
  // For example, if target_file_size_base is 2MB and
  // target_file_size_multiplier is 10, then each file on level-1 will
  // be 2MB, and each file on level 2 will be 20MB,
  // and each file on level-3 will be 200MB.

  // by default target_file_size_base is 2MB.
282
  int target_file_size_base;
283 284
  // by default target_file_size_multiplier is 1, which means
  // by default files in different levels will have similar size.
285 286
  int target_file_size_multiplier;

287 288 289 290 291 292 293 294 295 296
  // Control maximum total data size for a level.
  // max_bytes_for_level_base is the max total for level-1.
  // Maximum number of bytes for level L can be calculated as
  // (max_bytes_for_level_base) * (max_bytes_for_level_multiplier ^ (L-1))
  // For example, if max_bytes_for_level_base is 20MB, and if
  // max_bytes_for_level_multiplier is 10, total data size for level-1
  // will be 20MB, total file size for level-2 will be 200MB,
  // and total file size for level-3 will be 2GB.

  // by default 'max_bytes_for_level_base' is 10MB.
297
  uint64_t max_bytes_for_level_base;
298
  // by default 'max_bytes_for_level_base' is 10.
H
heyongqiang 已提交
299
  int max_bytes_for_level_multiplier;
300

301 302 303 304 305 306
  // Different max-size multipliers for different levels.
  // These are multiplied by max_bytes_for_level_multiplier to arrive
  // at the max-size of each level.
  // Default: 1
  std::vector<int> max_bytes_for_level_multiplier_additional;

H
heyongqiang 已提交
307 308 309 310 311
  // Maximum number of bytes in all compacted files.  We avoid expanding
  // the lower level file set of a compaction if it would make the
  // total compaction cover more than
  // (expanded_compaction_factor * targetFileSizeLevel()) many bytes.
  int expanded_compaction_factor;
312

313
  // Maximum number of bytes in all source files to be compacted in a
A
Abhishek Kona 已提交
314
  // single compaction run. We avoid picking too many files in the
315 316 317 318 319 320 321
  // source level so that we do not exceed the total source bytes
  // for compaction to exceed
  // (source_compaction_factor * targetFileSizeLevel()) many bytes.
  // Default:1, i.e. pick maxfilesize amount of data as the source of
  // a compaction.
  int source_compaction_factor;

H
heyongqiang 已提交
322 323 324
  // Control maximum bytes of overlaps in grandparent (i.e., level+2) before we
  // stop building a single file in a level->level+1 compaction.
  int max_grandparent_overlap_factor;
325

326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
  // Disable compaction triggered by seek.
  // With bloomfilter and fast storage, a miss on one level
  // is very cheap if the file handle is cached in table cache
  // (which is true if max_open_files is large).
  bool disable_seek_compaction;

  // Puts are delayed 0-1 ms when any level has a compaction score that exceeds
  // soft_rate_limit. This is ignored when == 0.0.
  // CONSTRAINT: soft_rate_limit <= hard_rate_limit. If this constraint does not
  // hold, RocksDB will set soft_rate_limit = hard_rate_limit
  // Default: 0 (disabled)
  double soft_rate_limit;

  // Puts are delayed 1ms at a time when any level has a compaction score that
  // exceeds hard_rate_limit. This is ignored when <= 1.0.
  // Default: 0 (disabled)
  double hard_rate_limit;

  // Max time a put will be stalled when hard_rate_limit is enforced. If 0, then
  // there is no limit.
  // Default: 1000
  unsigned int rate_limit_delay_max_milliseconds;

  // Disable block cache. If this is set to true,
  // then no block cache should be used, and the block_cache should
  // point to a nullptr object.
  // Default: false
  bool no_block_cache;

355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
  // size of one block in arena memory allocation.
  // If <= 0, a proper value is automatically calculated (usually 1/10 of
  // writer_buffer_size).
  //
  // There are two additonal restriction of the The specified size:
  // (1) size should be in the range of [4096, 2 << 30] and
  // (2) be the multiple of the CPU word (which helps with the memory
  // alignment).
  //
  // We'll automatically check and adjust the size number to make sure it
  // conforms to the restrictions.
  //
  // Default: 0
  size_t arena_block_size;

370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
  // Disable automatic compactions. Manual compactions can still
  // be issued on this column family
  bool disable_auto_compactions;

  // Purge duplicate/deleted keys when a memtable is flushed to storage.
  // Default: true
  bool purge_redundant_kvs_while_flush;

  // This is used to close a block before it reaches the configured
  // 'block_size'. If the percentage of free space in the current block is less
  // than this specified number and adding a new record to the block will
  // exceed the configured block size, then this block will be closed and the
  // new record will be written to the next block.
  // Default is 10.
  int block_size_deviation;

  // The compaction style. Default: kCompactionStyleLevel
  CompactionStyle compaction_style;

  // The options needed to support Universal Style compactions
  CompactionOptionsUniversal compaction_options_universal;

  // Use KeyMayExist API to filter deletes when this is true.
  // If KeyMayExist returns false, i.e. the key definitely does not exist, then
  // the delete is a noop. KeyMayExist only incurs in-memory look up.
  // This optimization avoids writing the delete to storage when appropriate.
  // Default: false
  bool filter_deletes;

  // An iteration->Next() sequentially skips over keys with the same
  // user-key unless this option is set. This number specifies the number
  // of keys (with the same userkey) that will be sequentially
  // skipped before a reseek is issued.
  // Default: 8
  uint64_t max_sequential_skip_in_iterations;

  // This is a factory that provides MemTableRep objects.
  // Default: a factory that provides a skip-list-based implementation of
  // MemTableRep.
  std::shared_ptr<MemTableRepFactory> memtable_factory;

  // This is a factory that provides TableFactory objects.
  // Default: a factory that provides a default implementation of
  // Table and TableBuilder.
  std::shared_ptr<TableFactory> table_factory;

  // This option allows user to to collect their own interested statistics of
  // the tables.
  // Default: emtpy vector -- no user-defined statistics collection will be
  // performed.
420 421 422 423 424 425 426 427 428 429 430
  typedef std::vector<std::shared_ptr<TablePropertiesCollector>>
      TablePropertiesCollectors;
  TablePropertiesCollectors table_properties_collectors;

  // Allows thread-safe inplace updates.
  // If inplace_callback function is not set,
  //   Put(key, new_value) will update inplace the existing_value iff
  //   * key exists in current memtable
  //   * new sizeof(new_value) <= sizeof(existing_value)
  //   * existing_value for that key is a put i.e. kTypeValue
  // If inplace_callback function is set, check doc for inplace_callback.
431 432 433 434 435 436 437
  // Default: false.
  bool inplace_update_support;

  // Number of locks used for inplace update
  // Default: 10000, if inplace_update_support = true, else 0.
  size_t inplace_update_num_locks;

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
  // existing_value - pointer to previous value (from both memtable and sst).
  //                  nullptr if key doesn't exist
  // existing_value_size - pointer to size of existing_value).
  //                       nullptr if key doesn't exist
  // delta_value - Delta value to be merged with the existing_value.
  //               Stored in transaction logs.
  // merged_value - Set when delta is applied on the previous value.

  // Applicable only when inplace_update_support is true,
  // this callback function is called at the time of updating the memtable
  // as part of a Put operation, lets say Put(key, delta_value). It allows the
  // 'delta_value' specified as part of the Put operation to be merged with
  // an 'existing_value' of the key in the database.

  // If the merged value is smaller in size that the 'existing_value',
  // then this function can update the 'existing_value' buffer inplace and
  // the corresponding 'existing_value'_size pointer, if it wishes to.
  // The callback should return UpdateStatus::UPDATED_INPLACE.
  // In this case. (In this case, the snapshot-semantics of the rocksdb
  // Iterator is not atomic anymore).

  // If the merged value is larger in size than the 'existing_value' or the
  // application does not wish to modify the 'existing_value' buffer inplace,
  // then the merged value should be returned via *merge_value. It is set by
  // merging the 'existing_value' and the Put 'delta_value'. The callback should
  // return UpdateStatus::UPDATED in this case. This merged value will be added
  // to the memtable.

  // If merging fails or the application does not wish to take any action,
  // then the callback should return UpdateStatus::UPDATE_FAILED.

  // Please remember that the original call from the application is Put(key,
  // delta_value). So the transaction log (if enabled) will still contain (key,
  // delta_value). The 'merged_value' is not stored in the transaction log.
  // Hence the inplace_callback function should be consistent across db reopens.

  // Default: nullptr
  UpdateStatus (*inplace_callback)(char* existing_value,
                                   uint32_t* existing_value_size,
                                   Slice delta_value,
                                   std::string* merged_value);

  // if prefix_extractor is set and bloom_bits is not 0, create prefix bloom
  // for memtable
  uint32_t memtable_prefix_bloom_bits;

  // number of hash probes per key
  uint32_t memtable_prefix_bloom_probes;

487 488 489 490 491 492 493 494 495 496 497
  // Maximum number of successive merge operations on a key in the memtable.
  //
  // When a merge operation is added to the memtable and the maximum number of
  // successive merges is reached, the value of the key will be calculated and
  // inserted into the memtable instead of the merge operation. This will
  // ensure that there are never more than max_successive_merges merge
  // operations in the memtable.
  //
  // Default: 0 (disabled)
  size_t max_successive_merges;

498 499
  // Create ColumnFamilyOptions with default values for all fields
  ColumnFamilyOptions();
500 501
  // Create ColumnFamilyOptions from Options
  explicit ColumnFamilyOptions(const Options& options);
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
};

struct DBOptions {
  // If true, the database will be created if it is missing.
  // Default: false
  bool create_if_missing;

  // If true, an error is raised if the database already exists.
  // Default: false
  bool error_if_exists;

  // If true, the implementation will do aggressive checking of the
  // data it is processing and will stop early if it detects any
  // errors.  This may have unforeseen ramifications: for example, a
  // corruption of one DB entry may cause a large number of entries to
  // become unreadable or for the entire DB to become unopenable.
  // If any of the  writes to the database fails (Put, Delete, Merge, Write),
  // the database will switch to read-only mode and fail all other
  // Write operations.
  // Default: false
  bool paranoid_checks;

  // Use the specified object to interact with the environment,
  // e.g. to read/write files, schedule background work, etc.
  // Default: Env::Default()
  Env* env;

529 530 531 532 533 534
  // Any internal progress/error information generated by the db will
  // be written to info_log if it is non-nullptr, or to a file stored
  // in the same directory as the DB contents if info_log is nullptr.
  // Default: nullptr
  shared_ptr<Logger> info_log;

535
  // Number of open files that can be used by the DB.  You may need to
536 537 538 539
  // increase this if your database has a large working set. Value -1 means
  // files opened are always kept open. You can estimate number of files based
  // on target_file_size_base and target_file_size_multiplier for level-based
  // compaction. For universal-style compaction, you can usually set it to -1.
540 541 542
  // Default: 1000
  int max_open_files;

543 544 545 546 547
  // If non-null, then we should collect metrics about database operations
  // Statistics objects should not be shared between DB instances as
  // it does not use any locks to prevent concurrent updates.
  shared_ptr<Statistics> statistics;

548 549 550 551 552 553 554 555
  // If true, then the contents of data files are not synced
  // to stable storage. Their contents remain in the OS buffers till the
  // OS decides to flush them. This option is good for bulk-loading
  // of data. Once the bulk-loading is complete, please issue a
  // sync to the OS to flush all dirty buffesrs to stable storage.
  // Default: false
  bool disableDataSync;

556 557 558
  // If true, then every store to stable storage will issue a fsync.
  // If false, then every store to stable storage will issue a fdatasync.
  // This parameter should be set to true while storing data to
I
Igor Canadi 已提交
559
  // filesystem like ext3 that can lose files after a reboot.
560 561 562
  // Default: false
  bool use_fsync;

563 564 565 566 567 568
  // This number controls how often a new scribe log about
  // db deploy stats is written out.
  // -1 indicates no logging at all.
  // Default value is 1800 (half an hour).
  int db_stats_log_interval;

569
  // This specifies the info LOG dir.
H
heyongqiang 已提交
570 571 572 573 574 575
  // If it is empty, the log files will be in the same dir as data.
  // If it is non empty, the log files will be in the specified dir,
  // and the db data dir's absolute path will be used as the log file
  // name's prefix.
  std::string db_log_dir;

576 577 578 579 580 581 582 583
  // This specifies the absolute dir path for write-ahead logs (WAL).
  // If it is empty, the log files will be in the same dir as data,
  //   dbname is used as the data dir by default
  // If it is non empty, the log files will be in kept the specified dir.
  // When destroying the db,
  //   all log files in wal_dir and the dir itself is deleted
  std::string wal_dir;

584
  // The periodicity when obsolete files get deleted. The default
I
Igor Canadi 已提交
585 586 587
  // value is 6 hours. The files that get out of scope by compaction
  // process will still get automatically delete on every compaction,
  // regardless of this setting
588
  uint64_t delete_obsolete_files_period_micros;
A
Abhishek Kona 已提交
589

590 591 592 593 594
  // Maximum number of concurrent background compaction jobs, submitted to
  // the default LOW priority thread pool.
  // If you're increasing this, also consider increasing number of threads in
  // LOW priority thread pool. For more information, see
  // Env::SetBackgroundThreads
595 596
  // Default: 1
  int max_background_compactions;
597

598 599
  // Maximum number of concurrent background memtable flush jobs, submitted to
  // the HIGH priority thread pool.
600
  //
601 602 603 604 605 606 607
  // By default, all background jobs (major compaction and memtable flush) go
  // to the LOW priority pool. If this option is set to a positive number,
  // memtable flush jobs will be submitted to the HIGH priority pool.
  // It is important when the same Env is shared by multiple db instances.
  // Without a separate pool, long running major compaction jobs could
  // potentially block memtable flush jobs of other db instances, leading to
  // unnecessary Put stalls.
608 609 610 611 612
  //
  // If you're increasing this, also consider increasing number of threads in
  // HIGH priority thread pool. For more information, see
  // Env::SetBackgroundThreads
  // Default: 1
613 614
  int max_background_flushes;

615 616 617 618 619 620 621
  // Specify the maximal size of the info log file. If the log file
  // is larger than `max_log_file_size`, a new info log file will
  // be created.
  // If max_log_file_size == 0, all logs will be written to one
  // log file.
  size_t max_log_file_size;

K
Kai Liu 已提交
622 623 624 625 626 627 628 629 630 631
  // Time for the info log file to roll (in seconds).
  // If specified with non-zero value, log file will be rolled
  // if it has been active longer than `log_file_time_to_roll`.
  // Default: 0 (disabled)
  size_t log_file_time_to_roll;

  // Maximal info log files to be kept.
  // Default: 1000
  size_t keep_log_file_num;

A
Abhishek Kona 已提交
632 633 634 635 636
  // manifest file is rolled over on reaching this limit.
  // The older manifest file be deleted.
  // The default value is MAX_INT so that roll-over does not take place.
  uint64_t max_manifest_file_size;

637 638 639 640 641 642 643 644 645 646 647 648
  // Number of shards used for table cache.
  int table_cache_numshardbits;

  // During data eviction of table's LRU cache, it would be inefficient
  // to strictly follow LRU because this piece of memory will not really
  // be released unless its refcount falls to zero. Instead, make two
  // passes: the first pass will release items with refcount = 1,
  // and if not enough space releases after scanning the number of
  // elements specified by this parameter, we will remove items in LRU
  // order.
  int table_cache_remove_scan_count_limit;

649 650 651 652 653 654 655 656
  // The following two fields affect how archived logs will be deleted.
  // 1. If both set to 0, logs will be deleted asap and will not get into
  //    the archive.
  // 2. If WAL_ttl_seconds is 0 and WAL_size_limit_MB is not 0,
  //    WAL files will be checked every 10 min and if total size is greater
  //    then WAL_size_limit_MB, they will be deleted starting with the
  //    earliest until size_limit is met. All empty files will be deleted.
  // 3. If WAL_ttl_seconds is not 0 and WAL_size_limit_MB is 0, then
I
Igor Canadi 已提交
657
  //    WAL files will be checked every WAL_ttl_secondsi / 2 and those that
658 659 660
  //    are older than WAL_ttl_seconds will be deleted.
  // 4. If both are not 0, WAL files will be checked every 10 min and both
  //    checks will be performed with ttl being first.
661
  uint64_t WAL_ttl_seconds;
662
  uint64_t WAL_size_limit_MB;
663 664 665 666 667 668

  // Number of bytes to preallocate (via fallocate) the manifest
  // files.  Default is 4mb, which is reasonable to reduce random IO
  // as well as prevent overallocation for mounts that preallocate
  // large amounts of data (such as xfs's allocsize option).
  size_t manifest_preallocation_size;
669

670 671 672 673
  // Data being read from file storage may be buffered in the OS
  // Default: true
  bool allow_os_buffer;

674
  // Allow the OS to mmap file for reading sst tables. Default: false
675 676 677 678
  bool allow_mmap_reads;

  // Allow the OS to mmap file for writing. Default: true
  bool allow_mmap_writes;
679 680 681

  // Disable child process inherit open files. Default: true
  bool is_fd_close_on_exec;
682 683 684 685 686 687

  // Skip log corruption error on recovery (If client is ok with
  // losing most recent changes)
  // Default: false
  bool skip_log_error_on_recovery;

688
  // if not zero, dump rocksdb.stats to LOG every stats_dump_period_sec
689 690
  // Default: 3600 (1 hour)
  unsigned int stats_dump_period_sec;
691

692 693 694 695 696 697 698 699
  // If set true, will hint the underlying file system that the file
  // access pattern is random, when a sst file is opened.
  // Default: true
  bool advise_random_on_open;

  // Specify the file access pattern once a compaction is started.
  // It will be applied to all input files of a compaction.
  // Default: NORMAL
700 701 702 703 704 705
  enum {
    NONE,
    NORMAL,
    SEQUENTIAL,
    WILLNEED
  } access_hint_on_compaction_start;
H
Haobo Xu 已提交
706 707 708 709 710 711 712 713

  // Use adaptive mutex, which spins in the user space before resorting
  // to kernel. This could reduce context switch when the mutex is not
  // heavily contended. However, if the mutex is hot, we could end up
  // wasting spin time.
  // Default: false
  bool use_adaptive_mutex;

H
Haobo Xu 已提交
714 715 716 717 718 719
  // Allows OS to incrementally sync files to disk while they are being
  // written, asynchronously, in the background.
  // Issue one request for every bytes_per_sync written. 0 turns it off.
  // Default: 0
  uint64_t bytes_per_sync;

720 721
  // Create DBOptions with default values for all fields
  DBOptions();
722 723
  // Create DBOptions from Options
  explicit DBOptions(const Options& options);
724
};
725

726 727 728 729 730 731
// Options to control the behavior of a database (passed to DB::Open)
struct Options : public DBOptions, public ColumnFamilyOptions {
  // Create an Options object with default values for all fields.
  Options() :
    DBOptions(),
    ColumnFamilyOptions() {}
S
Siying Dong 已提交
732

733 734 735
  Options(const DBOptions& db_options,
          const ColumnFamilyOptions& column_family_options)
      : DBOptions(db_options), ColumnFamilyOptions(column_family_options) {}
736

737
  void Dump(Logger* log) const;
738

739 740 741 742 743 744 745 746
  // Set appropriate parameters for bulk loading.
  // The reason that this is a function that returns "this" instead of a
  // constructor is to enable chaining of multiple similar calls in the future.
  //
  // All data will be in level 0 without any automatic compaction.
  // It's recommended to manually call CompactRange(NULL, NULL) before reading
  // from the database, because otherwise the read can be very slow.
  Options* PrepareForBulkLoad();
J
jorlow@chromium.org 已提交
747 748
};

749 750 751 752 753 754 755 756
//
// An application can issue a read request (via Get/Iterators) and specify
// if that read should process data that ALREADY resides on a specified cache
// level. For example, if an application specifies kBlockCacheTier then the
// Get call will process data that is already processed in the memtable or
// the block cache. It will not page in data from the OS cache or data that
// resides in storage.
enum ReadTier {
757
  kReadAllTier = 0x0,    // data in memtable, block cache, OS cache or storage
758 759 760
  kBlockCacheTier = 0x1  // data in memtable or block cache
};

J
jorlow@chromium.org 已提交
761 762 763 764
// Options that control read operations
struct ReadOptions {
  // If true, all data read from underlying storage will be
  // verified against corresponding checksums.
765
  // Default: true
J
jorlow@chromium.org 已提交
766 767
  bool verify_checksums;

K
Kai Liu 已提交
768 769
  // Should the "data block"/"index block"/"filter block" read for this
  // iteration be cached in memory?
J
jorlow@chromium.org 已提交
770 771 772 773
  // Callers may wish to set this field to false for bulk scans.
  // Default: true
  bool fill_cache;

774 775 776 777
  // If this option is set and memtable implementation allows, Seek
  // might only return keys with the same prefix as the seek-key
  bool prefix_seek;

A
Abhishek Kona 已提交
778
  // If "snapshot" is non-nullptr, read as of the supplied snapshot
J
jorlow@chromium.org 已提交
779
  // (which must belong to the DB that is being read and which must
A
Abhishek Kona 已提交
780
  // not have been released).  If "snapshot" is nullptr, use an impliicit
J
jorlow@chromium.org 已提交
781
  // snapshot of the state at the beginning of this read operation.
A
Abhishek Kona 已提交
782
  // Default: nullptr
J
jorlow@chromium.org 已提交
783 784
  const Snapshot* snapshot;

T
Tyler Harter 已提交
785 786 787 788 789 790 791 792 793 794 795 796 797
  // If "prefix" is non-nullptr, and ReadOptions is being passed to
  // db.NewIterator, only return results when the key begins with this
  // prefix.  This field is ignored by other calls (e.g., Get).
  // Options.prefix_extractor must also be set, and
  // prefix_extractor.InRange(prefix) must be true.  The iterator
  // returned by NewIterator when this option is set will behave just
  // as if the underlying store did not contain any non-matching keys,
  // with two exceptions.  Seek() only accepts keys starting with the
  // prefix, and SeekToLast() is not supported.  prefix filter with this
  // option will sometimes reduce the number of read IOPs.
  // Default: nullptr
  const Slice* prefix;

798 799
  // Specify if this read request should process data that ALREADY
  // resides on a particular cache. If the required data is not
800
  // found at the specified cache, then Status::Incomplete is returned.
801 802 803
  // Default: kReadAllTier
  ReadTier read_tier;

T
Tomislav Novak 已提交
804 805
  // Specify to create a tailing iterator -- a special iterator that has a
  // view of the complete database (i.e. it can also be used to read newly
806 807 808
  // added data) and is optimized for sequential reads. It will return records
  // that were inserted into the database after the creation of the iterator.
  // Default: false
T
Tomislav Novak 已提交
809 810
  bool tailing;

J
jorlow@chromium.org 已提交
811
  ReadOptions()
812
      : verify_checksums(true),
J
jorlow@chromium.org 已提交
813
        fill_cache(true),
814
        prefix_seek(false),
T
Tyler Harter 已提交
815
        snapshot(nullptr),
816
        prefix(nullptr),
T
Tomislav Novak 已提交
817 818
        read_tier(kReadAllTier),
        tailing(false) {}
819 820 821 822 823 824
  ReadOptions(bool cksum, bool cache)
      : verify_checksums(cksum),
        fill_cache(cache),
        prefix_seek(false),
        snapshot(nullptr),
        prefix(nullptr),
T
Tomislav Novak 已提交
825 826
        read_tier(kReadAllTier),
        tailing(false) {}
J
jorlow@chromium.org 已提交
827 828 829 830 831 832 833 834 835 836 837 838 839 840
};

// Options that control write operations
struct WriteOptions {
  // If true, the write will be flushed from the operating system
  // buffer cache (by calling WritableFile::Sync()) before the write
  // is considered complete.  If this flag is true, writes will be
  // slower.
  //
  // If this flag is false, and the machine crashes, some recent
  // writes may be lost.  Note that if it is just the process that
  // crashes (i.e., the machine does not reboot), no writes will be
  // lost even if sync==false.
  //
841 842 843
  // In other words, a DB write with sync==false has similar
  // crash semantics as the "write()" system call.  A DB write
  // with sync==true has similar crash semantics to a "write()"
I
Igor Canadi 已提交
844
  // system call followed by "fdatasync()".
845 846
  //
  // Default: false
J
jorlow@chromium.org 已提交
847 848
  bool sync;

H
heyongqiang 已提交
849 850 851 852
  // If true, writes will not first go to the write ahead log,
  // and the write may got lost after a crash.
  bool disableWAL;

853
  WriteOptions() : sync(false), disableWAL(false) {}
J
jorlow@chromium.org 已提交
854 855
};

H
heyongqiang 已提交
856 857 858 859 860 861
// Options that control flush operations
struct FlushOptions {
  // If true, the flush will wait until the flush is done.
  // Default: true
  bool wait;

862
  FlushOptions() : wait(true) {}
H
heyongqiang 已提交
863 864
};

865 866
}  // namespace rocksdb

867
#endif  // STORAGE_ROCKSDB_INCLUDE_OPTIONS_H_