Added missing Java ReadOptions settings (#1109)

* Minor reorganisation

* Java API - Added missing ReadOptions settings
main
Adam Retter 8 years ago committed by Siying Dong
parent 5e2c796589
commit 8796934af7
  1. 106
      java/rocksjni/options.cc
  2. 178
      java/src/main/java/org/rocksdb/ReadOptions.java
  3. 48
      java/src/main/java/org/rocksdb/ReadTier.java
  4. 40
      java/src/test/java/org/rocksdb/ReadOptionsTest.java

@ -3925,6 +3925,90 @@ jboolean Java_org_rocksdb_ReadOptions_tailing(
return reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->tailing;
}
/*
* Class: org_rocksdb_ReadOptions
* Method: managed
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_ReadOptions_managed(
JNIEnv* env, jobject jobj, jlong jhandle) {
return reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->managed;
}
/*
* Class: org_rocksdb_ReadOptions
* Method: setManaged
* Signature: (JZ)V
*/
void Java_org_rocksdb_ReadOptions_setManaged(
JNIEnv* env, jobject jobj, jlong jhandle, jboolean jmanaged) {
reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->managed =
static_cast<bool>(jmanaged);
}
/*
* Class: org_rocksdb_ReadOptions
* Method: totalOrderSeek
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_ReadOptions_totalOrderSeek(
JNIEnv* env, jobject jobj, jlong jhandle) {
return reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->total_order_seek;
}
/*
* Class: org_rocksdb_ReadOptions
* Method: setTotalOrderSeek
* Signature: (JZ)V
*/
void Java_org_rocksdb_ReadOptions_setTotalOrderSeek(
JNIEnv* env, jobject jobj, jlong jhandle, jboolean jtotal_order_seek) {
reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->total_order_seek =
static_cast<bool>(jtotal_order_seek);
}
/*
* Class: org_rocksdb_ReadOptions
* Method: prefixSameAsStart
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_ReadOptions_prefixSameAsStart(
JNIEnv* env, jobject jobj, jlong jhandle) {
return reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->prefix_same_as_start;
}
/*
* Class: org_rocksdb_ReadOptions
* Method: setPrefixSameAsStart
* Signature: (JZ)V
*/
void Java_org_rocksdb_ReadOptions_setPrefixSameAsStart(
JNIEnv* env, jobject jobj, jlong jhandle, jboolean jprefix_same_as_start) {
reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->prefix_same_as_start =
static_cast<bool>(jprefix_same_as_start);
}
/*
* Class: org_rocksdb_ReadOptions
* Method: pinData
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_ReadOptions_pinData(
JNIEnv* env, jobject jobj, jlong jhandle) {
return reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->pin_data;
}
/*
* Class: org_rocksdb_ReadOptions
* Method: setPinData
* Signature: (JZ)V
*/
void Java_org_rocksdb_ReadOptions_setPinData(
JNIEnv* env, jobject jobj, jlong jhandle, jboolean jpin_data) {
reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->pin_data =
static_cast<bool>(jpin_data);
}
/*
* Class: org_rocksdb_ReadOptions
* Method: setSnapshot
@ -3948,6 +4032,28 @@ jlong Java_org_rocksdb_ReadOptions_snapshot(
return reinterpret_cast<jlong>(snapshot);
}
/*
* Class: org_rocksdb_ReadOptions
* Method: readTier
* Signature: (J)B
*/
jbyte Java_org_rocksdb_ReadOptions_readTier(
JNIEnv* env, jobject jobj, jlong jhandle) {
return static_cast<jbyte>(
reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->read_tier);
}
/*
* Class: org_rocksdb_ReadOptions
* Method: setReadTier
* Signature: (JB)V
*/
void Java_org_rocksdb_ReadOptions_setReadTier(
JNIEnv* env, jobject jobj, jlong jhandle, jbyte jread_tier) {
reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->read_tier =
static_cast<rocksdb::ReadTier>(jread_tier);
}
/////////////////////////////////////////////////////////////////////
// rocksdb::ComparatorOptions

@ -15,7 +15,6 @@ public class ReadOptions extends RocksObject {
public ReadOptions() {
super(newReadOptions());
}
private native static long newReadOptions();
/**
* If true, all data read from underlying storage will be
@ -28,7 +27,6 @@ public class ReadOptions extends RocksObject {
assert(isOwningHandle());
return verifyChecksums(nativeHandle_);
}
private native boolean verifyChecksums(long handle);
/**
* If true, all data read from underlying storage will be
@ -45,8 +43,6 @@ public class ReadOptions extends RocksObject {
setVerifyChecksums(nativeHandle_, verifyChecksums);
return this;
}
private native void setVerifyChecksums(
long handle, boolean verifyChecksums);
// TODO(yhchiang): this option seems to be block-based table only.
// move this to a better place?
@ -61,7 +57,6 @@ public class ReadOptions extends RocksObject {
assert(isOwningHandle());
return fillCache(nativeHandle_);
}
private native boolean fillCache(long handle);
/**
* Fill the cache when loading the block-based sst formatted db.
@ -77,8 +72,21 @@ public class ReadOptions extends RocksObject {
setFillCache(nativeHandle_, fillCache);
return this;
}
private native void setFillCache(
long handle, boolean fillCache);
/**
* Returns the currently assigned Snapshot instance.
*
* @return the Snapshot assigned to this instance. If no Snapshot
* is assigned null.
*/
public Snapshot snapshot() {
assert(isOwningHandle());
long snapshotHandle = snapshot(nativeHandle_);
if (snapshotHandle != 0) {
return new Snapshot(snapshotHandle);
}
return null;
}
/**
* <p>If "snapshot" is non-nullptr, read as of the supplied snapshot
@ -99,23 +107,30 @@ public class ReadOptions extends RocksObject {
}
return this;
}
private native void setSnapshot(long handle, long snapshotHandle);
/**
* Returns the currently assigned Snapshot instance.
* Returns the current read tier.
*
* @return the Snapshot assigned to this instance. If no Snapshot
* is assigned null.
* @return the read tier in use, by default {@link ReadTier#READ_ALL_TIER}
*/
public Snapshot snapshot() {
public ReadTier readTier() {
assert(isOwningHandle());
long snapshotHandle = snapshot(nativeHandle_);
if (snapshotHandle != 0) {
return new Snapshot(snapshotHandle);
}
return null;
return ReadTier.getReadTier(readTier(nativeHandle_));
}
/**
* Specify if this read request should process data that ALREADY
* resides on a particular cache. If the required data is not
* found at the specified cache, then {@link RocksDBException} is thrown.
*
* @param readTier {@link ReadTier} instance
* @return the reference to the current ReadOptions.
*/
public ReadOptions setReadTier(final ReadTier readTier) {
assert(isOwningHandle());
setReadTier(nativeHandle_, readTier.getValue());
return this;
}
private native long snapshot(long handle);
/**
* Specify to create a tailing iterator -- a special iterator that has a
@ -132,7 +147,6 @@ public class ReadOptions extends RocksObject {
assert(isOwningHandle());
return tailing(nativeHandle_);
}
private native boolean tailing(long handle);
/**
* Specify to create a tailing iterator -- a special iterator that has a
@ -150,8 +164,130 @@ public class ReadOptions extends RocksObject {
setTailing(nativeHandle_, tailing);
return this;
}
private native void setTailing(
long handle, boolean tailing);
/**
* Returns whether managed iterators will be used.
*
* @return the setting of whether managed iterators will be used, by default false
*/
public boolean managed() {
assert(isOwningHandle());
return managed(nativeHandle_);
}
/**
* Specify to create a managed iterator -- a special iterator that
* uses less resources by having the ability to free its underlying
* resources on request.
*
* @param managed if true, then managed iterators will be enabled.
* @return the reference to the current ReadOptions.
*/
public ReadOptions setManaged(final boolean managed) {
assert(isOwningHandle());
setManaged(nativeHandle_, managed);
return this;
}
/**
* Returns whether a total seek order will be used
*
* @return the setting of whether a total seek order will be used
*/
public boolean totalOrderSeek() {
assert(isOwningHandle());
return totalOrderSeek(nativeHandle_);
}
/**
* Enable a total order seek regardless of index format (e.g. hash index)
* used in the table. Some table format (e.g. plain table) may not support
* this option.
*
* @param totalOrderSeek if true, then total order seek will be enabled.
* @return the reference to the current ReadOptions.
*/
public ReadOptions setTotalOrderSeek(final boolean totalOrderSeek) {
assert(isOwningHandle());
setTotalOrderSeek(nativeHandle_, totalOrderSeek);
return this;
}
/**
* Returns whether the iterator only iterates over the same prefix as the seek
*
* @return the setting of whether the iterator only iterates over the same
* prefix as the seek, default is false
*/
public boolean prefixSameAsStart() {
assert(isOwningHandle());
return prefixSameAsStart(nativeHandle_);
}
/**
* Enforce that the iterator only iterates over the same prefix as the seek.
* This option is effective only for prefix seeks, i.e. prefix_extractor is
* non-null for the column family and {@link #totalOrderSeek()} is false.
* Unlike iterate_upper_bound, {@link #setPrefixSameAsStart(boolean)} only
* works within a prefix but in both directions.
*
* @param prefixSameAsStart if true, then the iterator only iterates over the
* same prefix as the seek
* @return the reference to the current ReadOptions.
*/
public ReadOptions setPrefixSameAsStart(final boolean prefixSameAsStart) {
assert(isOwningHandle());
setPrefixSameAsStart(nativeHandle_, prefixSameAsStart);
return this;
}
/**
* Returns whether the blocks loaded by the iterator will be pinned in memory
*
* @return the setting of whether the blocks loaded by the iterator will be
* pinned in memory
*/
public boolean pinData() {
assert(isOwningHandle());
return pinData(nativeHandle_);
}
/**
* Keep the blocks loaded by the iterator pinned in memory as long as the
* iterator is not deleted, If used when reading from tables created with
* BlockBasedTableOptions::use_delta_encoding = false,
* Iterator's property "rocksdb.iterator.is-key-pinned" is guaranteed to
* return 1.
*
* @param pinData if true, the blocks loaded by the iterator will be pinned
* @return the reference to the current ReadOptions.
*/
public ReadOptions setPinData(final boolean pinData) {
assert(isOwningHandle());
setPinData(nativeHandle_, pinData);
return this;
}
private native static long newReadOptions();
private native boolean verifyChecksums(long handle);
private native void setVerifyChecksums(long handle, boolean verifyChecksums);
private native boolean fillCache(long handle);
private native void setFillCache(long handle, boolean fillCache);
private native long snapshot(long handle);
private native void setSnapshot(long handle, long snapshotHandle);
private native byte readTier(long handle);
private native void setReadTier(long handle, byte readTierValue);
private native boolean tailing(long handle);
private native void setTailing(long handle, boolean tailing);
private native boolean managed(long handle);
private native void setManaged(long handle, boolean managed);
private native boolean totalOrderSeek(long handle);
private native void setTotalOrderSeek(long handle, boolean totalOrderSeek);
private native boolean prefixSameAsStart(long handle);
private native void setPrefixSameAsStart(long handle, boolean prefixSameAsStart);
private native boolean pinData(long handle);
private native void setPinData(long handle, boolean pinData);
@Override protected final native void disposeInternal(final long handle);

@ -0,0 +1,48 @@
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
package org.rocksdb;
/**
* RocksDB {@link ReadOptions} read tiers.
*/
public enum ReadTier {
READ_ALL_TIER((byte)0),
BLOCK_CACHE_TIER((byte)1),
PERSISTED_TIER((byte)2);
private final byte value;
ReadTier(final byte value) {
this.value = value;
}
/**
* Returns the byte value of the enumerations value
*
* @return byte representation
*/
public byte getValue() {
return value;
}
/**
* Get ReadTier by byte value.
*
* @param value byte representation of ReadTier.
*
* @return {@link org.rocksdb.ReadTier} instance or null.
* @throws java.lang.IllegalArgumentException if an invalid
* value is provided.
*/
public static ReadTier getReadTier(final byte value) {
for (final ReadTier readTier : ReadTier.values()) {
if (readTier.getValue() == value){
return readTier;
}
}
throw new IllegalArgumentException("Illegal value provided for ReadTier.");
}
}

@ -61,6 +61,46 @@ public class ReadOptionsTest {
}
}
@Test
public void readTier() {
try (final ReadOptions opt = new ReadOptions()) {
opt.setReadTier(ReadTier.BLOCK_CACHE_TIER);
assertThat(opt.readTier()).isEqualTo(ReadTier.BLOCK_CACHE_TIER);
}
}
@Test
public void managed() {
try (final ReadOptions opt = new ReadOptions()) {
opt.setManaged(true);
assertThat(opt.managed()).isTrue();
}
}
@Test
public void totalOrderSeek() {
try (final ReadOptions opt = new ReadOptions()) {
opt.setTotalOrderSeek(true);
assertThat(opt.totalOrderSeek()).isTrue();
}
}
@Test
public void prefixSameAsStart() {
try (final ReadOptions opt = new ReadOptions()) {
opt.setPrefixSameAsStart(true);
assertThat(opt.prefixSameAsStart()).isTrue();
}
}
@Test
public void pinData() {
try (final ReadOptions opt = new ReadOptions()) {
opt.setPinData(true);
assertThat(opt.pinData()).isTrue();
}
}
@Test
public void failSetVerifyChecksumUninitialized() {
try (final ReadOptions readOptions =

Loading…
Cancel
Save