1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
6 #ifndef STORAGE_ROCKSDB_UNIVERSAL_COMPACTION_OPTIONS_H
7 #define STORAGE_ROCKSDB_UNIVERSAL_COMPACTION_OPTIONS_H
16 // Algorithm used to make a compaction request stop picking new files
17 // into a single compaction run
19 enum CompactionStopStyle
{
20 kCompactionStopStyleSimilarSize
, // pick files of similar size
21 kCompactionStopStyleTotalSize
// total size of picked files > next file
24 class CompactionOptionsUniversal
{
27 // Percentage flexibilty while comparing file size. If the candidate file(s)
28 // size is 1% smaller than the next file's size, then include next file into
29 // this candidate set. // Default: 1
30 unsigned int size_ratio
;
32 // The minimum number of files in a single compaction run. Default: 2
33 unsigned int min_merge_width
;
35 // The maximum number of files in a single compaction run. Default: UINT_MAX
36 unsigned int max_merge_width
;
38 // The size amplification is defined as the amount (in percentage) of
39 // additional storage needed to store a single byte of data in the database.
40 // For example, a size amplification of 2% means that a database that
41 // contains 100 bytes of user-data may occupy upto 102 bytes of
42 // physical storage. By this definition, a fully compacted database has
43 // a size amplification of 0%. Rocksdb uses the following heuristic
44 // to calculate size amplification: it assumes that all files excluding
45 // the earliest file contribute to the size amplification.
46 // Default: 200, which means that a 100 byte database could require upto
47 // 300 bytes of storage.
48 unsigned int max_size_amplification_percent
;
50 // If this option is set to be -1 (the default value), all the output files
51 // will follow compression type specified.
53 // If this option is not negative, we will try to make sure compressed
54 // size is just above this value. In normal cases, at least this percentage
55 // of data will be compressed.
56 // When we are compacting to a new file, here is the criteria whether
57 // it needs to be compressed: assuming here are the list of files sorted
58 // by generation time:
59 // A1...An B1...Bm C1...Ct
60 // where A1 is the newest and Ct is the oldest, and we are going to compact
61 // B1...Bm, we calculate the total size of all the files as total_size, as
62 // well as the total size of C1...Ct as total_C, the compaction output file
63 // will be compressed iff
64 // total_C / total_size < this percentage
66 int compression_size_percent
;
68 // The algorithm used to stop picking files into a single compaction run
69 // Default: kCompactionStopStyleTotalSize
70 CompactionStopStyle stop_style
;
72 // Option to optimize the universal multi level compaction by enabling
73 // trivial move for non overlapping files.
75 bool allow_trivial_move
;
77 // Default set of parameters
78 CompactionOptionsUniversal()
81 max_merge_width(UINT_MAX
),
82 max_size_amplification_percent(200),
83 compression_size_percent(-1),
84 stop_style(kCompactionStopStyleTotalSize
),
85 allow_trivial_move(false) {}
88 } // namespace rocksdb
90 #endif // STORAGE_ROCKSDB_UNIVERSAL_COMPACTION_OPTIONS_H