]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/BlockBasedTableConfig.java
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / BlockBasedTableConfig.java
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
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
340 public BlockBasedTableConfig setBlockSize(final long blockSize) {
341 this.blockSize = blockSize;
342 return this;
343 }
344
345 /**
346 * @return the hash table ratio.
347 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
476 public BlockBasedTableConfig setUseDeltaEncoding(
477 final boolean useDeltaEncoding) {
478 this.useDeltaEncoding = useDeltaEncoding;
479 return this;
480 }
481
482 /**
483 * Use the specified filter policy to reduce disk reads.
484 *
485 * {@link org.rocksdb.Filter} should not be disposed before options instances
486 * using this filter is disposed. If {@link Filter#dispose()} function is not
487 * called, then filter object will be GC'd automatically.
488 *
489 * {@link org.rocksdb.Filter} instance can be re-used in multiple options
490 * instances.
491 *
492 * @param filterPolicy {@link org.rocksdb.Filter} Filter Policy java instance.
493 * @return the reference to the current config.
494 */
495 public BlockBasedTableConfig setFilterPolicy(
496 final Filter filterPolicy) {
497 this.filterPolicy = filterPolicy;
498 return this;
499 }
500
501 /*
502 * @deprecated Use {@link #setFilterPolicy(Filter)}
503 */
504 @Deprecated
505 public BlockBasedTableConfig setFilter(
506 final Filter filter) {
507 return setFilterPolicy(filter);
508 }
509
510 /**
511 * Determine if whole keys as opposed to prefixes are placed in the filter.
512 *
513 * @return if whole key filtering is enabled
514 */
515 public boolean wholeKeyFiltering() {
516 return wholeKeyFiltering;
517 }
518
519 /**
520 * If true, place whole keys in the filter (not just prefixes).
521 * This must generally be true for gets to be efficient.
522 * Default: true
523 *
524 * @param wholeKeyFiltering if enable whole key filtering
525 * @return the reference to the current config.
526 */
527 public BlockBasedTableConfig setWholeKeyFiltering(
528 final boolean wholeKeyFiltering) {
529 this.wholeKeyFiltering = wholeKeyFiltering;
530 return this;
531 }
532
533 /**
534 * Returns true when compression verification is enabled.
535 *
536 * See {@link #setVerifyCompression(boolean)}.
537 *
538 * @return true if compression verification is enabled.
539 */
540 public boolean verifyCompression() {
541 return verifyCompression;
542 }
543
544 /**
545 * Verify that decompressing the compressed block gives back the input. This
546 * is a verification mode that we use to detect bugs in compression
547 * algorithms.
548 *
549 * @param verifyCompression true to enable compression verification.
550 *
551 * @return the reference to the current config.
552 */
553 public BlockBasedTableConfig setVerifyCompression(
554 final boolean verifyCompression) {
555 this.verifyCompression = verifyCompression;
556 return this;
557 }
558
559 /**
560 * Get the Read amplification bytes per-bit.
561 *
562 * See {@link #setReadAmpBytesPerBit(int)}.
563 *
564 * @return the bytes per-bit.
565 */
566 public int readAmpBytesPerBit() {
567 return readAmpBytesPerBit;
568 }
569
570 /**
571 * Set the Read amplification bytes per-bit.
572 *
573 * If used, For every data block we load into memory, we will create a bitmap
574 * of size ((block_size / `read_amp_bytes_per_bit`) / 8) bytes. This bitmap
575 * will be used to figure out the percentage we actually read of the blocks.
576 *
577 * When this feature is used Tickers::READ_AMP_ESTIMATE_USEFUL_BYTES and
578 * Tickers::READ_AMP_TOTAL_READ_BYTES can be used to calculate the
579 * read amplification using this formula
580 * (READ_AMP_TOTAL_READ_BYTES / READ_AMP_ESTIMATE_USEFUL_BYTES)
581 *
582 * value => memory usage (percentage of loaded blocks memory)
583 * 1 => 12.50 %
584 * 2 => 06.25 %
585 * 4 => 03.12 %
586 * 8 => 01.56 %
587 * 16 => 00.78 %
588 *
589 * Note: This number must be a power of 2, if not it will be sanitized
590 * to be the next lowest power of 2, for example a value of 7 will be
591 * treated as 4, a value of 19 will be treated as 16.
592 *
593 * Default: 0 (disabled)
594 *
595 * @param readAmpBytesPerBit the bytes per-bit
596 *
597 * @return the reference to the current config.
598 */
599 public BlockBasedTableConfig setReadAmpBytesPerBit(final int readAmpBytesPerBit) {
600 this.readAmpBytesPerBit = readAmpBytesPerBit;
601 return this;
602 }
603
604 /**
605 * Get the format version.
606 * See {@link #setFormatVersion(int)}.
607 *
608 * @return the currently configured format version.
609 */
610 public int formatVersion() {
611 return formatVersion;
612 }
613
614 /**
615 * <p>We currently have five versions:</p>
616 *
617 * <ul>
618 * <li><strong>0</strong> - This version is currently written
619 * out by all RocksDB's versions by default. Can be read by really old
620 * RocksDB's. Doesn't support changing checksum (default is CRC32).</li>
621 * <li><strong>1</strong> - Can be read by RocksDB's versions since 3.0.
622 * Supports non-default checksum, like xxHash. It is written by RocksDB when
623 * BlockBasedTableOptions::checksum is something other than kCRC32c. (version
624 * 0 is silently upconverted)</li>
625 * <li><strong>2</strong> - Can be read by RocksDB's versions since 3.10.
626 * Changes the way we encode compressed blocks with LZ4, BZip2 and Zlib
627 * compression. If you don't plan to run RocksDB before version 3.10,
628 * you should probably use this.</li>
629 * <li><strong>3</strong> - Can be read by RocksDB's versions since 5.15. Changes the way we
630 * encode the keys in index blocks. If you don't plan to run RocksDB before
631 * version 5.15, you should probably use this.
632 * This option only affects newly written tables. When reading existing
633 * tables, the information about version is read from the footer.</li>
634 * <li><strong>4</strong> - Can be read by RocksDB's versions since 5.16. Changes the way we
635 * encode the values in index blocks. If you don't plan to run RocksDB before
636 * version 5.16 and you are using index_block_restart_interval &gt; 1, you should
637 * probably use this as it would reduce the index size.</li>
638 * </ul>
639 * <p> This option only affects newly written tables. When reading existing
640 * tables, the information about version is read from the footer.</p>
641 *
642 * @param formatVersion integer representing the version to be used.
643 *
644 * @return the reference to the current option.
645 */
646 public BlockBasedTableConfig setFormatVersion(
647 final int formatVersion) {
648 assert(formatVersion >= 0 && formatVersion <= 4);
649 this.formatVersion = formatVersion;
650 return this;
651 }
652
653 /**
654 * Determine if index compression is enabled.
655 *
656 * See {@link #setEnableIndexCompression(boolean)}.
657 *
658 * @return true if index compression is enabled, false otherwise
659 */
660 public boolean enableIndexCompression() {
661 return enableIndexCompression;
662 }
663
664 /**
665 * Store index blocks on disk in compressed format.
666 *
667 * Changing this option to false will avoid the overhead of decompression
668 * if index blocks are evicted and read back.
669 *
670 * @param enableIndexCompression true to enable index compression,
671 * false to disable
672 *
673 * @return the reference to the current option.
674 */
675 public BlockBasedTableConfig setEnableIndexCompression(
676 final boolean enableIndexCompression) {
677 this.enableIndexCompression = enableIndexCompression;
678 return this;
679 }
680
681 /**
682 * Determines whether data blocks are aligned on the lesser of page size
683 * and block size.
684 *
685 * @return true if data blocks are aligned on the lesser of page size
686 * and block size.
687 */
688 public boolean blockAlign() {
689 return blockAlign;
690 }
691
692 /**
693 * Set whether data blocks should be aligned on the lesser of page size
694 * and block size.
695 *
696 * @param blockAlign true to align data blocks on the lesser of page size
697 * and block size.
698 *
699 * @return the reference to the current option.
700 */
701 public BlockBasedTableConfig setBlockAlign(final boolean blockAlign) {
702 this.blockAlign = blockAlign;
703 return this;
704 }
705
706
707 /**
708 * Get the size of the cache in bytes that will be used by RocksDB.
709 *
710 * @return block cache size in bytes
711 */
712 @Deprecated
713 public long blockCacheSize() {
714 return blockCacheSize;
715 }
716
717 /**
718 * Set the size of the cache in bytes that will be used by RocksDB.
719 * If cacheSize is non-positive, then cache will not be used.
720 * DEFAULT: 8M
721 *
722 * @param blockCacheSize block cache size in bytes
723 * @return the reference to the current config.
724 *
725 * @deprecated Use {@link #setBlockCache(Cache)}.
726 */
727 @Deprecated
728 public BlockBasedTableConfig setBlockCacheSize(final long blockCacheSize) {
729 this.blockCacheSize = blockCacheSize;
730 return this;
731 }
732
733 /**
734 * Returns the number of shard bits used in the block cache.
735 * The resulting number of shards would be 2 ^ (returned value).
736 * Any negative number means use default settings.
737 *
738 * @return the number of shard bits used in the block cache.
739 */
740 @Deprecated
741 public int cacheNumShardBits() {
742 return blockCacheNumShardBits;
743 }
744
745 /**
746 * Controls the number of shards for the block cache.
747 * This is applied only if cacheSize is set to non-negative.
748 *
749 * @param blockCacheNumShardBits the number of shard bits. The resulting
750 * number of shards would be 2 ^ numShardBits. Any negative
751 * number means use default settings."
752 * @return the reference to the current option.
753 *
754 * @deprecated Use {@link #setBlockCache(Cache)}.
755 */
756 @Deprecated
757 public BlockBasedTableConfig setCacheNumShardBits(
758 final int blockCacheNumShardBits) {
759 this.blockCacheNumShardBits = blockCacheNumShardBits;
760 return this;
761 }
762
763 /**
764 * Size of compressed block cache. If 0, then block_cache_compressed is set
765 * to null.
766 *
767 * @return size of compressed block cache.
768 */
769 @Deprecated
770 public long blockCacheCompressedSize() {
771 return blockCacheCompressedSize;
772 }
773
774 /**
775 * Size of compressed block cache. If 0, then block_cache_compressed is set
776 * to null.
777 *
778 * @param blockCacheCompressedSize of compressed block cache.
779 * @return the reference to the current config.
780 *
781 * @deprecated Use {@link #setBlockCacheCompressed(Cache)}.
782 */
783 @Deprecated
784 public BlockBasedTableConfig setBlockCacheCompressedSize(
785 final long blockCacheCompressedSize) {
786 this.blockCacheCompressedSize = blockCacheCompressedSize;
787 return this;
788 }
789
790 /**
791 * Controls the number of shards for the block compressed cache.
792 * This is applied only if blockCompressedCacheSize is set to non-negative.
793 *
794 * @return numShardBits the number of shard bits. The resulting
795 * number of shards would be 2 ^ numShardBits. Any negative
796 * number means use default settings.
797 */
798 @Deprecated
799 public int blockCacheCompressedNumShardBits() {
800 return blockCacheCompressedNumShardBits;
801 }
802
803 /**
804 * Controls the number of shards for the block compressed cache.
805 * This is applied only if blockCompressedCacheSize is set to non-negative.
806 *
807 * @param blockCacheCompressedNumShardBits the number of shard bits. The resulting
808 * number of shards would be 2 ^ numShardBits. Any negative
809 * number means use default settings."
810 * @return the reference to the current option.
811 *
812 * @deprecated Use {@link #setBlockCacheCompressed(Cache)}.
813 */
814 @Deprecated
815 public BlockBasedTableConfig setBlockCacheCompressedNumShardBits(
816 final int blockCacheCompressedNumShardBits) {
817 this.blockCacheCompressedNumShardBits = blockCacheCompressedNumShardBits;
818 return this;
819 }
820
821 /**
822 * Influence the behavior when kHashSearch is used.
823 * if false, stores a precise prefix to block range mapping
824 * if true, does not store prefix and allows prefix hash collision
825 * (less memory consumption)
826 *
827 * @return if hash collisions should be allowed.
828 *
829 * @deprecated This option is now deprecated. No matter what value it
830 * is set to, it will behave as
831 * if {@link #hashIndexAllowCollision()} == true.
832 */
833 @Deprecated
834 public boolean hashIndexAllowCollision() {
835 return true;
836 }
837
838 /**
839 * Influence the behavior when kHashSearch is used.
840 * if false, stores a precise prefix to block range mapping
841 * if true, does not store prefix and allows prefix hash collision
842 * (less memory consumption)
843 *
844 * @param hashIndexAllowCollision points out if hash collisions should be allowed.
845 *
846 * @return the reference to the current config.
847 *
848 * @deprecated This option is now deprecated. No matter what value it
849 * is set to, it will behave as
850 * if {@link #hashIndexAllowCollision()} == true.
851 */
852 @Deprecated
853 public BlockBasedTableConfig setHashIndexAllowCollision(
854 final boolean hashIndexAllowCollision) {
855 // no-op
856 return this;
857 }
858
859 @Override protected long newTableFactoryHandle() {
860 final long filterPolicyHandle;
861 if (filterPolicy != null) {
862 filterPolicyHandle = filterPolicy.nativeHandle_;
863 } else {
864 filterPolicyHandle = 0;
865 }
866
867 final long blockCacheHandle;
868 if (blockCache != null) {
869 blockCacheHandle = blockCache.nativeHandle_;
870 } else {
871 blockCacheHandle = 0;
872 }
873
874 final long persistentCacheHandle;
875 if (persistentCache != null) {
876 persistentCacheHandle = persistentCache.nativeHandle_;
877 } else {
878 persistentCacheHandle = 0;
879 }
880
881 final long blockCacheCompressedHandle;
882 if (blockCacheCompressed != null) {
883 blockCacheCompressedHandle = blockCacheCompressed.nativeHandle_;
884 } else {
885 blockCacheCompressedHandle = 0;
886 }
887
888 return newTableFactoryHandle(cacheIndexAndFilterBlocks,
889 cacheIndexAndFilterBlocksWithHighPriority,
890 pinL0FilterAndIndexBlocksInCache, pinTopLevelIndexAndFilter,
891 indexType.getValue(), dataBlockIndexType.getValue(),
892 dataBlockHashTableUtilRatio, checksumType.getValue(), noBlockCache,
893 blockCacheHandle, persistentCacheHandle, blockCacheCompressedHandle,
894 blockSize, blockSizeDeviation, blockRestartInterval,
895 indexBlockRestartInterval, metadataBlockSize, partitionFilters,
896 useDeltaEncoding, filterPolicyHandle, wholeKeyFiltering,
897 verifyCompression, readAmpBytesPerBit, formatVersion,
898 enableIndexCompression, blockAlign,
899 blockCacheSize, blockCacheNumShardBits,
900 blockCacheCompressedSize, blockCacheCompressedNumShardBits);
901 }
902
903 private native long newTableFactoryHandle(
904 final boolean cacheIndexAndFilterBlocks,
905 final boolean cacheIndexAndFilterBlocksWithHighPriority,
906 final boolean pinL0FilterAndIndexBlocksInCache,
907 final boolean pinTopLevelIndexAndFilter,
908 final byte indexTypeValue,
909 final byte dataBlockIndexTypeValue,
910 final double dataBlockHashTableUtilRatio,
911 final byte checksumTypeValue,
912 final boolean noBlockCache,
913 final long blockCacheHandle,
914 final long persistentCacheHandle,
915 final long blockCacheCompressedHandle,
916 final long blockSize,
917 final int blockSizeDeviation,
918 final int blockRestartInterval,
919 final int indexBlockRestartInterval,
920 final long metadataBlockSize,
921 final boolean partitionFilters,
922 final boolean useDeltaEncoding,
923 final long filterPolicyHandle,
924 final boolean wholeKeyFiltering,
925 final boolean verifyCompression,
926 final int readAmpBytesPerBit,
927 final int formatVersion,
928 final boolean enableIndexCompression,
929 final boolean blockAlign,
930
931 @Deprecated final long blockCacheSize,
932 @Deprecated final int blockCacheNumShardBits,
933
934 @Deprecated final long blockCacheCompressedSize,
935 @Deprecated final int blockCacheCompressedNumShardBits
936 );
937
938 //TODO(AR) flushBlockPolicyFactory
939 private boolean cacheIndexAndFilterBlocks;
940 private boolean cacheIndexAndFilterBlocksWithHighPriority;
941 private boolean pinL0FilterAndIndexBlocksInCache;
942 private boolean pinTopLevelIndexAndFilter;
943 private IndexType indexType;
944 private DataBlockIndexType dataBlockIndexType;
945 private double dataBlockHashTableUtilRatio;
946 private ChecksumType checksumType;
947 private boolean noBlockCache;
948 private Cache blockCache;
949 private PersistentCache persistentCache;
950 private Cache blockCacheCompressed;
951 private long blockSize;
952 private int blockSizeDeviation;
953 private int blockRestartInterval;
954 private int indexBlockRestartInterval;
955 private long metadataBlockSize;
956 private boolean partitionFilters;
957 private boolean useDeltaEncoding;
958 private Filter filterPolicy;
959 private boolean wholeKeyFiltering;
960 private boolean verifyCompression;
961 private int readAmpBytesPerBit;
962 private int formatVersion;
963 private boolean enableIndexCompression;
964 private boolean blockAlign;
965
966 // NOTE: ONLY used if blockCache == null
967 @Deprecated private long blockCacheSize;
968 @Deprecated private int blockCacheNumShardBits;
969
970 // NOTE: ONLY used if blockCacheCompressed == null
971 @Deprecated private long blockCacheCompressedSize;
972 @Deprecated private int blockCacheCompressedNumShardBits;
973 }