|
| 1 | +// Copyright (c) 2014, Facebook, Inc. All rights reserved. |
| 2 | +// This source code is licensed under the BSD-style license found in the |
| 3 | +// LICENSE file in the root directory of this source tree. An additional grant |
| 4 | +// of patent rights can be found in the PATENTS file in the same directory. |
| 5 | + |
| 6 | +package org.rocksdb; |
| 7 | + |
| 8 | +/** |
| 9 | + * The class that controls the get behavior. |
| 10 | + * |
| 11 | + * Note that dispose() must be called before an Options instance |
| 12 | + * become out-of-scope to release the allocated memory in c++. |
| 13 | + */ |
| 14 | +public class ReadOptions { |
| 15 | + public ReadOptions() { |
| 16 | + nativeHandle_ = 0; |
| 17 | + newReadOptions(); |
| 18 | + } |
| 19 | + private native void newReadOptions(); |
| 20 | + |
| 21 | + /** |
| 22 | + * Release the memory allocated for the current instance |
| 23 | + * in the c++ side. |
| 24 | + * |
| 25 | + * Calling other methods after dispose() leads to undefined behavior. |
| 26 | + */ |
| 27 | + public synchronized void dispose() { |
| 28 | + if (isInitialized()) { |
| 29 | + dispose(nativeHandle_); |
| 30 | + } |
| 31 | + } |
| 32 | + private native void dispose(long handle); |
| 33 | + |
| 34 | + /** |
| 35 | + * If true, all data read from underlying storage will be |
| 36 | + * verified against corresponding checksums. |
| 37 | + * Default: true |
| 38 | + * |
| 39 | + * @return true if checksum verification is on. |
| 40 | + */ |
| 41 | + public boolean verifyChecksums() { |
| 42 | + assert(isInitialized()); |
| 43 | + return verifyChecksums(nativeHandle_); |
| 44 | + } |
| 45 | + private native boolean verifyChecksums(long handle); |
| 46 | + |
| 47 | + /** |
| 48 | + * If true, all data read from underlying storage will be |
| 49 | + * verified against corresponding checksums. |
| 50 | + * Default: true |
| 51 | + * |
| 52 | + * @param verifyChecksums if true, then checksum verification |
| 53 | + * will be performed on every read. |
| 54 | + * @return the reference to the current ReadOptions. |
| 55 | + */ |
| 56 | + public ReadOptions setVerifyChecksums(boolean verifyChecksums) { |
| 57 | + assert(isInitialized()); |
| 58 | + setVerifyChecksums(nativeHandle_, verifyChecksums); |
| 59 | + return this; |
| 60 | + } |
| 61 | + private native void setVerifyChecksums( |
| 62 | + long handle, boolean verifyChecksums); |
| 63 | + |
| 64 | + // TODO(yhchiang): this option seems to be block-based table only. |
| 65 | + // move this to a better place? |
| 66 | + /** |
| 67 | + * Fill the cache when loading the block-based sst formated db. |
| 68 | + * Callers may wish to set this field to false for bulk scans. |
| 69 | + * Default: true |
| 70 | + * |
| 71 | + * @return true if the fill-cache behavior is on. |
| 72 | + */ |
| 73 | + public boolean fillCache() { |
| 74 | + assert(isInitialized()); |
| 75 | + return fillCache(nativeHandle_); |
| 76 | + } |
| 77 | + private native boolean fillCache(long handle); |
| 78 | + |
| 79 | + /** |
| 80 | + * Fill the cache when loading the block-based sst formated db. |
| 81 | + * Callers may wish to set this field to false for bulk scans. |
| 82 | + * Default: true |
| 83 | + * |
| 84 | + * @param fillCache if true, then fill-cache behavior will be |
| 85 | + * performed. |
| 86 | + * @return the reference to the current ReadOptions. |
| 87 | + */ |
| 88 | + public ReadOptions setFillCache(boolean fillCache) { |
| 89 | + assert(isInitialized()); |
| 90 | + setFillCache(nativeHandle_, fillCache); |
| 91 | + return this; |
| 92 | + } |
| 93 | + private native void setFillCache( |
| 94 | + long handle, boolean fillCache); |
| 95 | + |
| 96 | + /** |
| 97 | + * If this option is set and memtable implementation allows, Seek |
| 98 | + * might only return keys with the same prefix as the seek-key |
| 99 | + * Default: false |
| 100 | + * |
| 101 | + * @return true if prefix-seek is enabled. |
| 102 | + */ |
| 103 | + public boolean prefixSeek() { |
| 104 | + assert(isInitialized()); |
| 105 | + return prefixSeek(nativeHandle_); |
| 106 | + } |
| 107 | + private native boolean prefixSeek(long handle); |
| 108 | + |
| 109 | + /** |
| 110 | + * If this option is set and memtable implementation allows, Seek |
| 111 | + * might only return keys with the same prefix as the seek-key |
| 112 | + * |
| 113 | + * @param prefixSeek if true, then prefix-seek will be enabled. |
| 114 | + * @return the reference to the current ReadOptions. |
| 115 | + */ |
| 116 | + public ReadOptions setPrefixSeek(boolean prefixSeek) { |
| 117 | + assert(isInitialized()); |
| 118 | + setPrefixSeek(nativeHandle_, prefixSeek); |
| 119 | + return this; |
| 120 | + } |
| 121 | + private native void setPrefixSeek( |
| 122 | + long handle, boolean prefixSeek); |
| 123 | + |
| 124 | + /** |
| 125 | + * Specify to create a tailing iterator -- a special iterator that has a |
| 126 | + * view of the complete database (i.e. it can also be used to read newly |
| 127 | + * added data) and is optimized for sequential reads. It will return records |
| 128 | + * that were inserted into the database after the creation of the iterator. |
| 129 | + * Default: false |
| 130 | + * Not supported in ROCKSDB_LITE mode! |
| 131 | + * |
| 132 | + * @return true if tailing iterator is enabled. |
| 133 | + */ |
| 134 | + public boolean tailing() { |
| 135 | + assert(isInitialized()); |
| 136 | + return tailing(nativeHandle_); |
| 137 | + } |
| 138 | + private native boolean tailing(long handle); |
| 139 | + |
| 140 | + /** |
| 141 | + * Specify to create a tailing iterator -- a special iterator that has a |
| 142 | + * view of the complete database (i.e. it can also be used to read newly |
| 143 | + * added data) and is optimized for sequential reads. It will return records |
| 144 | + * that were inserted into the database after the creation of the iterator. |
| 145 | + * Default: false |
| 146 | + * Not supported in ROCKSDB_LITE mode! |
| 147 | + * |
| 148 | + * @param tailing if true, then tailing iterator will be enabled. |
| 149 | + * @return the reference to the current ReadOptions. |
| 150 | + */ |
| 151 | + public ReadOptions setTailing(boolean tailing) { |
| 152 | + assert(isInitialized()); |
| 153 | + setTailing(nativeHandle_, tailing); |
| 154 | + return this; |
| 155 | + } |
| 156 | + private native void setTailing( |
| 157 | + long handle, boolean tailing); |
| 158 | + |
| 159 | + protected long nativeHandle_; |
| 160 | + |
| 161 | + private boolean isInitialized() { |
| 162 | + return nativeHandle_ != 0; |
| 163 | + } |
| 164 | +} |
| 165 | + |
0 commit comments