]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/CompactionOptionsUniversal.java
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / CompactionOptionsUniversal.java
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 package org.rocksdb;
7
8 /**
9 * Options for Universal Compaction
10 */
11 public class CompactionOptionsUniversal extends RocksObject {
12
13 public CompactionOptionsUniversal() {
14 super(newCompactionOptionsUniversal());
15 }
16
17 /**
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
20 * this candidate set.
21 *
22 * Default: 1
23 *
24 * @param sizeRatio The size ratio to use
25 *
26 * @return the reference to the current options.
27 */
28 public CompactionOptionsUniversal setSizeRatio(final int sizeRatio) {
29 setSizeRatio(nativeHandle_, sizeRatio);
30 return this;
31 }
32
33 /**
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
36 * this candidate set.
37 *
38 * Default: 1
39 *
40 * @return The size ratio in use
41 */
42 public int sizeRatio() {
43 return sizeRatio(nativeHandle_);
44 }
45
46 /**
47 * The minimum number of files in a single compaction run.
48 *
49 * Default: 2
50 *
51 * @param minMergeWidth minimum number of files in a single compaction run
52 *
53 * @return the reference to the current options.
54 */
55 public CompactionOptionsUniversal setMinMergeWidth(final int minMergeWidth) {
56 setMinMergeWidth(nativeHandle_, minMergeWidth);
57 return this;
58 }
59
60 /**
61 * The minimum number of files in a single compaction run.
62 *
63 * Default: 2
64 *
65 * @return minimum number of files in a single compaction run
66 */
67 public int minMergeWidth() {
68 return minMergeWidth(nativeHandle_);
69 }
70
71 /**
72 * The maximum number of files in a single compaction run.
73 *
74 * Default: {@link Long#MAX_VALUE}
75 *
76 * @param maxMergeWidth maximum number of files in a single compaction run
77 *
78 * @return the reference to the current options.
79 */
80 public CompactionOptionsUniversal setMaxMergeWidth(final int maxMergeWidth) {
81 setMaxMergeWidth(nativeHandle_, maxMergeWidth);
82 return this;
83 }
84
85 /**
86 * The maximum number of files in a single compaction run.
87 *
88 * Default: {@link Long#MAX_VALUE}
89 *
90 * @return maximum number of files in a single compaction run
91 */
92 public int maxMergeWidth() {
93 return maxMergeWidth(nativeHandle_);
94 }
95
96 /**
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.
105 *
106 * Default: 200, which means that a 100 byte database could require upto
107 * 300 bytes of storage.
108 *
109 * @param maxSizeAmplificationPercent the amount of additional storage needed
110 * (as a percentage) to store a single byte in the database
111 *
112 * @return the reference to the current options.
113 */
114 public CompactionOptionsUniversal setMaxSizeAmplificationPercent(
115 final int maxSizeAmplificationPercent) {
116 setMaxSizeAmplificationPercent(nativeHandle_, maxSizeAmplificationPercent);
117 return this;
118 }
119
120 /**
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.
129 *
130 * Default: 200, which means that a 100 byte database could require upto
131 * 300 bytes of storage.
132 *
133 * @return the amount of additional storage needed (as a percentage) to store
134 * a single byte in the database
135 */
136 public int maxSizeAmplificationPercent() {
137 return maxSizeAmplificationPercent(nativeHandle_);
138 }
139
140 /**
141 * If this option is set to be -1 (the default value), all the output files
142 * will follow compression type specified.
143 *
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.
147 *
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
157 *
158 * Default: -1
159 *
160 * @param compressionSizePercent percentage of size for compression
161 *
162 * @return the reference to the current options.
163 */
164 public CompactionOptionsUniversal setCompressionSizePercent(
165 final int compressionSizePercent) {
166 setCompressionSizePercent(nativeHandle_, compressionSizePercent);
167 return this;
168 }
169
170 /**
171 * If this option is set to be -1 (the default value), all the output files
172 * will follow compression type specified.
173 *
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.
177 *
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
187 *
188 * Default: -1
189 *
190 * @return percentage of size for compression
191 */
192 public int compressionSizePercent() {
193 return compressionSizePercent(nativeHandle_);
194 }
195
196 /**
197 * The algorithm used to stop picking files into a single compaction run
198 *
199 * Default: {@link CompactionStopStyle#CompactionStopStyleTotalSize}
200 *
201 * @param compactionStopStyle The compaction algorithm
202 *
203 * @return the reference to the current options.
204 */
205 public CompactionOptionsUniversal setStopStyle(
206 final CompactionStopStyle compactionStopStyle) {
207 setStopStyle(nativeHandle_, compactionStopStyle.getValue());
208 return this;
209 }
210
211 /**
212 * The algorithm used to stop picking files into a single compaction run
213 *
214 * Default: {@link CompactionStopStyle#CompactionStopStyleTotalSize}
215 *
216 * @return The compaction algorithm
217 */
218 public CompactionStopStyle stopStyle() {
219 return CompactionStopStyle.getCompactionStopStyle(stopStyle(nativeHandle_));
220 }
221
222 /**
223 * Option to optimize the universal multi level compaction by enabling
224 * trivial move for non overlapping files.
225 *
226 * Default: false
227 *
228 * @param allowTrivialMove true if trivial move is allowed
229 *
230 * @return the reference to the current options.
231 */
232 public CompactionOptionsUniversal setAllowTrivialMove(
233 final boolean allowTrivialMove) {
234 setAllowTrivialMove(nativeHandle_, allowTrivialMove);
235 return this;
236 }
237
238 /**
239 * Option to optimize the universal multi level compaction by enabling
240 * trivial move for non overlapping files.
241 *
242 * Default: false
243 *
244 * @return true if trivial move is allowed
245 */
246 public boolean allowTrivialMove() {
247 return allowTrivialMove(nativeHandle_);
248 }
249
250 private native static long newCompactionOptionsUniversal();
251 @Override protected final native void disposeInternal(final long handle);
252
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);
273 }