]>
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 FG |
5 | |
6 | package org.rocksdb; | |
7 | ||
20effc67 TL |
8 | import java.util.Collection; |
9 | import java.util.List; | |
10 | ||
f67539c2 TL |
11 | public interface ColumnFamilyOptionsInterface<T extends ColumnFamilyOptionsInterface<T>> |
12 | extends AdvancedColumnFamilyOptionsInterface<T> { | |
20effc67 TL |
13 | /** |
14 | * The function recovers options to a previous version. Only 4.6 or later | |
15 | * versions are supported. | |
16 | * | |
1e59de90 TL |
17 | * @param majorVersion The major version to recover default values of options |
18 | * @param minorVersion The minor version to recover default values of options | |
20effc67 TL |
19 | * @return the instance of the current object. |
20 | */ | |
21 | T oldDefaults(int majorVersion, int minorVersion); | |
22 | ||
7c673cae FG |
23 | /** |
24 | * Use this if your DB is very small (like under 1GB) and you don't want to | |
25 | * spend lots of memory for memtables. | |
26 | * | |
27 | * @return the instance of the current object. | |
28 | */ | |
29 | T optimizeForSmallDb(); | |
30 | ||
20effc67 TL |
31 | /** |
32 | * Some functions that make it easier to optimize RocksDB | |
33 | * Use this if your DB is very small (like under 1GB) and you don't want to | |
34 | * spend lots of memory for memtables. | |
20effc67 | 35 | * |
1e59de90 | 36 | * @param cache An optional cache object is passed in to be used as the block cache |
20effc67 TL |
37 | * @return the instance of the current object. |
38 | */ | |
39 | T optimizeForSmallDb(Cache cache); | |
40 | ||
7c673cae FG |
41 | /** |
42 | * Use this if you don't need to keep the data sorted, i.e. you'll never use | |
43 | * an iterator, only Put() and Get() API calls | |
44 | * | |
45 | * @param blockCacheSizeMb Block cache size in MB | |
46 | * @return the instance of the current object. | |
47 | */ | |
48 | T optimizeForPointLookup(long blockCacheSizeMb); | |
49 | ||
50 | /** | |
51 | * <p>Default values for some parameters in ColumnFamilyOptions are not | |
52 | * optimized for heavy workloads and big datasets, which means you might | |
53 | * observe write stalls under some conditions. As a starting point for tuning | |
54 | * RocksDB options, use the following for level style compaction.</p> | |
55 | * | |
56 | * <p>Make sure to also call IncreaseParallelism(), which will provide the | |
57 | * biggest performance gains.</p> | |
58 | * <p>Note: we might use more memory than memtable_memory_budget during high | |
59 | * write rate period</p> | |
60 | * | |
61 | * @return the instance of the current object. | |
62 | */ | |
63 | T optimizeLevelStyleCompaction(); | |
64 | ||
65 | /** | |
66 | * <p>Default values for some parameters in ColumnFamilyOptions are not | |
67 | * optimized for heavy workloads and big datasets, which means you might | |
68 | * observe write stalls under some conditions. As a starting point for tuning | |
69 | * RocksDB options, use the following for level style compaction.</p> | |
70 | * | |
71 | * <p>Make sure to also call IncreaseParallelism(), which will provide the | |
72 | * biggest performance gains.</p> | |
73 | * <p>Note: we might use more memory than memtable_memory_budget during high | |
74 | * write rate period</p> | |
75 | * | |
76 | * @param memtableMemoryBudget memory budget in bytes | |
77 | * @return the instance of the current object. | |
78 | */ | |
79 | T optimizeLevelStyleCompaction( | |
80 | long memtableMemoryBudget); | |
81 | ||
82 | /** | |
83 | * <p>Default values for some parameters in ColumnFamilyOptions are not | |
84 | * optimized for heavy workloads and big datasets, which means you might | |
85 | * observe write stalls under some conditions. As a starting point for tuning | |
86 | * RocksDB options, use the following for universal style compaction.</p> | |
87 | * | |
88 | * <p>Universal style compaction is focused on reducing Write Amplification | |
89 | * Factor for big data sets, but increases Space Amplification.</p> | |
90 | * | |
91 | * <p>Make sure to also call IncreaseParallelism(), which will provide the | |
92 | * biggest performance gains.</p> | |
93 | * | |
94 | * <p>Note: we might use more memory than memtable_memory_budget during high | |
95 | * write rate period</p> | |
96 | * | |
97 | * @return the instance of the current object. | |
98 | */ | |
99 | T optimizeUniversalStyleCompaction(); | |
100 | ||
101 | /** | |
102 | * <p>Default values for some parameters in ColumnFamilyOptions are not | |
103 | * optimized for heavy workloads and big datasets, which means you might | |
104 | * observe write stalls under some conditions. As a starting point for tuning | |
105 | * RocksDB options, use the following for universal style compaction.</p> | |
106 | * | |
107 | * <p>Universal style compaction is focused on reducing Write Amplification | |
108 | * Factor for big data sets, but increases Space Amplification.</p> | |
109 | * | |
110 | * <p>Make sure to also call IncreaseParallelism(), which will provide the | |
111 | * biggest performance gains.</p> | |
112 | * | |
113 | * <p>Note: we might use more memory than memtable_memory_budget during high | |
114 | * write rate period</p> | |
115 | * | |
116 | * @param memtableMemoryBudget memory budget in bytes | |
117 | * @return the instance of the current object. | |
118 | */ | |
119 | T optimizeUniversalStyleCompaction( | |
120 | long memtableMemoryBudget); | |
121 | ||
122 | /** | |
123 | * Set {@link BuiltinComparator} to be used with RocksDB. | |
124 | * | |
125 | * Note: Comparator can be set once upon database creation. | |
126 | * | |
127 | * Default: BytewiseComparator. | |
128 | * @param builtinComparator a {@link BuiltinComparator} type. | |
129 | * @return the instance of the current object. | |
130 | */ | |
131 | T setComparator( | |
132 | BuiltinComparator builtinComparator); | |
133 | ||
134 | /** | |
135 | * Use the specified comparator for key ordering. | |
136 | * | |
137 | * Comparator should not be disposed before options instances using this comparator is | |
138 | * disposed. If dispose() function is not called, then comparator object will be | |
139 | * GC'd automatically. | |
140 | * | |
141 | * Comparator instance can be re-used in multiple options instances. | |
142 | * | |
143 | * @param comparator java instance. | |
144 | * @return the instance of the current object. | |
145 | */ | |
146 | T setComparator( | |
f67539c2 | 147 | AbstractComparator comparator); |
7c673cae FG |
148 | |
149 | /** | |
150 | * <p>Set the merge operator to be used for merging two merge operands | |
151 | * of the same key. The merge function is invoked during | |
152 | * compaction and at lookup time, if multiple key/value pairs belonging | |
153 | * to the same key are found in the database.</p> | |
154 | * | |
155 | * @param name the name of the merge function, as defined by | |
156 | * the MergeOperators factory (see utilities/MergeOperators.h) | |
157 | * The merge function is specified by name and must be one of the | |
158 | * standard merge operators provided by RocksDB. The available | |
159 | * operators are "put", "uint64add", "stringappend" and "stringappendtest". | |
160 | * @return the instance of the current object. | |
161 | */ | |
162 | T setMergeOperatorName(String name); | |
163 | ||
164 | /** | |
165 | * <p>Set the merge operator to be used for merging two different key/value | |
166 | * pairs that share the same key. The merge function is invoked during | |
167 | * compaction and at lookup time, if multiple key/value pairs belonging | |
168 | * to the same key are found in the database.</p> | |
169 | * | |
170 | * @param mergeOperator {@link MergeOperator} instance. | |
171 | * @return the instance of the current object. | |
172 | */ | |
173 | T setMergeOperator(MergeOperator mergeOperator); | |
174 | ||
494da23a TL |
175 | /** |
176 | * A single CompactionFilter instance to call into during compaction. | |
177 | * Allows an application to modify/delete a key-value during background | |
178 | * compaction. | |
179 | * | |
180 | * If the client requires a new compaction filter to be used for different | |
181 | * compaction runs, it can specify call | |
182 | * {@link #setCompactionFilterFactory(AbstractCompactionFilterFactory)} | |
183 | * instead. | |
184 | * | |
185 | * The client should specify only set one of the two. | |
186 | * {@link #setCompactionFilter(AbstractCompactionFilter)} takes precedence | |
187 | * over {@link #setCompactionFilterFactory(AbstractCompactionFilterFactory)} | |
188 | * if the client specifies both. | |
189 | * | |
190 | * If multithreaded compaction is being used, the supplied CompactionFilter | |
191 | * instance may be used from different threads concurrently and so should be thread-safe. | |
192 | * | |
193 | * @param compactionFilter {@link AbstractCompactionFilter} instance. | |
194 | * @return the instance of the current object. | |
195 | */ | |
196 | T setCompactionFilter( | |
197 | final AbstractCompactionFilter<? extends AbstractSlice<?>> compactionFilter); | |
198 | ||
199 | /** | |
200 | * Accessor for the CompactionFilter instance in use. | |
201 | * | |
202 | * @return Reference to the CompactionFilter, or null if one hasn't been set. | |
203 | */ | |
204 | AbstractCompactionFilter<? extends AbstractSlice<?>> compactionFilter(); | |
205 | ||
206 | /** | |
207 | * This is a factory that provides {@link AbstractCompactionFilter} objects | |
208 | * which allow an application to modify/delete a key-value during background | |
209 | * compaction. | |
210 | * | |
211 | * A new filter will be created on each compaction run. If multithreaded | |
212 | * compaction is being used, each created CompactionFilter will only be used | |
213 | * from a single thread and so does not need to be thread-safe. | |
214 | * | |
215 | * @param compactionFilterFactory {@link AbstractCompactionFilterFactory} instance. | |
216 | * @return the instance of the current object. | |
217 | */ | |
218 | T setCompactionFilterFactory( | |
219 | final AbstractCompactionFilterFactory<? extends AbstractCompactionFilter<?>> | |
220 | compactionFilterFactory); | |
221 | ||
222 | /** | |
223 | * Accessor for the CompactionFilterFactory instance in use. | |
224 | * | |
225 | * @return Reference to the CompactionFilterFactory, or null if one hasn't been set. | |
226 | */ | |
227 | AbstractCompactionFilterFactory<? extends AbstractCompactionFilter<?>> compactionFilterFactory(); | |
228 | ||
7c673cae FG |
229 | /** |
230 | * This prefix-extractor uses the first n bytes of a key as its prefix. | |
231 | * | |
232 | * In some hash-based memtable representation such as HashLinkedList | |
233 | * and HashSkipList, prefixes are used to partition the keys into | |
234 | * several buckets. Prefix extractor is used to specify how to | |
235 | * extract the prefix given a key. | |
236 | * | |
237 | * @param n use the first n bytes of a key as its prefix. | |
238 | * @return the reference to the current option. | |
239 | */ | |
240 | T useFixedLengthPrefixExtractor(int n); | |
241 | ||
242 | /** | |
243 | * Same as fixed length prefix extractor, except that when slice is | |
244 | * shorter than the fixed length, it will use the full key. | |
245 | * | |
246 | * @param n use the first n bytes of a key as its prefix. | |
247 | * @return the reference to the current option. | |
248 | */ | |
249 | T useCappedPrefixExtractor(int n); | |
250 | ||
251 | /** | |
252 | * Number of files to trigger level-0 compaction. A value < 0 means that | |
253 | * level-0 compaction will not be triggered by number of files at all. | |
254 | * Default: 4 | |
255 | * | |
256 | * @param numFiles the number of files in level-0 to trigger compaction. | |
257 | * @return the reference to the current option. | |
258 | */ | |
259 | T setLevelZeroFileNumCompactionTrigger( | |
260 | int numFiles); | |
261 | ||
262 | /** | |
263 | * The number of files in level 0 to trigger compaction from level-0 to | |
264 | * level-1. A value < 0 means that level-0 compaction will not be | |
265 | * triggered by number of files at all. | |
266 | * Default: 4 | |
267 | * | |
268 | * @return the number of files in level 0 to trigger compaction. | |
269 | */ | |
270 | int levelZeroFileNumCompactionTrigger(); | |
271 | ||
272 | /** | |
273 | * Soft limit on number of level-0 files. We start slowing down writes at this | |
274 | * point. A value < 0 means that no writing slow down will be triggered by | |
275 | * number of files in level-0. | |
276 | * | |
277 | * @param numFiles soft limit on number of level-0 files. | |
278 | * @return the reference to the current option. | |
279 | */ | |
280 | T setLevelZeroSlowdownWritesTrigger( | |
281 | int numFiles); | |
282 | ||
283 | /** | |
284 | * Soft limit on the number of level-0 files. We start slowing down writes | |
285 | * at this point. A value < 0 means that no writing slow down will be | |
286 | * triggered by number of files in level-0. | |
287 | * | |
288 | * @return the soft limit on the number of level-0 files. | |
289 | */ | |
290 | int levelZeroSlowdownWritesTrigger(); | |
291 | ||
292 | /** | |
293 | * Maximum number of level-0 files. We stop writes at this point. | |
294 | * | |
295 | * @param numFiles the hard limit of the number of level-0 files. | |
296 | * @return the reference to the current option. | |
297 | */ | |
298 | T setLevelZeroStopWritesTrigger(int numFiles); | |
299 | ||
300 | /** | |
301 | * Maximum number of level-0 files. We stop writes at this point. | |
302 | * | |
303 | * @return the hard limit of the number of level-0 file. | |
304 | */ | |
305 | int levelZeroStopWritesTrigger(); | |
306 | ||
307 | /** | |
308 | * The ratio between the total size of level-(L+1) files and the total | |
309 | * size of level-L files for all L. | |
310 | * DEFAULT: 10 | |
311 | * | |
312 | * @param multiplier the ratio between the total size of level-(L+1) | |
313 | * files and the total size of level-L files for all L. | |
314 | * @return the reference to the current option. | |
315 | */ | |
316 | T setMaxBytesForLevelMultiplier( | |
317 | double multiplier); | |
318 | ||
319 | /** | |
320 | * The ratio between the total size of level-(L+1) files and the total | |
321 | * size of level-L files for all L. | |
322 | * DEFAULT: 10 | |
323 | * | |
324 | * @return the ratio between the total size of level-(L+1) files and | |
325 | * the total size of level-L files for all L. | |
326 | */ | |
327 | double maxBytesForLevelMultiplier(); | |
328 | ||
329 | /** | |
330 | * FIFO compaction option. | |
331 | * The oldest table file will be deleted | |
332 | * once the sum of table files reaches this size. | |
333 | * The default value is 1GB (1 * 1024 * 1024 * 1024). | |
334 | * | |
335 | * @param maxTableFilesSize the size limit of the total sum of table files. | |
336 | * @return the instance of the current object. | |
337 | */ | |
338 | T setMaxTableFilesSizeFIFO( | |
339 | long maxTableFilesSize); | |
340 | ||
341 | /** | |
342 | * FIFO compaction option. | |
343 | * The oldest table file will be deleted | |
344 | * once the sum of table files reaches this size. | |
345 | * The default value is 1GB (1 * 1024 * 1024 * 1024). | |
346 | * | |
347 | * @return the size limit of the total sum of table files. | |
348 | */ | |
349 | long maxTableFilesSizeFIFO(); | |
350 | ||
351 | /** | |
352 | * Get the config for mem-table. | |
353 | * | |
354 | * @return the mem-table config. | |
355 | */ | |
356 | MemTableConfig memTableConfig(); | |
357 | ||
358 | /** | |
359 | * Set the config for mem-table. | |
360 | * | |
361 | * @param memTableConfig the mem-table config. | |
362 | * @return the instance of the current object. | |
363 | * @throws java.lang.IllegalArgumentException thrown on 32-Bit platforms | |
364 | * while overflowing the underlying platform specific value. | |
365 | */ | |
366 | T setMemTableConfig(MemTableConfig memTableConfig); | |
367 | ||
368 | /** | |
369 | * Returns the name of the current mem table representation. | |
370 | * Memtable format can be set using setTableFormatConfig. | |
371 | * | |
372 | * @return the name of the currently-used memtable factory. | |
373 | * @see #setTableFormatConfig(org.rocksdb.TableFormatConfig) | |
374 | */ | |
375 | String memTableFactoryName(); | |
376 | ||
377 | /** | |
378 | * Get the config for table format. | |
379 | * | |
380 | * @return the table format config. | |
381 | */ | |
382 | TableFormatConfig tableFormatConfig(); | |
383 | ||
384 | /** | |
385 | * Set the config for table format. | |
386 | * | |
387 | * @param config the table format config. | |
388 | * @return the reference of the current options. | |
389 | */ | |
390 | T setTableFormatConfig(TableFormatConfig config); | |
391 | ||
392 | /** | |
393 | * @return the name of the currently used table factory. | |
394 | */ | |
395 | String tableFactoryName(); | |
396 | ||
20effc67 TL |
397 | /** |
398 | * A list of paths where SST files for this column family | |
399 | * can be put into, with its target size. Similar to db_paths, | |
400 | * newer data is placed into paths specified earlier in the | |
401 | * vector while older data gradually moves to paths specified | |
402 | * later in the vector. | |
403 | * Note that, if a path is supplied to multiple column | |
404 | * families, it would have files and total size from all | |
405 | * the column families combined. User should provision for the | |
406 | * total size(from all the column families) in such cases. | |
407 | * | |
408 | * If left empty, db_paths will be used. | |
409 | * Default: empty | |
410 | * | |
411 | * @param paths collection of paths for SST files. | |
412 | * @return the reference of the current options. | |
413 | */ | |
414 | T setCfPaths(final Collection<DbPath> paths); | |
415 | ||
416 | /** | |
417 | * @return collection of paths for SST files. | |
418 | */ | |
419 | List<DbPath> cfPaths(); | |
420 | ||
7c673cae FG |
421 | /** |
422 | * Compression algorithm that will be used for the bottommost level that | |
423 | * contain files. If level-compaction is used, this option will only affect | |
424 | * levels after base level. | |
425 | * | |
426 | * Default: {@link CompressionType#DISABLE_COMPRESSION_OPTION} | |
427 | * | |
428 | * @param bottommostCompressionType The compression type to use for the | |
429 | * bottommost level | |
430 | * | |
431 | * @return the reference of the current options. | |
432 | */ | |
433 | T setBottommostCompressionType( | |
434 | final CompressionType bottommostCompressionType); | |
435 | ||
436 | /** | |
437 | * Compression algorithm that will be used for the bottommost level that | |
438 | * contain files. If level-compaction is used, this option will only affect | |
439 | * levels after base level. | |
440 | * | |
441 | * Default: {@link CompressionType#DISABLE_COMPRESSION_OPTION} | |
442 | * | |
443 | * @return The compression type used for the bottommost level | |
444 | */ | |
445 | CompressionType bottommostCompressionType(); | |
446 | ||
494da23a TL |
447 | /** |
448 | * Set the options for compression algorithms used by | |
449 | * {@link #bottommostCompressionType()} if it is enabled. | |
450 | * | |
451 | * To enable it, please see the definition of | |
452 | * {@link CompressionOptions}. | |
453 | * | |
454 | * @param compressionOptions the bottom most compression options. | |
455 | * | |
456 | * @return the reference of the current options. | |
457 | */ | |
458 | T setBottommostCompressionOptions( | |
459 | final CompressionOptions compressionOptions); | |
460 | ||
461 | /** | |
462 | * Get the bottom most compression options. | |
463 | * | |
464 | * See {@link #setBottommostCompressionOptions(CompressionOptions)}. | |
465 | * | |
466 | * @return the bottom most compression options. | |
467 | */ | |
468 | CompressionOptions bottommostCompressionOptions(); | |
7c673cae FG |
469 | |
470 | /** | |
471 | * Set the different options for compression algorithms | |
472 | * | |
473 | * @param compressionOptions The compression options | |
474 | * | |
475 | * @return the reference of the current options. | |
476 | */ | |
477 | T setCompressionOptions( | |
478 | CompressionOptions compressionOptions); | |
479 | ||
480 | /** | |
481 | * Get the different options for compression algorithms | |
482 | * | |
483 | * @return The compression options | |
484 | */ | |
485 | CompressionOptions compressionOptions(); | |
486 | ||
20effc67 TL |
487 | /** |
488 | * If non-nullptr, use the specified factory for a function to determine the | |
489 | * partitioning of sst files. This helps compaction to split the files | |
490 | * on interesting boundaries (key prefixes) to make propagation of sst | |
491 | * files less write amplifying (covering the whole key space). | |
492 | * | |
493 | * Default: nullptr | |
494 | * | |
495 | * @param factory The factory reference | |
496 | * @return the reference of the current options. | |
497 | */ | |
498 | @Experimental("Caution: this option is experimental") | |
499 | T setSstPartitionerFactory(SstPartitionerFactory factory); | |
500 | ||
501 | /** | |
502 | * Get SST partitioner factory | |
503 | * | |
504 | * @return SST partitioner factory | |
505 | */ | |
506 | @Experimental("Caution: this option is experimental") | |
507 | SstPartitionerFactory sstPartitionerFactory(); | |
508 | ||
509 | /** | |
510 | * Compaction concurrent thread limiter for the column family. | |
511 | * If non-nullptr, use given concurrent thread limiter to control | |
512 | * the max outstanding compaction tasks. Limiter can be shared with | |
513 | * multiple column families across db instances. | |
514 | * | |
515 | * @param concurrentTaskLimiter The compaction thread limiter. | |
516 | * @return the reference of the current options. | |
517 | */ | |
518 | T setCompactionThreadLimiter(ConcurrentTaskLimiter concurrentTaskLimiter); | |
519 | ||
520 | /** | |
521 | * Get compaction thread limiter | |
522 | * | |
523 | * @return Compaction thread limiter | |
524 | */ | |
525 | ConcurrentTaskLimiter compactionThreadLimiter(); | |
526 | ||
7c673cae FG |
527 | /** |
528 | * Default memtable memory budget used with the following methods: | |
529 | * | |
530 | * <ol> | |
531 | * <li>{@link #optimizeLevelStyleCompaction()}</li> | |
532 | * <li>{@link #optimizeUniversalStyleCompaction()}</li> | |
533 | * </ol> | |
534 | */ | |
535 | long DEFAULT_COMPACTION_MEMTABLE_MEMORY_BUDGET = 512 * 1024 * 1024; | |
536 | } |