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.
9 * Options for Universal Compaction
11 public class CompactionOptionsUniversal
extends RocksObject
{
13 public CompactionOptionsUniversal() {
14 super(newCompactionOptionsUniversal());
18 * Percentage flexibilty while comparing file size. If the candidate file(s)
19 * size is 1% smaller than the next file's size, then include next file into
24 * @param sizeRatio The size ratio to use
26 * @return the reference to the current options.
28 public CompactionOptionsUniversal
setSizeRatio(final int sizeRatio
) {
29 setSizeRatio(nativeHandle_
, sizeRatio
);
34 * Percentage flexibilty while comparing file size. If the candidate file(s)
35 * size is 1% smaller than the next file's size, then include next file into
40 * @return The size ratio in use
42 public int sizeRatio() {
43 return sizeRatio(nativeHandle_
);
47 * The minimum number of files in a single compaction run.
51 * @param minMergeWidth minimum number of files in a single compaction run
53 * @return the reference to the current options.
55 public CompactionOptionsUniversal
setMinMergeWidth(final int minMergeWidth
) {
56 setMinMergeWidth(nativeHandle_
, minMergeWidth
);
61 * The minimum number of files in a single compaction run.
65 * @return minimum number of files in a single compaction run
67 public int minMergeWidth() {
68 return minMergeWidth(nativeHandle_
);
72 * The maximum number of files in a single compaction run.
74 * Default: {@link Long#MAX_VALUE}
76 * @param maxMergeWidth maximum number of files in a single compaction run
78 * @return the reference to the current options.
80 public CompactionOptionsUniversal
setMaxMergeWidth(final int maxMergeWidth
) {
81 setMaxMergeWidth(nativeHandle_
, maxMergeWidth
);
86 * The maximum number of files in a single compaction run.
88 * Default: {@link Long#MAX_VALUE}
90 * @return maximum number of files in a single compaction run
92 public int maxMergeWidth() {
93 return maxMergeWidth(nativeHandle_
);
97 * The size amplification is defined as the amount (in percentage) of
98 * additional storage needed to store a single byte of data in the database.
99 * For example, a size amplification of 2% means that a database that
100 * contains 100 bytes of user-data may occupy upto 102 bytes of
101 * physical storage. By this definition, a fully compacted database has
102 * a size amplification of 0%. Rocksdb uses the following heuristic
103 * to calculate size amplification: it assumes that all files excluding
104 * the earliest file contribute to the size amplification.
106 * Default: 200, which means that a 100 byte database could require upto
107 * 300 bytes of storage.
109 * @param maxSizeAmplificationPercent the amount of additional storage needed
110 * (as a percentage) to store a single byte in the database
112 * @return the reference to the current options.
114 public CompactionOptionsUniversal
setMaxSizeAmplificationPercent(
115 final int maxSizeAmplificationPercent
) {
116 setMaxSizeAmplificationPercent(nativeHandle_
, maxSizeAmplificationPercent
);
121 * The size amplification is defined as the amount (in percentage) of
122 * additional storage needed to store a single byte of data in the database.
123 * For example, a size amplification of 2% means that a database that
124 * contains 100 bytes of user-data may occupy upto 102 bytes of
125 * physical storage. By this definition, a fully compacted database has
126 * a size amplification of 0%. Rocksdb uses the following heuristic
127 * to calculate size amplification: it assumes that all files excluding
128 * the earliest file contribute to the size amplification.
130 * Default: 200, which means that a 100 byte database could require upto
131 * 300 bytes of storage.
133 * @return the amount of additional storage needed (as a percentage) to store
134 * a single byte in the database
136 public int maxSizeAmplificationPercent() {
137 return maxSizeAmplificationPercent(nativeHandle_
);
141 * If this option is set to be -1 (the default value), all the output files
142 * will follow compression type specified.
144 * If this option is not negative, we will try to make sure compressed
145 * size is just above this value. In normal cases, at least this percentage
146 * of data will be compressed.
148 * When we are compacting to a new file, here is the criteria whether
149 * it needs to be compressed: assuming here are the list of files sorted
150 * by generation time:
151 * A1...An B1...Bm C1...Ct
152 * where A1 is the newest and Ct is the oldest, and we are going to compact
153 * B1...Bm, we calculate the total size of all the files as total_size, as
154 * well as the total size of C1...Ct as total_C, the compaction output file
155 * will be compressed iff
156 * total_C / total_size < this percentage
160 * @param compressionSizePercent percentage of size for compression
162 * @return the reference to the current options.
164 public CompactionOptionsUniversal
setCompressionSizePercent(
165 final int compressionSizePercent
) {
166 setCompressionSizePercent(nativeHandle_
, compressionSizePercent
);
171 * If this option is set to be -1 (the default value), all the output files
172 * will follow compression type specified.
174 * If this option is not negative, we will try to make sure compressed
175 * size is just above this value. In normal cases, at least this percentage
176 * of data will be compressed.
178 * When we are compacting to a new file, here is the criteria whether
179 * it needs to be compressed: assuming here are the list of files sorted
180 * by generation time:
181 * A1...An B1...Bm C1...Ct
182 * where A1 is the newest and Ct is the oldest, and we are going to compact
183 * B1...Bm, we calculate the total size of all the files as total_size, as
184 * well as the total size of C1...Ct as total_C, the compaction output file
185 * will be compressed iff
186 * total_C / total_size < this percentage
190 * @return percentage of size for compression
192 public int compressionSizePercent() {
193 return compressionSizePercent(nativeHandle_
);
197 * The algorithm used to stop picking files into a single compaction run
199 * Default: {@link CompactionStopStyle#CompactionStopStyleTotalSize}
201 * @param compactionStopStyle The compaction algorithm
203 * @return the reference to the current options.
205 public CompactionOptionsUniversal
setStopStyle(
206 final CompactionStopStyle compactionStopStyle
) {
207 setStopStyle(nativeHandle_
, compactionStopStyle
.getValue());
212 * The algorithm used to stop picking files into a single compaction run
214 * Default: {@link CompactionStopStyle#CompactionStopStyleTotalSize}
216 * @return The compaction algorithm
218 public CompactionStopStyle
stopStyle() {
219 return CompactionStopStyle
.getCompactionStopStyle(stopStyle(nativeHandle_
));
223 * Option to optimize the universal multi level compaction by enabling
224 * trivial move for non overlapping files.
228 * @param allowTrivialMove true if trivial move is allowed
230 * @return the reference to the current options.
232 public CompactionOptionsUniversal
setAllowTrivialMove(
233 final boolean allowTrivialMove
) {
234 setAllowTrivialMove(nativeHandle_
, allowTrivialMove
);
239 * Option to optimize the universal multi level compaction by enabling
240 * trivial move for non overlapping files.
244 * @return true if trivial move is allowed
246 public boolean allowTrivialMove() {
247 return allowTrivialMove(nativeHandle_
);
250 private native static long newCompactionOptionsUniversal();
251 @Override protected final native void disposeInternal(final long handle
);
253 private native void setSizeRatio(final long handle
, final int sizeRatio
);
254 private native int sizeRatio(final long handle
);
255 private native void setMinMergeWidth(
256 final long handle
, final int minMergeWidth
);
257 private native int minMergeWidth(final long handle
);
258 private native void setMaxMergeWidth(
259 final long handle
, final int maxMergeWidth
);
260 private native int maxMergeWidth(final long handle
);
261 private native void setMaxSizeAmplificationPercent(
262 final long handle
, final int maxSizeAmplificationPercent
);
263 private native int maxSizeAmplificationPercent(final long handle
);
264 private native void setCompressionSizePercent(
265 final long handle
, final int compressionSizePercent
);
266 private native int compressionSizePercent(final long handle
);
267 private native void setStopStyle(
268 final long handle
, final byte stopStyle
);
269 private native byte stopStyle(final long handle
);
270 private native void setAllowTrivialMove(
271 final long handle
, final boolean allowTrivialMove
);
272 private native boolean allowTrivialMove(final long handle
);