[Java] Add SizeUnit in org.rocksdb.util to store const like KB, GB.
Summary: * Add a class SizeUnit to store frequently used consts. Currently it has KB, MB, GB, TB, and PB. * Change the parameter type of Options.writeBufferSize and Options.blockSize from int to long. Test Plan: make rocksdbjava make jtest Reviewers: haobo, ankgup87, sdong, dhruba Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D17703
This commit is contained in:
parent
31e7e7fe84
commit
51f4b5090d
@ -8,8 +8,8 @@ clean:
|
||||
rm -f $(ROCKSDB_JAR)
|
||||
|
||||
java:
|
||||
javac org/rocksdb/*.java
|
||||
jar -cf $(ROCKSDB_JAR) org/rocksdb/*.class
|
||||
javac org/rocksdb/*.java org/rocksdb/util/*.java
|
||||
jar -cf $(ROCKSDB_JAR) org/rocksdb/*.class org/rocksdb/util/*.class
|
||||
javah -d $(NATIVE_INCLUDE) -jni $(NATIVE_JAVA_CLASSES)
|
||||
|
||||
sample: java
|
||||
|
@ -6,6 +6,7 @@
|
||||
import java.util.*;
|
||||
import java.lang.*;
|
||||
import org.rocksdb.*;
|
||||
import org.rocksdb.util.SizeUnit;
|
||||
import java.io.IOException;
|
||||
|
||||
public class RocksDBSample {
|
||||
@ -33,17 +34,17 @@ public class RocksDBSample {
|
||||
}
|
||||
|
||||
options.setCreateIfMissing(true)
|
||||
.setWriteBufferSize(8 * 1024)
|
||||
.setWriteBufferSize(8 * SizeUnit.KB)
|
||||
.setMaxWriteBufferNumber(3)
|
||||
.setDisableSeekCompaction(true)
|
||||
.setBlockSize(64 * 1024)
|
||||
.setBlockSize(64 * SizeUnit.KB)
|
||||
.setMaxBackgroundCompactions(10);
|
||||
|
||||
assert(options.createIfMissing() == true);
|
||||
assert(options.writeBufferSize() == 8192);
|
||||
assert(options.writeBufferSize() == 8 * SizeUnit.KB);
|
||||
assert(options.maxWriteBufferNumber() == 3);
|
||||
assert(options.disableSeekCompaction() == true);
|
||||
assert(options.blockSize() == 65536);
|
||||
assert(options.blockSize() == 64 * SizeUnit.KB);
|
||||
assert(options.maxBackgroundCompactions() == 10);
|
||||
|
||||
try {
|
||||
|
@ -71,7 +71,7 @@ public class Options {
|
||||
* @return the instance of the current Options.
|
||||
* @see RocksDB.open()
|
||||
*/
|
||||
public Options setWriteBufferSize(int writeBufferSize) {
|
||||
public Options setWriteBufferSize(long writeBufferSize) {
|
||||
assert(isInitialized());
|
||||
setWriteBufferSize(nativeHandle_, writeBufferSize);
|
||||
return this;
|
||||
@ -83,7 +83,7 @@ public class Options {
|
||||
* @return size of write buffer.
|
||||
* @see setWriteBufferSize()
|
||||
*/
|
||||
public int writeBufferSize() {
|
||||
public long writeBufferSize() {
|
||||
assert(isInitialized());
|
||||
return writeBufferSize(nativeHandle_);
|
||||
}
|
||||
@ -127,7 +127,7 @@ public class Options {
|
||||
* @return the instance of the current Options.
|
||||
* @see RocksDB.open()
|
||||
*/
|
||||
public Options setBlockSize(int blockSize) {
|
||||
public Options setBlockSize(long blockSize) {
|
||||
assert(isInitialized());
|
||||
setBlockSize(nativeHandle_, blockSize);
|
||||
return this;
|
||||
@ -139,7 +139,7 @@ public class Options {
|
||||
* @return block size.
|
||||
* @see setBlockSize()
|
||||
*/
|
||||
public int blockSize() {
|
||||
public long blockSize() {
|
||||
assert(isInitialized());
|
||||
return blockSize(nativeHandle_);
|
||||
}
|
||||
@ -236,13 +236,13 @@ public class Options {
|
||||
private native void dispose0();
|
||||
private native void setCreateIfMissing(long handle, boolean flag);
|
||||
private native boolean createIfMissing(long handle);
|
||||
private native void setWriteBufferSize(long handle, int writeBufferSize);
|
||||
private native int writeBufferSize(long handle);
|
||||
private native void setWriteBufferSize(long handle, long writeBufferSize);
|
||||
private native long writeBufferSize(long handle);
|
||||
private native void setMaxWriteBufferNumber(
|
||||
long handle, int maxWriteBufferNumber);
|
||||
private native int maxWriteBufferNumber(long handle);
|
||||
private native void setBlockSize(long handle, int blockSize);
|
||||
private native int blockSize(long handle);
|
||||
private native void setBlockSize(long handle, long blockSize);
|
||||
private native long blockSize(long handle);
|
||||
private native void setDisableSeekCompaction(
|
||||
long handle, boolean disableSeekCompaction);
|
||||
private native boolean disableSeekCompaction(long handle);
|
||||
|
16
java/org/rocksdb/util/SizeUnit.java
Normal file
16
java/org/rocksdb/util/SizeUnit.java
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2014, 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.util;
|
||||
|
||||
public class SizeUnit {
|
||||
public static final long KB = 1024L;
|
||||
public static final long MB = KB * KB;
|
||||
public static final long GB = KB * MB;
|
||||
public static final long TB = KB * GB;
|
||||
public static final long PB = KB * TB;
|
||||
|
||||
private SizeUnit() {}
|
||||
}
|
@ -61,10 +61,10 @@ jboolean Java_org_rocksdb_Options_createIfMissing(
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
* Method: setWriteBufferSize
|
||||
* Signature: (JZ)I
|
||||
* Signature: (JJ)I
|
||||
*/
|
||||
void Java_org_rocksdb_Options_setWriteBufferSize(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jint jwrite_buffer_size) {
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jlong jwrite_buffer_size) {
|
||||
reinterpret_cast<rocksdb::Options*>(jhandle)->write_buffer_size =
|
||||
static_cast<size_t>(jwrite_buffer_size);
|
||||
}
|
||||
@ -73,9 +73,9 @@ void Java_org_rocksdb_Options_setWriteBufferSize(
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
* Method: writeBufferSize
|
||||
* Signature: (J)I
|
||||
* Signature: (J)J
|
||||
*/
|
||||
jint Java_org_rocksdb_Options_writeBufferSize(
|
||||
jlong Java_org_rocksdb_Options_writeBufferSize(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
return reinterpret_cast<rocksdb::Options*>(jhandle)->write_buffer_size;
|
||||
}
|
||||
@ -105,10 +105,10 @@ jint Java_org_rocksdb_Options_maxWriteBufferNumber(
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
* Method: setBlockSize
|
||||
* Signature: (JI)V
|
||||
* Signature: (JJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_Options_setBlockSize(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jint jblock_size) {
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jlong jblock_size) {
|
||||
reinterpret_cast<rocksdb::Options*>(jhandle)->block_size =
|
||||
static_cast<size_t>(jblock_size);
|
||||
}
|
||||
@ -116,9 +116,9 @@ void Java_org_rocksdb_Options_setBlockSize(
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
* Method: blockSize
|
||||
* Signature: (J)I
|
||||
* Signature: (J)J
|
||||
*/
|
||||
jint Java_org_rocksdb_Options_blockSize(
|
||||
jlong Java_org_rocksdb_Options_blockSize(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
return reinterpret_cast<rocksdb::Options*>(jhandle)->block_size;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user