1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
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).
8 public interface ColumnFamilyOptionsInterface
9 <T
extends ColumnFamilyOptionsInterface
>
10 extends AdvancedColumnFamilyOptionsInterface
<T
> {
13 * Use this if your DB is very small (like under 1GB) and you don't want to
14 * spend lots of memory for memtables.
16 * @return the instance of the current object.
18 T
optimizeForSmallDb();
21 * Use this if you don't need to keep the data sorted, i.e. you'll never use
22 * an iterator, only Put() and Get() API calls
24 * @param blockCacheSizeMb Block cache size in MB
25 * @return the instance of the current object.
27 T
optimizeForPointLookup(long blockCacheSizeMb
);
30 * <p>Default values for some parameters in ColumnFamilyOptions are not
31 * optimized for heavy workloads and big datasets, which means you might
32 * observe write stalls under some conditions. As a starting point for tuning
33 * RocksDB options, use the following for level style compaction.</p>
35 * <p>Make sure to also call IncreaseParallelism(), which will provide the
36 * biggest performance gains.</p>
37 * <p>Note: we might use more memory than memtable_memory_budget during high
38 * write rate period</p>
40 * @return the instance of the current object.
42 T
optimizeLevelStyleCompaction();
45 * <p>Default values for some parameters in ColumnFamilyOptions are not
46 * optimized for heavy workloads and big datasets, which means you might
47 * observe write stalls under some conditions. As a starting point for tuning
48 * RocksDB options, use the following for level style compaction.</p>
50 * <p>Make sure to also call IncreaseParallelism(), which will provide the
51 * biggest performance gains.</p>
52 * <p>Note: we might use more memory than memtable_memory_budget during high
53 * write rate period</p>
55 * @param memtableMemoryBudget memory budget in bytes
56 * @return the instance of the current object.
58 T
optimizeLevelStyleCompaction(
59 long memtableMemoryBudget
);
62 * <p>Default values for some parameters in ColumnFamilyOptions are not
63 * optimized for heavy workloads and big datasets, which means you might
64 * observe write stalls under some conditions. As a starting point for tuning
65 * RocksDB options, use the following for universal style compaction.</p>
67 * <p>Universal style compaction is focused on reducing Write Amplification
68 * Factor for big data sets, but increases Space Amplification.</p>
70 * <p>Make sure to also call IncreaseParallelism(), which will provide the
71 * biggest performance gains.</p>
73 * <p>Note: we might use more memory than memtable_memory_budget during high
74 * write rate period</p>
76 * @return the instance of the current object.
78 T
optimizeUniversalStyleCompaction();
81 * <p>Default values for some parameters in ColumnFamilyOptions are not
82 * optimized for heavy workloads and big datasets, which means you might
83 * observe write stalls under some conditions. As a starting point for tuning
84 * RocksDB options, use the following for universal style compaction.</p>
86 * <p>Universal style compaction is focused on reducing Write Amplification
87 * Factor for big data sets, but increases Space Amplification.</p>
89 * <p>Make sure to also call IncreaseParallelism(), which will provide the
90 * biggest performance gains.</p>
92 * <p>Note: we might use more memory than memtable_memory_budget during high
93 * write rate period</p>
95 * @param memtableMemoryBudget memory budget in bytes
96 * @return the instance of the current object.
98 T
optimizeUniversalStyleCompaction(
99 long memtableMemoryBudget
);
102 * Set {@link BuiltinComparator} to be used with RocksDB.
104 * Note: Comparator can be set once upon database creation.
106 * Default: BytewiseComparator.
107 * @param builtinComparator a {@link BuiltinComparator} type.
108 * @return the instance of the current object.
111 BuiltinComparator builtinComparator
);
114 * Use the specified comparator for key ordering.
116 * Comparator should not be disposed before options instances using this comparator is
117 * disposed. If dispose() function is not called, then comparator object will be
118 * GC'd automatically.
120 * Comparator instance can be re-used in multiple options instances.
122 * @param comparator java instance.
123 * @return the instance of the current object.
126 AbstractComparator
<?
extends AbstractSlice
<?
>> comparator
);
129 * <p>Set the merge operator to be used for merging two merge operands
130 * of the same key. The merge function is invoked during
131 * compaction and at lookup time, if multiple key/value pairs belonging
132 * to the same key are found in the database.</p>
134 * @param name the name of the merge function, as defined by
135 * the MergeOperators factory (see utilities/MergeOperators.h)
136 * The merge function is specified by name and must be one of the
137 * standard merge operators provided by RocksDB. The available
138 * operators are "put", "uint64add", "stringappend" and "stringappendtest".
139 * @return the instance of the current object.
141 T
setMergeOperatorName(String name
);
144 * <p>Set the merge operator to be used for merging two different key/value
145 * pairs that share the same key. The merge function is invoked during
146 * compaction and at lookup time, if multiple key/value pairs belonging
147 * to the same key are found in the database.</p>
149 * @param mergeOperator {@link MergeOperator} instance.
150 * @return the instance of the current object.
152 T
setMergeOperator(MergeOperator mergeOperator
);
155 * A single CompactionFilter instance to call into during compaction.
156 * Allows an application to modify/delete a key-value during background
159 * If the client requires a new compaction filter to be used for different
160 * compaction runs, it can specify call
161 * {@link #setCompactionFilterFactory(AbstractCompactionFilterFactory)}
164 * The client should specify only set one of the two.
165 * {@link #setCompactionFilter(AbstractCompactionFilter)} takes precedence
166 * over {@link #setCompactionFilterFactory(AbstractCompactionFilterFactory)}
167 * if the client specifies both.
169 * If multithreaded compaction is being used, the supplied CompactionFilter
170 * instance may be used from different threads concurrently and so should be thread-safe.
172 * @param compactionFilter {@link AbstractCompactionFilter} instance.
173 * @return the instance of the current object.
175 T
setCompactionFilter(
176 final AbstractCompactionFilter
<?
extends AbstractSlice
<?
>> compactionFilter
);
179 * Accessor for the CompactionFilter instance in use.
181 * @return Reference to the CompactionFilter, or null if one hasn't been set.
183 AbstractCompactionFilter
<?
extends AbstractSlice
<?
>> compactionFilter();
186 * This is a factory that provides {@link AbstractCompactionFilter} objects
187 * which allow an application to modify/delete a key-value during background
190 * A new filter will be created on each compaction run. If multithreaded
191 * compaction is being used, each created CompactionFilter will only be used
192 * from a single thread and so does not need to be thread-safe.
194 * @param compactionFilterFactory {@link AbstractCompactionFilterFactory} instance.
195 * @return the instance of the current object.
197 T
setCompactionFilterFactory(
198 final AbstractCompactionFilterFactory
<?
extends AbstractCompactionFilter
<?
>>
199 compactionFilterFactory
);
202 * Accessor for the CompactionFilterFactory instance in use.
204 * @return Reference to the CompactionFilterFactory, or null if one hasn't been set.
206 AbstractCompactionFilterFactory
<?
extends AbstractCompactionFilter
<?
>> compactionFilterFactory();
209 * This prefix-extractor uses the first n bytes of a key as its prefix.
211 * In some hash-based memtable representation such as HashLinkedList
212 * and HashSkipList, prefixes are used to partition the keys into
213 * several buckets. Prefix extractor is used to specify how to
214 * extract the prefix given a key.
216 * @param n use the first n bytes of a key as its prefix.
217 * @return the reference to the current option.
219 T
useFixedLengthPrefixExtractor(int n
);
222 * Same as fixed length prefix extractor, except that when slice is
223 * shorter than the fixed length, it will use the full key.
225 * @param n use the first n bytes of a key as its prefix.
226 * @return the reference to the current option.
228 T
useCappedPrefixExtractor(int n
);
231 * Number of files to trigger level-0 compaction. A value < 0 means that
232 * level-0 compaction will not be triggered by number of files at all.
235 * @param numFiles the number of files in level-0 to trigger compaction.
236 * @return the reference to the current option.
238 T
setLevelZeroFileNumCompactionTrigger(
242 * The number of files in level 0 to trigger compaction from level-0 to
243 * level-1. A value < 0 means that level-0 compaction will not be
244 * triggered by number of files at all.
247 * @return the number of files in level 0 to trigger compaction.
249 int levelZeroFileNumCompactionTrigger();
252 * Soft limit on number of level-0 files. We start slowing down writes at this
253 * point. A value < 0 means that no writing slow down will be triggered by
254 * number of files in level-0.
256 * @param numFiles soft limit on number of level-0 files.
257 * @return the reference to the current option.
259 T
setLevelZeroSlowdownWritesTrigger(
263 * Soft limit on the number of level-0 files. We start slowing down writes
264 * at this point. A value < 0 means that no writing slow down will be
265 * triggered by number of files in level-0.
267 * @return the soft limit on the number of level-0 files.
269 int levelZeroSlowdownWritesTrigger();
272 * Maximum number of level-0 files. We stop writes at this point.
274 * @param numFiles the hard limit of the number of level-0 files.
275 * @return the reference to the current option.
277 T
setLevelZeroStopWritesTrigger(int numFiles
);
280 * Maximum number of level-0 files. We stop writes at this point.
282 * @return the hard limit of the number of level-0 file.
284 int levelZeroStopWritesTrigger();
287 * The ratio between the total size of level-(L+1) files and the total
288 * size of level-L files for all L.
291 * @param multiplier the ratio between the total size of level-(L+1)
292 * files and the total size of level-L files for all L.
293 * @return the reference to the current option.
295 T
setMaxBytesForLevelMultiplier(
299 * The ratio between the total size of level-(L+1) files and the total
300 * size of level-L files for all L.
303 * @return the ratio between the total size of level-(L+1) files and
304 * the total size of level-L files for all L.
306 double maxBytesForLevelMultiplier();
309 * FIFO compaction option.
310 * The oldest table file will be deleted
311 * once the sum of table files reaches this size.
312 * The default value is 1GB (1 * 1024 * 1024 * 1024).
314 * @param maxTableFilesSize the size limit of the total sum of table files.
315 * @return the instance of the current object.
317 T
setMaxTableFilesSizeFIFO(
318 long maxTableFilesSize
);
321 * FIFO compaction option.
322 * The oldest table file will be deleted
323 * once the sum of table files reaches this size.
324 * The default value is 1GB (1 * 1024 * 1024 * 1024).
326 * @return the size limit of the total sum of table files.
328 long maxTableFilesSizeFIFO();
331 * Get the config for mem-table.
333 * @return the mem-table config.
335 MemTableConfig
memTableConfig();
338 * Set the config for mem-table.
340 * @param memTableConfig the mem-table config.
341 * @return the instance of the current object.
342 * @throws java.lang.IllegalArgumentException thrown on 32-Bit platforms
343 * while overflowing the underlying platform specific value.
345 T
setMemTableConfig(MemTableConfig memTableConfig
);
348 * Returns the name of the current mem table representation.
349 * Memtable format can be set using setTableFormatConfig.
351 * @return the name of the currently-used memtable factory.
352 * @see #setTableFormatConfig(org.rocksdb.TableFormatConfig)
354 String
memTableFactoryName();
357 * Get the config for table format.
359 * @return the table format config.
361 TableFormatConfig
tableFormatConfig();
364 * Set the config for table format.
366 * @param config the table format config.
367 * @return the reference of the current options.
369 T
setTableFormatConfig(TableFormatConfig config
);
372 * @return the name of the currently used table factory.
374 String
tableFactoryName();
377 * Compression algorithm that will be used for the bottommost level that
378 * contain files. If level-compaction is used, this option will only affect
379 * levels after base level.
381 * Default: {@link CompressionType#DISABLE_COMPRESSION_OPTION}
383 * @param bottommostCompressionType The compression type to use for the
386 * @return the reference of the current options.
388 T
setBottommostCompressionType(
389 final CompressionType bottommostCompressionType
);
392 * Compression algorithm that will be used for the bottommost level that
393 * contain files. If level-compaction is used, this option will only affect
394 * levels after base level.
396 * Default: {@link CompressionType#DISABLE_COMPRESSION_OPTION}
398 * @return The compression type used for the bottommost level
400 CompressionType
bottommostCompressionType();
403 * Set the options for compression algorithms used by
404 * {@link #bottommostCompressionType()} if it is enabled.
406 * To enable it, please see the definition of
407 * {@link CompressionOptions}.
409 * @param compressionOptions the bottom most compression options.
411 * @return the reference of the current options.
413 T
setBottommostCompressionOptions(
414 final CompressionOptions compressionOptions
);
417 * Get the bottom most compression options.
419 * See {@link #setBottommostCompressionOptions(CompressionOptions)}.
421 * @return the bottom most compression options.
423 CompressionOptions
bottommostCompressionOptions();
426 * Set the different options for compression algorithms
428 * @param compressionOptions The compression options
430 * @return the reference of the current options.
432 T
setCompressionOptions(
433 CompressionOptions compressionOptions
);
436 * Get the different options for compression algorithms
438 * @return The compression options
440 CompressionOptions
compressionOptions();
443 * Default memtable memory budget used with the following methods:
446 * <li>{@link #optimizeLevelStyleCompaction()}</li>
447 * <li>{@link #optimizeUniversalStyleCompaction()}</li>
450 long DEFAULT_COMPACTION_MEMTABLE_MEMORY_BUDGET
= 512 * 1024 * 1024;