/Users/deen/code/yugabyte-db/src/yb/rocksdb/universal_compaction.h
Line | Count | Source |
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. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | |
21 | | #ifndef YB_ROCKSDB_UNIVERSAL_COMPACTION_H |
22 | | #define YB_ROCKSDB_UNIVERSAL_COMPACTION_H |
23 | | |
24 | | #include <climits> |
25 | | |
26 | | #include "yb/util/size_literals.h" |
27 | | |
28 | | using yb::operator"" _MB; |
29 | | |
30 | | namespace rocksdb { |
31 | | |
32 | | // |
33 | | // Algorithm used to make a compaction request stop picking new files |
34 | | // into a single compaction run |
35 | | // |
36 | | enum CompactionStopStyle { |
37 | | kCompactionStopStyleSimilarSize, // pick files of similar size |
38 | | kCompactionStopStyleTotalSize // total size of picked files > next file |
39 | | }; |
40 | | |
41 | | class CompactionOptionsUniversal { |
42 | | public: |
43 | | |
44 | | // Percentage flexibilty while comparing file size. If the candidate file(s) |
45 | | // size is 1% smaller than the next file's size, then include next file into |
46 | | // this candidate set. // Default: 1 |
47 | | unsigned int size_ratio; |
48 | | |
49 | | // Always include files with size less or equal to always_include_threshold into candidate set. |
50 | | size_t always_include_size_threshold = 0; |
51 | | |
52 | | // The minimum number of files in a single compaction run. Default: 2 |
53 | | unsigned int min_merge_width; |
54 | | |
55 | | // The maximum number of files in a single compaction run. Default: UINT_MAX |
56 | | unsigned int max_merge_width; |
57 | | |
58 | | // The size amplification is defined as the amount (in percentage) of |
59 | | // additional storage needed to store a single byte of data in the database. |
60 | | // For example, a size amplification of 2% means that a database that |
61 | | // contains 100 bytes of user-data may occupy upto 102 bytes of |
62 | | // physical storage. By this definition, a fully compacted database has |
63 | | // a size amplification of 0%. Rocksdb uses the following heuristic |
64 | | // to calculate size amplification: it assumes that all files excluding |
65 | | // the earliest file contribute to the size amplification. |
66 | | // Default: 200, which means that a 100 byte database could require upto |
67 | | // 300 bytes of storage. |
68 | | unsigned int max_size_amplification_percent; |
69 | | |
70 | | // If this option is set to be -1 (the default value), all the output files |
71 | | // will follow compression type specified. |
72 | | // |
73 | | // If this option is not negative, we will try to make sure compressed |
74 | | // size is just above this value. In normal cases, at least this percentage |
75 | | // of data will be compressed. |
76 | | // When we are compacting to a new file, here is the criteria whether |
77 | | // it needs to be compressed: assuming here are the list of files sorted |
78 | | // by generation time: |
79 | | // A1...An B1...Bm C1...Ct |
80 | | // where A1 is the newest and Ct is the oldest, and we are going to compact |
81 | | // B1...Bm, we calculate the total size of all the files as total_size, as |
82 | | // well as the total size of C1...Ct as total_C, the compaction output file |
83 | | // will be compressed iff |
84 | | // total_C / total_size < this percentage |
85 | | // Default: -1 |
86 | | int compression_size_percent; |
87 | | |
88 | | // The algorithm used to stop picking files into a single compaction run |
89 | | // Default: kCompactionStopStyleTotalSize |
90 | | CompactionStopStyle stop_style; |
91 | | |
92 | | // Option to optimize the universal multi level compaction by enabling |
93 | | // trivial move for non overlapping files. |
94 | | // Default: false |
95 | | bool allow_trivial_move; |
96 | | |
97 | | // Default set of parameters |
98 | | CompactionOptionsUniversal() |
99 | | : size_ratio(1), |
100 | | min_merge_width(2), |
101 | | max_merge_width(UINT_MAX), |
102 | | max_size_amplification_percent(200), |
103 | | compression_size_percent(-1), |
104 | | stop_style(kCompactionStopStyleTotalSize), |
105 | 3.62M | allow_trivial_move(false) {} |
106 | | }; |
107 | | |
108 | | } // namespace rocksdb |
109 | | |
110 | | #endif // YB_ROCKSDB_UNIVERSAL_COMPACTION_H |