diff --git a/java/Makefile b/java/Makefile index 90a43a40c..0f971433f 100644 --- a/java/Makefile +++ b/java/Makefile @@ -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 diff --git a/java/RocksDBSample.java b/java/RocksDBSample.java index 0f8e7e2d9..293e84fd4 100644 --- a/java/RocksDBSample.java +++ b/java/RocksDBSample.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 { diff --git a/java/org/rocksdb/Options.java b/java/org/rocksdb/Options.java index cca9fcaf7..13c05bc3f 100644 --- a/java/org/rocksdb/Options.java +++ b/java/org/rocksdb/Options.java @@ -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); diff --git a/java/org/rocksdb/util/SizeUnit.java b/java/org/rocksdb/util/SizeUnit.java new file mode 100644 index 000000000..8d50cd10e --- /dev/null +++ b/java/org/rocksdb/util/SizeUnit.java @@ -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() {} +} diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index a6e392c1f..e9d3e48ed 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -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(jhandle)->write_buffer_size = static_cast(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(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(jhandle)->block_size = static_cast(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(jhandle)->block_size; }