diff --git a/java/RocksDBSample.java b/java/RocksDBSample.java index 1493977a9..5c4b70001 100644 --- a/java/RocksDBSample.java +++ b/java/RocksDBSample.java @@ -43,7 +43,8 @@ public class RocksDBSample { .setDisableSeekCompaction(true) .setBlockSize(64 * SizeUnit.KB) .setMaxBackgroundCompactions(10) - .setFilter(filter); + .setFilter(filter) + .setCompressionType(CompressionType.SNAPPY_COMPRESSION); Statistics stats = options.statisticsPtr(); assert(options.createIfMissing() == true); @@ -52,6 +53,7 @@ public class RocksDBSample { assert(options.disableSeekCompaction() == true); assert(options.blockSize() == 64 * SizeUnit.KB); assert(options.maxBackgroundCompactions() == 10); + assert(options.compressionType() == CompressionType.SNAPPY_COMPRESSION); assert(options.memTableFactoryName().equals("SkipListFactory")); options.setMemTableConfig( diff --git a/java/org/rocksdb/CompressionType.java b/java/org/rocksdb/CompressionType.java new file mode 100644 index 000000000..c5d6253a9 --- /dev/null +++ b/java/org/rocksdb/CompressionType.java @@ -0,0 +1,25 @@ +// 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; + +public enum CompressionType { + NO_COMPRESSION((byte) 0), + SNAPPY_COMPRESSION((byte) 1), + ZLIB_COMPRESSION((byte) 2), + BZLIB2_COMPRESSION((byte) 3), + LZ4_COMPRESSION((byte) 4), + LZ4HC_COMPRESSION((byte) 5); + + private final byte value_; + + private CompressionType(byte value) { + value_ = value; + } + + public byte getValue() { + return value_; + } +} diff --git a/java/org/rocksdb/Options.java b/java/org/rocksdb/Options.java index 0bf7a9aa9..dac5aeb4e 100644 --- a/java/org/rocksdb/Options.java +++ b/java/org/rocksdb/Options.java @@ -1307,6 +1307,34 @@ public class Options extends RocksObject { } private native void setBlockRestartInterval( long handle, int blockRestartInterval); + + /** + * Compress blocks using the specified compression algorithm. This + parameter can be changed dynamically. + * + * Default: SNAPPY_COMPRESSION, which gives lightweight but fast compression. + * + * @return Compression type. + */ + public CompressionType compressionType() { + return CompressionType.values()[compressionType(nativeHandle_)]; + } + private native byte compressionType(long handle); + + /** + * Compress blocks using the specified compression algorithm. This + parameter can be changed dynamically. + * + * Default: SNAPPY_COMPRESSION, which gives lightweight but fast compression. + * + * @param compressionType Compression Type. + * @return the reference to the current option. + */ + public Options setCompressionType(CompressionType compressionType) { + setCompressionType(nativeHandle_, compressionType.getValue()); + return this; + } + private native void setCompressionType(long handle, byte compressionType); /** * If true, place whole keys in the filter (not just prefixes). diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index 003d353e6..763b28f5d 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -935,6 +935,27 @@ void Java_org_rocksdb_Options_setBlockRestartInterval( static_cast(jblock_restart_interval); } +/* + * Class: org_rocksdb_Options + * Method: setCompressionType + * Signature: (JB)V + */ +void Java_org_rocksdb_Options_setCompressionType( + JNIEnv* env, jobject jobj, jlong jhandle, jbyte compression) { + reinterpret_cast(jhandle)->compression = + static_cast(compression); +} + +/* + * Class: org_rocksdb_Options + * Method: compressionType + * Signature: (J)B + */ +jbyte Java_org_rocksdb_Options_compressionType( + JNIEnv* env, jobject jobj, jlong jhandle) { + return reinterpret_cast(jhandle)->compression; +} + /* * Class: org_rocksdb_Options * Method: wholeKeyFiltering