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).
5 package org.rocksdb;
6 
7 /**
8  * The config for plain table sst format.
9  *
10  * BlockBasedTable is a RocksDB's default SST file format.
11  */
12 //TODO(AR) should be renamed BlockBasedTableOptions
13 public class BlockBasedTableConfig extends TableFormatConfig {
14 
BlockBasedTableConfig()15   public BlockBasedTableConfig() {
16     //TODO(AR) flushBlockPolicyFactory
17     cacheIndexAndFilterBlocks = false;
18     cacheIndexAndFilterBlocksWithHighPriority = false;
19     pinL0FilterAndIndexBlocksInCache = false;
20     pinTopLevelIndexAndFilter = true;
21     indexType = IndexType.kBinarySearch;
22     dataBlockIndexType = DataBlockIndexType.kDataBlockBinarySearch;
23     dataBlockHashTableUtilRatio = 0.75;
24     checksumType = ChecksumType.kCRC32c;
25     noBlockCache = false;
26     blockCache = null;
27     persistentCache = null;
28     blockCacheCompressed = null;
29     blockSize = 4 * 1024;
30     blockSizeDeviation = 10;
31     blockRestartInterval = 16;
32     indexBlockRestartInterval = 1;
33     metadataBlockSize = 4096;
34     partitionFilters = false;
35     useDeltaEncoding = true;
36     filterPolicy = null;
37     wholeKeyFiltering = true;
38     verifyCompression = true;
39     readAmpBytesPerBit = 0;
40     formatVersion = 2;
41     enableIndexCompression = true;
42     blockAlign = false;
43 
44     // NOTE: ONLY used if blockCache == null
45     blockCacheSize = 8 * 1024 * 1024;
46     blockCacheNumShardBits = 0;
47 
48     // NOTE: ONLY used if blockCacheCompressed == null
49     blockCacheCompressedSize = 0;
50     blockCacheCompressedNumShardBits = 0;
51   }
52 
53   /**
54    * Indicating if we'd put index/filter blocks to the block cache.
55    * If not specified, each "table reader" object will pre-load index/filter
56    * block during table initialization.
57    *
58    * @return if index and filter blocks should be put in block cache.
59    */
cacheIndexAndFilterBlocks()60   public boolean cacheIndexAndFilterBlocks() {
61     return cacheIndexAndFilterBlocks;
62   }
63 
64   /**
65    * Indicating if we'd put index/filter blocks to the block cache.
66    * If not specified, each "table reader" object will pre-load index/filter
67    * block during table initialization.
68    *
69    * @param cacheIndexAndFilterBlocks and filter blocks should be put in block cache.
70    * @return the reference to the current config.
71    */
setCacheIndexAndFilterBlocks( final boolean cacheIndexAndFilterBlocks)72   public BlockBasedTableConfig setCacheIndexAndFilterBlocks(
73       final boolean cacheIndexAndFilterBlocks) {
74     this.cacheIndexAndFilterBlocks = cacheIndexAndFilterBlocks;
75     return this;
76   }
77 
78   /**
79    * Indicates if index and filter blocks will be treated as high-priority in the block cache.
80    * See note below about applicability. If not specified, defaults to false.
81    *
82    * @return if index and filter blocks will be treated as high-priority.
83    */
cacheIndexAndFilterBlocksWithHighPriority()84   public boolean cacheIndexAndFilterBlocksWithHighPriority() {
85     return cacheIndexAndFilterBlocksWithHighPriority;
86   }
87 
88   /**
89    * If true, cache index and filter blocks with high priority. If set to true,
90    * depending on implementation of block cache, index and filter blocks may be
91    * less likely to be evicted than data blocks.
92    *
93    * @param cacheIndexAndFilterBlocksWithHighPriority if index and filter blocks
94    *            will be treated as high-priority.
95    * @return the reference to the current config.
96    */
setCacheIndexAndFilterBlocksWithHighPriority( final boolean cacheIndexAndFilterBlocksWithHighPriority)97   public BlockBasedTableConfig setCacheIndexAndFilterBlocksWithHighPriority(
98       final boolean cacheIndexAndFilterBlocksWithHighPriority) {
99     this.cacheIndexAndFilterBlocksWithHighPriority = cacheIndexAndFilterBlocksWithHighPriority;
100     return this;
101   }
102 
103   /**
104    * Indicating if we'd like to pin L0 index/filter blocks to the block cache.
105    If not specified, defaults to false.
106    *
107    * @return if L0 index and filter blocks should be pinned to the block cache.
108    */
pinL0FilterAndIndexBlocksInCache()109   public boolean pinL0FilterAndIndexBlocksInCache() {
110     return pinL0FilterAndIndexBlocksInCache;
111   }
112 
113   /**
114    * Indicating if we'd like to pin L0 index/filter blocks to the block cache.
115    If not specified, defaults to false.
116    *
117    * @param pinL0FilterAndIndexBlocksInCache pin blocks in block cache
118    * @return the reference to the current config.
119    */
setPinL0FilterAndIndexBlocksInCache( final boolean pinL0FilterAndIndexBlocksInCache)120   public BlockBasedTableConfig setPinL0FilterAndIndexBlocksInCache(
121       final boolean pinL0FilterAndIndexBlocksInCache) {
122     this.pinL0FilterAndIndexBlocksInCache = pinL0FilterAndIndexBlocksInCache;
123     return this;
124   }
125 
126   /**
127    * Indicates if top-level index and filter blocks should be pinned.
128    *
129    * @return if top-level index and filter blocks should be pinned.
130    */
pinTopLevelIndexAndFilter()131   public boolean pinTopLevelIndexAndFilter() {
132     return pinTopLevelIndexAndFilter;
133   }
134 
135   /**
136    * If cacheIndexAndFilterBlocks is true and the below is true, then
137    * the top-level index of partitioned filter and index blocks are stored in
138    * the cache, but a reference is held in the "table reader" object so the
139    * blocks are pinned and only evicted from cache when the table reader is
140    * freed. This is not limited to l0 in LSM tree.
141    *
142    * @param pinTopLevelIndexAndFilter if top-level index and filter blocks should be pinned.
143    * @return the reference to the current config.
144    */
setPinTopLevelIndexAndFilter(final boolean pinTopLevelIndexAndFilter)145   public BlockBasedTableConfig setPinTopLevelIndexAndFilter(final boolean pinTopLevelIndexAndFilter) {
146     this.pinTopLevelIndexAndFilter = pinTopLevelIndexAndFilter;
147     return this;
148   }
149 
150   /**
151    * Get the index type.
152    *
153    * @return the currently set index type
154    */
indexType()155   public IndexType indexType() {
156     return indexType;
157   }
158 
159   /**
160    * Sets the index type to used with this table.
161    *
162    * @param indexType {@link org.rocksdb.IndexType} value
163    * @return the reference to the current option.
164    */
setIndexType( final IndexType indexType)165   public BlockBasedTableConfig setIndexType(
166       final IndexType indexType) {
167     this.indexType = indexType;
168     return this;
169   }
170 
171   /**
172    * Get the data block index type.
173    *
174    * @return the currently set data block index type
175    */
dataBlockIndexType()176   public DataBlockIndexType dataBlockIndexType() {
177     return dataBlockIndexType;
178   }
179 
180   /**
181    * Sets the data block index type to used with this table.
182    *
183    * @param dataBlockIndexType {@link org.rocksdb.DataBlockIndexType} value
184    * @return the reference to the current option.
185    */
setDataBlockIndexType( final DataBlockIndexType dataBlockIndexType)186   public BlockBasedTableConfig setDataBlockIndexType(
187       final DataBlockIndexType dataBlockIndexType) {
188     this.dataBlockIndexType = dataBlockIndexType;
189     return this;
190   }
191 
192   /**
193    * Get the #entries/#buckets. It is valid only when {@link #dataBlockIndexType()} is
194    * {@link DataBlockIndexType#kDataBlockBinaryAndHash}.
195    *
196    * @return the #entries/#buckets.
197    */
dataBlockHashTableUtilRatio()198   public double dataBlockHashTableUtilRatio() {
199     return dataBlockHashTableUtilRatio;
200   }
201 
202   /**
203    * Set the #entries/#buckets. It is valid only when {@link #dataBlockIndexType()} is
204    * {@link DataBlockIndexType#kDataBlockBinaryAndHash}.
205    *
206    * @param dataBlockHashTableUtilRatio #entries/#buckets
207    * @return the reference to the current option.
208    */
setDataBlockHashTableUtilRatio( final double dataBlockHashTableUtilRatio)209   public BlockBasedTableConfig setDataBlockHashTableUtilRatio(
210       final double dataBlockHashTableUtilRatio) {
211     this.dataBlockHashTableUtilRatio = dataBlockHashTableUtilRatio;
212     return this;
213   }
214 
215   /**
216    * Get the checksum type to be used with this table.
217    *
218    * @return the currently set checksum type
219    */
checksumType()220   public ChecksumType checksumType() {
221     return checksumType;
222   }
223 
224   /**
225    * Sets
226    *
227    * @param checksumType {@link org.rocksdb.ChecksumType} value.
228    * @return the reference to the current option.
229    */
setChecksumType( final ChecksumType checksumType)230   public BlockBasedTableConfig setChecksumType(
231       final ChecksumType checksumType) {
232     this.checksumType = checksumType;
233     return this;
234   }
235 
236   /**
237    * Determine if the block cache is disabled.
238    *
239    * @return if block cache is disabled
240    */
noBlockCache()241   public boolean noBlockCache() {
242     return noBlockCache;
243   }
244 
245   /**
246    * Disable block cache. If this is set to true,
247    * then no block cache should be used, and the {@link #setBlockCache(Cache)}
248    * should point to a {@code null} object.
249    *
250    * Default: false
251    *
252    * @param noBlockCache if use block cache
253    * @return the reference to the current config.
254    */
setNoBlockCache(final boolean noBlockCache)255   public BlockBasedTableConfig setNoBlockCache(final boolean noBlockCache) {
256     this.noBlockCache = noBlockCache;
257     return this;
258   }
259 
260   /**
261    * Use the specified cache for blocks.
262    * When not null this take precedence even if the user sets a block cache size.
263    *
264    * {@link org.rocksdb.Cache} should not be disposed before options instances
265    * using this cache is disposed.
266    *
267    * {@link org.rocksdb.Cache} instance can be re-used in multiple options
268    * instances.
269    *
270    * @param blockCache {@link org.rocksdb.Cache} Cache java instance
271    *     (e.g. LRUCache).
272    *
273    * @return the reference to the current config.
274    */
setBlockCache(final Cache blockCache)275   public BlockBasedTableConfig setBlockCache(final Cache blockCache) {
276     this.blockCache = blockCache;
277     return this;
278   }
279 
280   /**
281    * Use the specified persistent cache.
282    *
283    * If {@code !null} use the specified cache for pages read from device,
284    * otherwise no page cache is used.
285    *
286    * @param persistentCache the persistent cache
287    *
288    * @return the reference to the current config.
289    */
setPersistentCache( final PersistentCache persistentCache)290   public BlockBasedTableConfig setPersistentCache(
291       final PersistentCache persistentCache) {
292     this.persistentCache = persistentCache;
293     return this;
294   }
295 
296   /**
297    * Use the specified cache for compressed blocks.
298    *
299    * If {@code null}, RocksDB will not use a compressed block cache.
300    *
301    * Note: though it looks similar to {@link #setBlockCache(Cache)}, RocksDB
302    *     doesn't put the same type of object there.
303    *
304    * {@link org.rocksdb.Cache} should not be disposed before options instances
305    * using this cache is disposed.
306    *
307    * {@link org.rocksdb.Cache} instance can be re-used in multiple options
308    * instances.
309    *
310    * @param blockCacheCompressed {@link org.rocksdb.Cache} Cache java instance
311    *     (e.g. LRUCache).
312    *
313    * @return the reference to the current config.
314    */
setBlockCacheCompressed( final Cache blockCacheCompressed)315   public BlockBasedTableConfig setBlockCacheCompressed(
316       final Cache blockCacheCompressed) {
317     this.blockCacheCompressed = blockCacheCompressed;
318     return this;
319   }
320 
321   /**
322    * Get the approximate size of user data packed per block.
323    *
324    * @return block size in bytes
325    */
blockSize()326   public long blockSize() {
327     return blockSize;
328   }
329 
330   /**
331    * Approximate size of user data packed per block. Note that the
332    * block size specified here corresponds to uncompressed data.  The
333    * actual size of the unit read from disk may be smaller if
334    * compression is enabled.  This parameter can be changed dynamically.
335    * Default: 4K
336    *
337    * @param blockSize block size in bytes
338    * @return the reference to the current config.
339    */
setBlockSize(final long blockSize)340   public BlockBasedTableConfig setBlockSize(final long blockSize) {
341     this.blockSize = blockSize;
342     return this;
343   }
344 
345   /**
346    * @return the hash table ratio.
347    */
blockSizeDeviation()348   public int blockSizeDeviation() {
349     return blockSizeDeviation;
350   }
351 
352   /**
353    * This is used to close a block before it reaches the configured
354    * {@link #blockSize()}. If the percentage of free space in the current block
355    * is less than this specified number and adding a new record to the block
356    * will exceed the configured block size, then this block will be closed and
357    * the new record will be written to the next block.
358    *
359    * Default is 10.
360    *
361    * @param blockSizeDeviation the deviation to block size allowed
362    * @return the reference to the current config.
363    */
setBlockSizeDeviation( final int blockSizeDeviation)364   public BlockBasedTableConfig setBlockSizeDeviation(
365       final int blockSizeDeviation) {
366     this.blockSizeDeviation = blockSizeDeviation;
367     return this;
368   }
369 
370   /**
371    * Get the block restart interval.
372    *
373    * @return block restart interval
374    */
blockRestartInterval()375   public int blockRestartInterval() {
376     return blockRestartInterval;
377   }
378 
379   /**
380    * Set the block restart interval.
381    *
382    * @param restartInterval block restart interval.
383    * @return the reference to the current config.
384    */
setBlockRestartInterval( final int restartInterval)385   public BlockBasedTableConfig setBlockRestartInterval(
386       final int restartInterval) {
387     blockRestartInterval = restartInterval;
388     return this;
389   }
390 
391   /**
392    * Get the index block restart interval.
393    *
394    * @return index block restart interval
395    */
indexBlockRestartInterval()396   public int indexBlockRestartInterval() {
397     return indexBlockRestartInterval;
398   }
399 
400   /**
401    * Set the index block restart interval
402    *
403    * @param restartInterval index block restart interval.
404    * @return the reference to the current config.
405    */
setIndexBlockRestartInterval( final int restartInterval)406   public BlockBasedTableConfig setIndexBlockRestartInterval(
407       final int restartInterval) {
408     indexBlockRestartInterval = restartInterval;
409     return this;
410   }
411 
412   /**
413    * Get the block size for partitioned metadata.
414    *
415    * @return block size for partitioned metadata.
416    */
metadataBlockSize()417   public long metadataBlockSize() {
418     return metadataBlockSize;
419   }
420 
421   /**
422    * Set block size for partitioned metadata.
423    *
424    * @param metadataBlockSize Partitioned metadata block size.
425    * @return the reference to the current config.
426    */
setMetadataBlockSize( final long metadataBlockSize)427   public BlockBasedTableConfig setMetadataBlockSize(
428       final long metadataBlockSize) {
429     this.metadataBlockSize = metadataBlockSize;
430     return this;
431   }
432 
433   /**
434    * Indicates if we're using partitioned filters.
435    *
436    * @return if we're using partition filters.
437    */
partitionFilters()438   public boolean partitionFilters() {
439     return partitionFilters;
440   }
441 
442   /**
443    * Use partitioned full filters for each SST file. This option is incompatible
444    * with block-based filters.
445    *
446    * Defaults to false.
447    *
448    * @param partitionFilters use partition filters.
449    * @return the reference to the current config.
450    */
setPartitionFilters(final boolean partitionFilters)451   public BlockBasedTableConfig setPartitionFilters(final boolean partitionFilters) {
452     this.partitionFilters = partitionFilters;
453     return this;
454   }
455 
456   /**
457    * Determine if delta encoding is being used to compress block keys.
458    *
459    * @return true if delta encoding is enabled, false otherwise.
460    */
useDeltaEncoding()461   public boolean useDeltaEncoding() {
462     return useDeltaEncoding;
463   }
464 
465   /**
466    * Use delta encoding to compress keys in blocks.
467    *
468    * NOTE: {@link ReadOptions#pinData()} requires this option to be disabled.
469    *
470    * Default: true
471    *
472    * @param useDeltaEncoding true to enable delta encoding
473    *
474    * @return the reference to the current config.
475    */
setUseDeltaEncoding( final boolean useDeltaEncoding)476   public BlockBasedTableConfig setUseDeltaEncoding(
477       final boolean useDeltaEncoding) {
478     this.useDeltaEncoding = useDeltaEncoding;
479     return this;
480   }
481 
482   /**
483    * Get the filter policy.
484    *
485    * @return the current filter policy.
486    */
filterPolicy()487   public Filter filterPolicy() {
488     return filterPolicy;
489   }
490 
491   /**
492    * Use the specified filter policy to reduce disk reads.
493    *
494    * {@link org.rocksdb.Filter} should not be disposed before options instances
495    * using this filter is disposed. If {@link Filter#dispose()} function is not
496    * called, then filter object will be GC'd automatically.
497    *
498    * {@link org.rocksdb.Filter} instance can be re-used in multiple options
499    * instances.
500    *
501    * @param filterPolicy {@link org.rocksdb.Filter} Filter Policy java instance.
502    * @return the reference to the current config.
503    */
setFilterPolicy( final Filter filterPolicy)504   public BlockBasedTableConfig setFilterPolicy(
505       final Filter filterPolicy) {
506     this.filterPolicy = filterPolicy;
507     return this;
508   }
509 
510   /**
511    * Set the filter.
512    *
513    * @param filter the filter
514    * @return the reference to the current config.
515    *
516    * @deprecated Use {@link #setFilterPolicy(Filter)}
517    */
518   @Deprecated
setFilter( final Filter filter)519   public BlockBasedTableConfig setFilter(
520       final Filter filter) {
521     return setFilterPolicy(filter);
522   }
523 
524   /**
525    * Determine if whole keys as opposed to prefixes are placed in the filter.
526    *
527    * @return if whole key filtering is enabled
528    */
wholeKeyFiltering()529   public boolean wholeKeyFiltering() {
530     return wholeKeyFiltering;
531   }
532 
533   /**
534    * If true, place whole keys in the filter (not just prefixes).
535    * This must generally be true for gets to be efficient.
536    * Default: true
537    *
538    * @param wholeKeyFiltering if enable whole key filtering
539    * @return the reference to the current config.
540    */
setWholeKeyFiltering( final boolean wholeKeyFiltering)541   public BlockBasedTableConfig setWholeKeyFiltering(
542       final boolean wholeKeyFiltering) {
543     this.wholeKeyFiltering = wholeKeyFiltering;
544     return this;
545   }
546 
547   /**
548    * Returns true when compression verification is enabled.
549    *
550    * See {@link #setVerifyCompression(boolean)}.
551    *
552    * @return true if compression verification is enabled.
553    */
verifyCompression()554   public boolean verifyCompression() {
555     return verifyCompression;
556   }
557 
558   /**
559    * Verify that decompressing the compressed block gives back the input. This
560    * is a verification mode that we use to detect bugs in compression
561    * algorithms.
562    *
563    * @param verifyCompression true to enable compression verification.
564    *
565    * @return the reference to the current config.
566    */
setVerifyCompression( final boolean verifyCompression)567   public BlockBasedTableConfig setVerifyCompression(
568       final boolean verifyCompression) {
569     this.verifyCompression = verifyCompression;
570     return this;
571   }
572 
573   /**
574    * Get the Read amplification bytes per-bit.
575    *
576    * See {@link #setReadAmpBytesPerBit(int)}.
577    *
578    * @return the bytes per-bit.
579    */
readAmpBytesPerBit()580   public int readAmpBytesPerBit() {
581     return readAmpBytesPerBit;
582   }
583 
584   /**
585    * Set the Read amplification bytes per-bit.
586    *
587    * If used, For every data block we load into memory, we will create a bitmap
588    * of size ((block_size / `read_amp_bytes_per_bit`) / 8) bytes. This bitmap
589    * will be used to figure out the percentage we actually read of the blocks.
590    *
591    * When this feature is used Tickers::READ_AMP_ESTIMATE_USEFUL_BYTES and
592    * Tickers::READ_AMP_TOTAL_READ_BYTES can be used to calculate the
593    * read amplification using this formula
594    * (READ_AMP_TOTAL_READ_BYTES / READ_AMP_ESTIMATE_USEFUL_BYTES)
595    *
596    * value  =>  memory usage (percentage of loaded blocks memory)
597    * 1      =>  12.50 %
598    * 2      =>  06.25 %
599    * 4      =>  03.12 %
600    * 8      =>  01.56 %
601    * 16     =>  00.78 %
602    *
603    * Note: This number must be a power of 2, if not it will be sanitized
604    * to be the next lowest power of 2, for example a value of 7 will be
605    * treated as 4, a value of 19 will be treated as 16.
606    *
607    * Default: 0 (disabled)
608    *
609    * @param readAmpBytesPerBit the bytes per-bit
610    *
611    * @return the reference to the current config.
612    */
setReadAmpBytesPerBit(final int readAmpBytesPerBit)613   public BlockBasedTableConfig setReadAmpBytesPerBit(final int readAmpBytesPerBit) {
614     this.readAmpBytesPerBit = readAmpBytesPerBit;
615     return this;
616   }
617 
618   /**
619    * Get the format version.
620    * See {@link #setFormatVersion(int)}.
621    *
622    * @return the currently configured format version.
623    */
formatVersion()624   public int formatVersion() {
625     return formatVersion;
626   }
627 
628   /**
629    * <p>We currently have five versions:</p>
630    *
631    * <ul>
632    * <li><strong>0</strong> - This version is currently written
633    * out by all RocksDB's versions by default. Can be read by really old
634    * RocksDB's. Doesn't support changing checksum (default is CRC32).</li>
635    * <li><strong>1</strong> - Can be read by RocksDB's versions since 3.0.
636    * Supports non-default checksum, like xxHash. It is written by RocksDB when
637    * BlockBasedTableOptions::checksum is something other than kCRC32c. (version
638    * 0 is silently upconverted)</li>
639    * <li><strong>2</strong> - Can be read by RocksDB's versions since 3.10.
640    * Changes the way we encode compressed blocks with LZ4, BZip2 and Zlib
641    * compression. If you don't plan to run RocksDB before version 3.10,
642    * you should probably use this.</li>
643    * <li><strong>3</strong> - Can be read by RocksDB's versions since 5.15. Changes the way we
644    * encode the keys in index blocks. If you don't plan to run RocksDB before
645    * version 5.15, you should probably use this.
646    * This option only affects newly written tables. When reading existing
647    * tables, the information about version is read from the footer.</li>
648    * <li><strong>4</strong> - Can be read by RocksDB's versions since 5.16. Changes the way we
649    * encode the values in index blocks. If you don't plan to run RocksDB before
650    * version 5.16 and you are using index_block_restart_interval &gt; 1, you should
651    * probably use this as it would reduce the index size.</li>
652    * </ul>
653    * <p> This option only affects newly written tables. When reading existing
654    * tables, the information about version is read from the footer.</p>
655    *
656    * @param formatVersion integer representing the version to be used.
657    *
658    * @return the reference to the current option.
659    */
setFormatVersion( final int formatVersion)660   public BlockBasedTableConfig setFormatVersion(
661       final int formatVersion) {
662     assert(formatVersion >= 0 && formatVersion <= 4);
663     this.formatVersion = formatVersion;
664     return this;
665   }
666 
667   /**
668    * Determine if index compression is enabled.
669    *
670    * See {@link #setEnableIndexCompression(boolean)}.
671    *
672    * @return true if index compression is enabled, false otherwise
673    */
enableIndexCompression()674   public boolean enableIndexCompression() {
675     return enableIndexCompression;
676   }
677 
678   /**
679    * Store index blocks on disk in compressed format.
680    *
681    * Changing this option to false  will avoid the overhead of decompression
682    * if index blocks are evicted and read back.
683    *
684    * @param enableIndexCompression true to enable index compression,
685    *     false to disable
686    *
687    * @return the reference to the current option.
688    */
setEnableIndexCompression( final boolean enableIndexCompression)689   public BlockBasedTableConfig setEnableIndexCompression(
690       final boolean enableIndexCompression) {
691     this.enableIndexCompression = enableIndexCompression;
692     return this;
693   }
694 
695   /**
696    * Determines whether data blocks are aligned on the lesser of page size
697    * and block size.
698    *
699    * @return true if data blocks are aligned on the lesser of page size
700    *     and block size.
701    */
blockAlign()702   public boolean blockAlign() {
703     return blockAlign;
704   }
705 
706   /**
707    * Set whether data blocks should be aligned on the lesser of page size
708    * and block size.
709    *
710    * @param blockAlign true to align data blocks on the lesser of page size
711    *     and block size.
712    *
713    * @return the reference to the current option.
714    */
setBlockAlign(final boolean blockAlign)715   public BlockBasedTableConfig setBlockAlign(final boolean blockAlign) {
716     this.blockAlign = blockAlign;
717     return this;
718   }
719 
720 
721   /**
722    * Get the size of the cache in bytes that will be used by RocksDB.
723    *
724    * @return block cache size in bytes
725    */
726   @Deprecated
blockCacheSize()727   public long blockCacheSize() {
728     return blockCacheSize;
729   }
730 
731   /**
732    * Set the size of the cache in bytes that will be used by RocksDB.
733    * If cacheSize is negative, then cache will not be used.
734    * DEFAULT: 8M
735    *
736    * @param blockCacheSize block cache size in bytes
737    * @return the reference to the current config.
738    *
739    * @deprecated Use {@link #setBlockCache(Cache)}.
740    */
741   @Deprecated
setBlockCacheSize(final long blockCacheSize)742   public BlockBasedTableConfig setBlockCacheSize(final long blockCacheSize) {
743     this.blockCacheSize = blockCacheSize;
744     return this;
745   }
746 
747   /**
748    * Returns the number of shard bits used in the block cache.
749    * The resulting number of shards would be 2 ^ (returned value).
750    * Any negative number means use default settings.
751    *
752    * @return the number of shard bits used in the block cache.
753    */
754   @Deprecated
cacheNumShardBits()755   public int cacheNumShardBits() {
756     return blockCacheNumShardBits;
757   }
758 
759   /**
760    * Controls the number of shards for the block cache.
761    * This is applied only if cacheSize is set to non-negative.
762    *
763    * @param blockCacheNumShardBits the number of shard bits. The resulting
764    *     number of shards would be 2 ^ numShardBits.  Any negative
765    *     number means use default settings."
766    * @return the reference to the current option.
767    *
768    * @deprecated Use {@link #setBlockCache(Cache)}.
769    */
770   @Deprecated
setCacheNumShardBits( final int blockCacheNumShardBits)771   public BlockBasedTableConfig setCacheNumShardBits(
772       final int blockCacheNumShardBits) {
773     this.blockCacheNumShardBits = blockCacheNumShardBits;
774     return this;
775   }
776 
777   /**
778    * Size of compressed block cache. If 0, then block_cache_compressed is set
779    * to null.
780    *
781    * @return size of compressed block cache.
782    */
783   @Deprecated
blockCacheCompressedSize()784   public long blockCacheCompressedSize() {
785     return blockCacheCompressedSize;
786   }
787 
788   /**
789    * Size of compressed block cache. If 0, then block_cache_compressed is set
790    * to null.
791    *
792    * @param blockCacheCompressedSize of compressed block cache.
793    * @return the reference to the current config.
794    *
795    * @deprecated Use {@link #setBlockCacheCompressed(Cache)}.
796    */
797   @Deprecated
setBlockCacheCompressedSize( final long blockCacheCompressedSize)798   public BlockBasedTableConfig setBlockCacheCompressedSize(
799       final long blockCacheCompressedSize) {
800     this.blockCacheCompressedSize = blockCacheCompressedSize;
801     return this;
802   }
803 
804   /**
805    * Controls the number of shards for the block compressed cache.
806    * This is applied only if blockCompressedCacheSize is set to non-negative.
807    *
808    * @return numShardBits the number of shard bits.  The resulting
809    *     number of shards would be 2 ^ numShardBits.  Any negative
810    *     number means use default settings.
811    */
812   @Deprecated
blockCacheCompressedNumShardBits()813   public int blockCacheCompressedNumShardBits() {
814     return blockCacheCompressedNumShardBits;
815   }
816 
817   /**
818    * Controls the number of shards for the block compressed cache.
819    * This is applied only if blockCompressedCacheSize is set to non-negative.
820    *
821    * @param blockCacheCompressedNumShardBits the number of shard bits.  The resulting
822    *     number of shards would be 2 ^ numShardBits.  Any negative
823    *     number means use default settings."
824    * @return the reference to the current option.
825    *
826    * @deprecated Use {@link #setBlockCacheCompressed(Cache)}.
827    */
828   @Deprecated
setBlockCacheCompressedNumShardBits( final int blockCacheCompressedNumShardBits)829   public BlockBasedTableConfig setBlockCacheCompressedNumShardBits(
830       final int blockCacheCompressedNumShardBits) {
831     this.blockCacheCompressedNumShardBits = blockCacheCompressedNumShardBits;
832     return this;
833   }
834 
835   /**
836    * Influence the behavior when kHashSearch is used.
837    *  if false, stores a precise prefix to block range mapping
838    *  if true, does not store prefix and allows prefix hash collision
839    *  (less memory consumption)
840    *
841    * @return if hash collisions should be allowed.
842    *
843    * @deprecated This option is now deprecated. No matter what value it
844    *     is set to, it will behave as
845    *     if {@link #hashIndexAllowCollision()} == true.
846    */
847   @Deprecated
hashIndexAllowCollision()848   public boolean hashIndexAllowCollision() {
849     return true;
850   }
851 
852   /**
853    * Influence the behavior when kHashSearch is used.
854    * if false, stores a precise prefix to block range mapping
855    * if true, does not store prefix and allows prefix hash collision
856    * (less memory consumption)
857    *
858    * @param hashIndexAllowCollision points out if hash collisions should be allowed.
859    *
860    * @return the reference to the current config.
861    *
862    * @deprecated This option is now deprecated. No matter what value it
863    *     is set to, it will behave as
864    *     if {@link #hashIndexAllowCollision()} == true.
865    */
866   @Deprecated
setHashIndexAllowCollision( final boolean hashIndexAllowCollision)867   public BlockBasedTableConfig setHashIndexAllowCollision(
868       final boolean hashIndexAllowCollision) {
869     // no-op
870     return this;
871   }
872 
newTableFactoryHandle()873   @Override protected long newTableFactoryHandle() {
874     final long filterPolicyHandle;
875     if (filterPolicy != null) {
876       filterPolicyHandle = filterPolicy.nativeHandle_;
877     } else {
878       filterPolicyHandle = 0;
879     }
880 
881     final long blockCacheHandle;
882     if (blockCache != null) {
883       blockCacheHandle = blockCache.nativeHandle_;
884     } else {
885       blockCacheHandle = 0;
886     }
887 
888     final long persistentCacheHandle;
889     if (persistentCache != null) {
890       persistentCacheHandle = persistentCache.nativeHandle_;
891     } else {
892       persistentCacheHandle = 0;
893     }
894 
895     final long blockCacheCompressedHandle;
896     if (blockCacheCompressed != null) {
897       blockCacheCompressedHandle = blockCacheCompressed.nativeHandle_;
898     } else {
899       blockCacheCompressedHandle = 0;
900     }
901 
902     return newTableFactoryHandle(cacheIndexAndFilterBlocks,
903         cacheIndexAndFilterBlocksWithHighPriority,
904         pinL0FilterAndIndexBlocksInCache, pinTopLevelIndexAndFilter,
905         indexType.getValue(), dataBlockIndexType.getValue(),
906         dataBlockHashTableUtilRatio, checksumType.getValue(), noBlockCache,
907         blockCacheHandle, persistentCacheHandle, blockCacheCompressedHandle,
908         blockSize, blockSizeDeviation, blockRestartInterval,
909         indexBlockRestartInterval, metadataBlockSize, partitionFilters,
910         useDeltaEncoding, filterPolicyHandle, wholeKeyFiltering,
911         verifyCompression, readAmpBytesPerBit, formatVersion,
912         enableIndexCompression, blockAlign,
913         blockCacheSize, blockCacheNumShardBits,
914         blockCacheCompressedSize, blockCacheCompressedNumShardBits);
915   }
916 
newTableFactoryHandle( final boolean cacheIndexAndFilterBlocks, final boolean cacheIndexAndFilterBlocksWithHighPriority, final boolean pinL0FilterAndIndexBlocksInCache, final boolean pinTopLevelIndexAndFilter, final byte indexTypeValue, final byte dataBlockIndexTypeValue, final double dataBlockHashTableUtilRatio, final byte checksumTypeValue, final boolean noBlockCache, final long blockCacheHandle, final long persistentCacheHandle, final long blockCacheCompressedHandle, final long blockSize, final int blockSizeDeviation, final int blockRestartInterval, final int indexBlockRestartInterval, final long metadataBlockSize, final boolean partitionFilters, final boolean useDeltaEncoding, final long filterPolicyHandle, final boolean wholeKeyFiltering, final boolean verifyCompression, final int readAmpBytesPerBit, final int formatVersion, final boolean enableIndexCompression, final boolean blockAlign, @Deprecated final long blockCacheSize, @Deprecated final int blockCacheNumShardBits, @Deprecated final long blockCacheCompressedSize, @Deprecated final int blockCacheCompressedNumShardBits )917   private native long newTableFactoryHandle(
918       final boolean cacheIndexAndFilterBlocks,
919       final boolean cacheIndexAndFilterBlocksWithHighPriority,
920       final boolean pinL0FilterAndIndexBlocksInCache,
921       final boolean pinTopLevelIndexAndFilter,
922       final byte indexTypeValue,
923       final byte dataBlockIndexTypeValue,
924       final double dataBlockHashTableUtilRatio,
925       final byte checksumTypeValue,
926       final boolean noBlockCache,
927       final long blockCacheHandle,
928       final long persistentCacheHandle,
929       final long blockCacheCompressedHandle,
930       final long blockSize,
931       final int blockSizeDeviation,
932       final int blockRestartInterval,
933       final int indexBlockRestartInterval,
934       final long metadataBlockSize,
935       final boolean partitionFilters,
936       final boolean useDeltaEncoding,
937       final long filterPolicyHandle,
938       final boolean wholeKeyFiltering,
939       final boolean verifyCompression,
940       final int readAmpBytesPerBit,
941       final int formatVersion,
942       final boolean enableIndexCompression,
943       final boolean blockAlign,
944 
945       @Deprecated final long blockCacheSize,
946       @Deprecated final int blockCacheNumShardBits,
947 
948       @Deprecated final long blockCacheCompressedSize,
949       @Deprecated final int blockCacheCompressedNumShardBits
950   );
951 
952   //TODO(AR) flushBlockPolicyFactory
953   private boolean cacheIndexAndFilterBlocks;
954   private boolean cacheIndexAndFilterBlocksWithHighPriority;
955   private boolean pinL0FilterAndIndexBlocksInCache;
956   private boolean pinTopLevelIndexAndFilter;
957   private IndexType indexType;
958   private DataBlockIndexType dataBlockIndexType;
959   private double dataBlockHashTableUtilRatio;
960   private ChecksumType checksumType;
961   private boolean noBlockCache;
962   private Cache blockCache;
963   private PersistentCache persistentCache;
964   private Cache blockCacheCompressed;
965   private long blockSize;
966   private int blockSizeDeviation;
967   private int blockRestartInterval;
968   private int indexBlockRestartInterval;
969   private long metadataBlockSize;
970   private boolean partitionFilters;
971   private boolean useDeltaEncoding;
972   private Filter filterPolicy;
973   private boolean wholeKeyFiltering;
974   private boolean verifyCompression;
975   private int readAmpBytesPerBit;
976   private int formatVersion;
977   private boolean enableIndexCompression;
978   private boolean blockAlign;
979 
980   // NOTE: ONLY used if blockCache == null
981   @Deprecated private long blockCacheSize;
982   @Deprecated private int blockCacheNumShardBits;
983 
984   // NOTE: ONLY used if blockCacheCompressed == null
985   @Deprecated private long blockCacheCompressedSize;
986   @Deprecated private int blockCacheCompressedNumShardBits;
987 }
988