]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
2 | // This source code is licensed under both the GPLv2 (found in the |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
7c673cae | 5 | |
11fdf7f2 | 6 | #pragma once |
7c673cae | 7 | |
7c673cae | 8 | #include <climits> |
1e59de90 | 9 | #include <cstdint> |
7c673cae FG |
10 | #include <vector> |
11 | ||
1e59de90 TL |
12 | #include "rocksdb/rocksdb_namespace.h" |
13 | ||
f67539c2 | 14 | namespace ROCKSDB_NAMESPACE { |
7c673cae FG |
15 | |
16 | // | |
17 | // Algorithm used to make a compaction request stop picking new files | |
18 | // into a single compaction run | |
19 | // | |
20 | enum CompactionStopStyle { | |
494da23a TL |
21 | kCompactionStopStyleSimilarSize, // pick files of similar size |
22 | kCompactionStopStyleTotalSize // total size of picked files > next file | |
7c673cae FG |
23 | }; |
24 | ||
25 | class CompactionOptionsUniversal { | |
26 | public: | |
11fdf7f2 | 27 | // Percentage flexibility while comparing file size. If the candidate file(s) |
7c673cae FG |
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; | |
31 | ||
32 | // The minimum number of files in a single compaction run. Default: 2 | |
33 | unsigned int min_merge_width; | |
34 | ||
35 | // The maximum number of files in a single compaction run. Default: UINT_MAX | |
36 | unsigned int max_merge_width; | |
37 | ||
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 | |
1e59de90 | 41 | // contains 100 bytes of user-data may occupy up to 102 bytes of |
7c673cae FG |
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. | |
1e59de90 | 46 | // Default: 200, which means that a 100 byte database could require up to |
7c673cae FG |
47 | // 300 bytes of storage. |
48 | unsigned int max_size_amplification_percent; | |
49 | ||
50 | // If this option is set to be -1 (the default value), all the output files | |
51 | // will follow compression type specified. | |
52 | // | |
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 | |
1e59de90 | 62 | // well as the total size of C1...Ct as total_C, the compaction output file |
7c673cae FG |
63 | // will be compressed iff |
64 | // total_C / total_size < this percentage | |
65 | // Default: -1 | |
66 | int compression_size_percent; | |
67 | ||
68 | // The algorithm used to stop picking files into a single compaction run | |
69 | // Default: kCompactionStopStyleTotalSize | |
70 | CompactionStopStyle stop_style; | |
71 | ||
72 | // Option to optimize the universal multi level compaction by enabling | |
73 | // trivial move for non overlapping files. | |
74 | // Default: false | |
75 | bool allow_trivial_move; | |
76 | ||
1e59de90 TL |
77 | // EXPERIMENTAL |
78 | // If true, try to limit compaction size under max_compaction_bytes. | |
79 | // This might cause higher write amplification, but can prevent some | |
80 | // problem caused by large compactions. | |
81 | // Default: false | |
82 | bool incremental; | |
83 | ||
7c673cae FG |
84 | // Default set of parameters |
85 | CompactionOptionsUniversal() | |
86 | : size_ratio(1), | |
87 | min_merge_width(2), | |
88 | max_merge_width(UINT_MAX), | |
89 | max_size_amplification_percent(200), | |
90 | compression_size_percent(-1), | |
91 | stop_style(kCompactionStopStyleTotalSize), | |
1e59de90 TL |
92 | allow_trivial_move(false), |
93 | incremental(false) {} | |
7c673cae FG |
94 | }; |
95 | ||
f67539c2 | 96 | } // namespace ROCKSDB_NAMESPACE |