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 6 package org.rocksdb; 7 8 /** 9 * Options for Compression 10 */ 11 public class CompressionOptions extends RocksObject { 12 CompressionOptions()13 public CompressionOptions() { 14 super(newCompressionOptions()); 15 } 16 setWindowBits(final int windowBits)17 public CompressionOptions setWindowBits(final int windowBits) { 18 setWindowBits(nativeHandle_, windowBits); 19 return this; 20 } 21 windowBits()22 public int windowBits() { 23 return windowBits(nativeHandle_); 24 } 25 setLevel(final int level)26 public CompressionOptions setLevel(final int level) { 27 setLevel(nativeHandle_, level); 28 return this; 29 } 30 level()31 public int level() { 32 return level(nativeHandle_); 33 } 34 setStrategy(final int strategy)35 public CompressionOptions setStrategy(final int strategy) { 36 setStrategy(nativeHandle_, strategy); 37 return this; 38 } 39 strategy()40 public int strategy() { 41 return strategy(nativeHandle_); 42 } 43 44 /** 45 * Maximum size of dictionary used to prime the compression library. Currently 46 * this dictionary will be constructed by sampling the first output file in a 47 * subcompaction when the target level is bottommost. This dictionary will be 48 * loaded into the compression library before compressing/uncompressing each 49 * data block of subsequent files in the subcompaction. Effectively, this 50 * improves compression ratios when there are repetitions across data blocks. 51 * 52 * A value of 0 indicates the feature is disabled. 53 * 54 * Default: 0. 55 * 56 * @param maxDictBytes Maximum bytes to use for the dictionary 57 * 58 * @return the reference to the current options 59 */ setMaxDictBytes(final int maxDictBytes)60 public CompressionOptions setMaxDictBytes(final int maxDictBytes) { 61 setMaxDictBytes(nativeHandle_, maxDictBytes); 62 return this; 63 } 64 65 /** 66 * Maximum size of dictionary used to prime the compression library. 67 * 68 * @return The maximum bytes to use for the dictionary 69 */ maxDictBytes()70 public int maxDictBytes() { 71 return maxDictBytes(nativeHandle_); 72 } 73 74 /** 75 * Maximum size of training data passed to zstd's dictionary trainer. Using 76 * zstd's dictionary trainer can achieve even better compression ratio 77 * improvements than using {@link #setMaxDictBytes(int)} alone. 78 * 79 * The training data will be used to generate a dictionary 80 * of {@link #maxDictBytes()}. 81 * 82 * Default: 0. 83 * 84 * @param zstdMaxTrainBytes Maximum bytes to use for training ZStd. 85 * 86 * @return the reference to the current options 87 */ setZStdMaxTrainBytes(final int zstdMaxTrainBytes)88 public CompressionOptions setZStdMaxTrainBytes(final int zstdMaxTrainBytes) { 89 setZstdMaxTrainBytes(nativeHandle_, zstdMaxTrainBytes); 90 return this; 91 } 92 93 /** 94 * Maximum size of training data passed to zstd's dictionary trainer. 95 * 96 * @return Maximum bytes to use for training ZStd 97 */ zstdMaxTrainBytes()98 public int zstdMaxTrainBytes() { 99 return zstdMaxTrainBytes(nativeHandle_); 100 } 101 102 /** 103 * When the compression options are set by the user, it will be set to "true". 104 * For bottommost_compression_opts, to enable it, user must set enabled=true. 105 * Otherwise, bottommost compression will use compression_opts as default 106 * compression options. 107 * 108 * For compression_opts, if compression_opts.enabled=false, it is still 109 * used as compression options for compression process. 110 * 111 * Default: false. 112 * 113 * @param enabled true to use these compression options 114 * for the bottommost_compression_opts, false otherwise 115 * 116 * @return the reference to the current options 117 */ setEnabled(final boolean enabled)118 public CompressionOptions setEnabled(final boolean enabled) { 119 setEnabled(nativeHandle_, enabled); 120 return this; 121 } 122 123 /** 124 * Determine whether these compression options 125 * are used for the bottommost_compression_opts. 126 * 127 * @return true if these compression options are used 128 * for the bottommost_compression_opts, false otherwise 129 */ enabled()130 public boolean enabled() { 131 return enabled(nativeHandle_); 132 } 133 134 newCompressionOptions()135 private native static long newCompressionOptions(); disposeInternal(final long handle)136 @Override protected final native void disposeInternal(final long handle); 137 setWindowBits(final long handle, final int windowBits)138 private native void setWindowBits(final long handle, final int windowBits); windowBits(final long handle)139 private native int windowBits(final long handle); setLevel(final long handle, final int level)140 private native void setLevel(final long handle, final int level); level(final long handle)141 private native int level(final long handle); setStrategy(final long handle, final int strategy)142 private native void setStrategy(final long handle, final int strategy); strategy(final long handle)143 private native int strategy(final long handle); setMaxDictBytes(final long handle, final int maxDictBytes)144 private native void setMaxDictBytes(final long handle, final int maxDictBytes); maxDictBytes(final long handle)145 private native int maxDictBytes(final long handle); setZstdMaxTrainBytes(final long handle, final int zstdMaxTrainBytes)146 private native void setZstdMaxTrainBytes(final long handle, 147 final int zstdMaxTrainBytes); zstdMaxTrainBytes(final long handle)148 private native int zstdMaxTrainBytes(final long handle); setEnabled(final long handle, final boolean enabled)149 private native void setEnabled(final long handle, final boolean enabled); enabled(final long handle)150 private native boolean enabled(final long handle); 151 } 152