Integrated changes from D29571
This commit is contained in:
parent
a15169f2e9
commit
3e684aa685
@ -14,25 +14,59 @@ package org.rocksdb;
|
||||
* compression method (if any) is used to compress a block.</p>
|
||||
*/
|
||||
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_;
|
||||
NO_COMPRESSION((byte) 0, null),
|
||||
SNAPPY_COMPRESSION((byte) 1, "snappy"),
|
||||
ZLIB_COMPRESSION((byte) 2, "z"),
|
||||
BZLIB2_COMPRESSION((byte) 3, "bzip2"),
|
||||
LZ4_COMPRESSION((byte) 4, "lz4"),
|
||||
LZ4HC_COMPRESSION((byte) 5, "lz4hc");
|
||||
|
||||
private CompressionType(byte value) {
|
||||
value_ = value;
|
||||
/**
|
||||
* <p>Get the CompressionType enumeration value by
|
||||
* passing the library name to this method.</p>
|
||||
*
|
||||
* <p>If library cannot be found the enumeration
|
||||
* value {@code NO_COMPRESSION} will be returned.</p>
|
||||
*
|
||||
* @return CompressionType instance.
|
||||
*/
|
||||
public static CompressionType getCompressionType(String libraryName) {
|
||||
if (libraryName != null) {
|
||||
for (CompressionType compressionType : CompressionType.values()) {
|
||||
if (compressionType.getLibraryName() != null &&
|
||||
compressionType.getLibraryName().equals(libraryName)) {
|
||||
return compressionType;
|
||||
}
|
||||
}
|
||||
}
|
||||
return CompressionType.NO_COMPRESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte value of the enumerations value
|
||||
* <p>Returns the byte value of the enumerations value.</p>
|
||||
*
|
||||
* @return byte representation
|
||||
*/
|
||||
public byte getValue() {
|
||||
return value_;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns the library name of the compression type
|
||||
* identified by the enumeration value.</p>
|
||||
*
|
||||
* @return library name
|
||||
*/
|
||||
public String getLibraryName() {
|
||||
return libraryName_;
|
||||
}
|
||||
|
||||
private CompressionType(byte value, final String libraryName) {
|
||||
value_ = value;
|
||||
libraryName_ = libraryName;
|
||||
}
|
||||
|
||||
private final byte value_;
|
||||
private final String libraryName_;
|
||||
}
|
||||
|
@ -18,8 +18,6 @@ import org.rocksdb.util.Environment;
|
||||
public class RocksDB extends RocksObject {
|
||||
public static final String DEFAULT_COLUMN_FAMILY = "default";
|
||||
public static final int NOT_FOUND = -1;
|
||||
private static final String[] compressionLibs_ = {
|
||||
"snappy", "z", "bzip2", "lz4", "lz4hc"};
|
||||
|
||||
static {
|
||||
RocksDB.loadLibrary();
|
||||
@ -35,9 +33,11 @@ public class RocksDB extends RocksObject {
|
||||
public static synchronized void loadLibrary() {
|
||||
String tmpDir = System.getenv("ROCKSDB_SHAREDLIB_DIR");
|
||||
// loading possibly necessary libraries.
|
||||
for (String lib : compressionLibs_) {
|
||||
for (CompressionType compressionType : CompressionType.values()) {
|
||||
try {
|
||||
System.loadLibrary(lib);
|
||||
if (compressionType.getLibraryName() != null) {
|
||||
System.loadLibrary(compressionType.getLibraryName());
|
||||
}
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
// since it may be optional, we ignore its loading failure here.
|
||||
}
|
||||
@ -60,10 +60,14 @@ public class RocksDB extends RocksObject {
|
||||
* of a library.
|
||||
*/
|
||||
public static synchronized void loadLibrary(List<String> paths) {
|
||||
for (String lib : compressionLibs_) {
|
||||
for (CompressionType compressionType : CompressionType.values()) {
|
||||
if (compressionType.equals(CompressionType.NO_COMPRESSION)) {
|
||||
continue;
|
||||
}
|
||||
for (String path : paths) {
|
||||
try {
|
||||
System.load(path + "/" + Environment.getSharedLibraryName(lib));
|
||||
System.load(path + "/" + Environment.getSharedLibraryName(
|
||||
compressionType.getLibraryName()));
|
||||
break;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
// since they are optional, we ignore loading fails.
|
||||
|
@ -163,15 +163,6 @@ public class DbBenchmark {
|
||||
EXISTING
|
||||
}
|
||||
|
||||
enum CompressionType {
|
||||
NONE,
|
||||
SNAPPY,
|
||||
ZLIB,
|
||||
BZIP2,
|
||||
LZ4,
|
||||
LZ4HC
|
||||
}
|
||||
|
||||
static {
|
||||
RocksDB.loadLibrary();
|
||||
}
|
||||
@ -457,24 +448,16 @@ public class DbBenchmark {
|
||||
// options.setPrefixSize((Integer)flags_.get(Flag.prefix_size));
|
||||
// options.setKeysPerPrefix((Long)flags_.get(Flag.keys_per_prefix));
|
||||
compressionType_ = (String) flags.get(Flag.compression_type);
|
||||
compression_ = CompressionType.NONE;
|
||||
compression_ = CompressionType.NO_COMPRESSION;
|
||||
try {
|
||||
switch (compressionType_) {
|
||||
case "snappy":
|
||||
System.loadLibrary("snappy");
|
||||
break;
|
||||
case "zlib":
|
||||
System.loadLibrary("z");
|
||||
break;
|
||||
case "bzip2":
|
||||
System.loadLibrary("bzip2");
|
||||
break;
|
||||
case "lz4":
|
||||
System.loadLibrary("lz4");
|
||||
break;
|
||||
case "lz4hc":
|
||||
System.loadLibrary("lz4hc");
|
||||
break;
|
||||
if (compressionType_!=null) {
|
||||
final CompressionType compressionType =
|
||||
CompressionType.getCompressionType(compressionType_);
|
||||
if (compressionType != null &&
|
||||
compressionType != CompressionType.NO_COMPRESSION) {
|
||||
System.loadLibrary(compressionType.getLibraryName());
|
||||
}
|
||||
|
||||
}
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.format("Unable to load %s library:%s%n" +
|
||||
|
22
java/org/rocksdb/test/CompressionOptionsTest.java
Normal file
22
java/org/rocksdb/test/CompressionOptionsTest.java
Normal file
@ -0,0 +1,22 @@
|
||||
// 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.test;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.rocksdb.CompressionType;
|
||||
|
||||
|
||||
public class CompressionOptionsTest
|
||||
{
|
||||
@Test
|
||||
public void getCompressionType() {
|
||||
for (CompressionType compressionType : CompressionType.values()) {
|
||||
String libraryName = compressionType.getLibraryName();
|
||||
compressionType.equals(CompressionType.getCompressionType(
|
||||
libraryName));
|
||||
}
|
||||
}
|
||||
}
|
@ -53,6 +53,5 @@ public class MixedOptionsTest {
|
||||
options.optimizeUniversalStyleCompaction(400);
|
||||
options.optimizeForPointLookup(1024);
|
||||
options.prepareForBulkLoad();
|
||||
System.out.println("Mixed options test passed");
|
||||
}
|
||||
}
|
||||
|
@ -63,10 +63,6 @@ public class PlainTableConfigTest {
|
||||
public void encodingType() {
|
||||
PlainTableConfig plainTableConfig = new PlainTableConfig();
|
||||
plainTableConfig.setEncodingType(EncodingType.kPrefix);
|
||||
assertThat(EncodingType.valueOf("kPrefix")).isEqualTo(
|
||||
EncodingType.kPrefix);
|
||||
assertThat(EncodingType.values().length).
|
||||
isEqualTo(2);
|
||||
assertThat(plainTableConfig.encodingType()).isEqualTo(
|
||||
EncodingType.kPrefix);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user