Summary: Add Java bindings for memtables and sst format. Specifically, add two abstract Java classses --- MemTableConfig and SstFormatConfig. Each MemTable / SST implementation should has its own config class extends MemTableConfig / SstFormatConfig respectively and pass it to Options via setMemTableConfig / setSstConfig. Test Plan: make rocksdbjava make jdb_test make jdb_bench java/jdb_bench.sh \ --benchmarks=fillseq,readrandom,readwhilewriting \ --memtablerep=hash_skiplist \ --use_plain_table=1 \ --key_size=20 \ --prefix_size=12 \ --value_size=100 \ --cache_size=17179869184 \ --disable_wal=0 \ --sync=0 \ Reviewers: haobo, ankgup87, sdong Reviewed By: haobo CC: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D17997main
parent
8dc34364d2
commit
ef8b8a8ef6
@ -0,0 +1 @@ |
|||||||
|
java -Djava.library.path=.:../ -cp "rocksdbjni.jar:.:./*" org.rocksdb.benchmark.DbBenchmark $@ |
@ -0,0 +1,52 @@ |
|||||||
|
package org.rocksdb; |
||||||
|
|
||||||
|
/** |
||||||
|
* The config for hash linked list memtable representation |
||||||
|
* Such memtable contains a fix-sized array of buckets, where |
||||||
|
* each bucket points to a sorted singly-linked |
||||||
|
* list (or null if the bucket is empty). |
||||||
|
* |
||||||
|
* Note that since this mem-table representation relies on the |
||||||
|
* key prefix, it is required to invoke one of the usePrefixExtractor |
||||||
|
* functions to specify how to extract key prefix given a key. |
||||||
|
* If proper prefix-extractor is not set, then RocksDB will |
||||||
|
* use the default memtable representation (SkipList) instead |
||||||
|
* and post a warning in the LOG. |
||||||
|
*/ |
||||||
|
public class HashLinkedListMemTableConfig extends MemTableConfig { |
||||||
|
public static final long DEFAULT_BUCKET_COUNT = 50000; |
||||||
|
|
||||||
|
public HashLinkedListMemTableConfig() { |
||||||
|
bucketCount_ = DEFAULT_BUCKET_COUNT; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set the number of buckets in the fixed-size array used |
||||||
|
* in the hash linked-list mem-table. |
||||||
|
* |
||||||
|
* @param count the number of hash buckets. |
||||||
|
* @return the reference to the current HashLinkedListMemTableConfig. |
||||||
|
*/ |
||||||
|
public HashLinkedListMemTableConfig setBucketCount(long count) { |
||||||
|
bucketCount_ = count; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns the number of buckets that will be used in the memtable |
||||||
|
* created based on this config. |
||||||
|
* |
||||||
|
* @return the number of buckets |
||||||
|
*/ |
||||||
|
public long bucketCount() { |
||||||
|
return bucketCount_; |
||||||
|
} |
||||||
|
|
||||||
|
@Override protected long newMemTableFactoryHandle() { |
||||||
|
return newMemTableFactoryHandle(bucketCount_); |
||||||
|
} |
||||||
|
|
||||||
|
private native long newMemTableFactoryHandle(long bucketCount); |
||||||
|
|
||||||
|
private long bucketCount_; |
||||||
|
} |
@ -0,0 +1,97 @@ |
|||||||
|
package org.rocksdb; |
||||||
|
|
||||||
|
/** |
||||||
|
* The config for hash skip-list mem-table representation. |
||||||
|
* Such mem-table representation contains a fix-sized array of |
||||||
|
* buckets, where each bucket points to a skiplist (or null if the |
||||||
|
* bucket is empty). |
||||||
|
* |
||||||
|
* Note that since this mem-table representation relies on the |
||||||
|
* key prefix, it is required to invoke one of the usePrefixExtractor |
||||||
|
* functions to specify how to extract key prefix given a key. |
||||||
|
* If proper prefix-extractor is not set, then RocksDB will |
||||||
|
* use the default memtable representation (SkipList) instead |
||||||
|
* and post a warning in the LOG. |
||||||
|
*/ |
||||||
|
public class HashSkipListMemTableConfig extends MemTableConfig { |
||||||
|
public static final int DEFAULT_BUCKET_COUNT = 1000000; |
||||||
|
public static final int DEFAULT_BRANCHING_FACTOR = 4; |
||||||
|
public static final int DEFAULT_HEIGHT = 4; |
||||||
|
|
||||||
|
public HashSkipListMemTableConfig() { |
||||||
|
bucketCount_ = DEFAULT_BUCKET_COUNT; |
||||||
|
branchingFactor_ = DEFAULT_BRANCHING_FACTOR; |
||||||
|
height_ = DEFAULT_HEIGHT; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set the number of hash buckets used in the hash skiplist memtable. |
||||||
|
* Default = 1000000. |
||||||
|
* |
||||||
|
* @param count the number of hash buckets used in the hash |
||||||
|
* skiplist memtable. |
||||||
|
* @return the reference to the current HashSkipListMemTableConfig. |
||||||
|
*/ |
||||||
|
public HashSkipListMemTableConfig setBucketCount(long count) { |
||||||
|
bucketCount_ = count; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the number of hash buckets |
||||||
|
*/ |
||||||
|
public long bucketCount() { |
||||||
|
return bucketCount_; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set the height of the skip list. Default = 4. |
||||||
|
* |
||||||
|
* @return the reference to the current HashSkipListMemTableConfig. |
||||||
|
*/ |
||||||
|
public HashSkipListMemTableConfig setHeight(int height) { |
||||||
|
height_ = height; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the height of the skip list. |
||||||
|
*/ |
||||||
|
public int height() { |
||||||
|
return height_; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set the branching factor used in the hash skip-list memtable. |
||||||
|
* This factor controls the probabilistic size ratio between adjacent |
||||||
|
* links in the skip list. |
||||||
|
* |
||||||
|
* @param bf the probabilistic size ratio between adjacent link |
||||||
|
* lists in the skip list. |
||||||
|
* @return the reference to the current HashSkipListMemTableConfig. |
||||||
|
*/ |
||||||
|
public HashSkipListMemTableConfig setBranchingFactor(int bf) { |
||||||
|
branchingFactor_ = bf; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return branching factor, the probabilistic size ratio between |
||||||
|
* adjacent links in the skip list. |
||||||
|
*/ |
||||||
|
public int branchingFactor() { |
||||||
|
return branchingFactor_; |
||||||
|
} |
||||||
|
|
||||||
|
@Override protected long newMemTableFactoryHandle() { |
||||||
|
return newMemTableFactoryHandle( |
||||||
|
bucketCount_, height_, branchingFactor_); |
||||||
|
} |
||||||
|
|
||||||
|
private native long newMemTableFactoryHandle( |
||||||
|
long bucketCount, int height, int branchingFactor); |
||||||
|
|
||||||
|
private long bucketCount_; |
||||||
|
private int branchingFactor_; |
||||||
|
private int height_; |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
// 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; |
||||||
|
|
||||||
|
/** |
||||||
|
* MemTableConfig is used to config the internal mem-table of a RocksDB. |
||||||
|
* It is required for each memtable to have one such sub-class to allow |
||||||
|
* Java developers to use it. |
||||||
|
* |
||||||
|
* To make a RocksDB to use a specific MemTable format, its associated |
||||||
|
* MemTableConfig should be properly set and passed into Options |
||||||
|
* via Options.setMemTableFactory() and open the db using that Options. |
||||||
|
* |
||||||
|
* @see Options |
||||||
|
*/ |
||||||
|
public abstract class MemTableConfig { |
||||||
|
/** |
||||||
|
* This function should only be called by Options.setMemTableConfig(), |
||||||
|
* which will create a c++ shared-pointer to the c++ MemTableRepFactory |
||||||
|
* that associated with the Java MemTableConfig. |
||||||
|
* |
||||||
|
* @see Options.setMemTableFactory() |
||||||
|
*/ |
||||||
|
abstract protected long newMemTableFactoryHandle(); |
||||||
|
} |
@ -0,0 +1,123 @@ |
|||||||
|
// 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; |
||||||
|
|
||||||
|
/** |
||||||
|
* The config for plain table sst format. |
||||||
|
* |
||||||
|
* PlainTable is a RocksDB's SST file format optimized for low query latency |
||||||
|
* on pure-memory or really low-latency media. It also support prefix |
||||||
|
* hash feature. |
||||||
|
*/ |
||||||
|
public class PlainTableConfig extends TableFormatConfig { |
||||||
|
public static final int VARIABLE_LENGTH = 0; |
||||||
|
public static final int DEFAULT_BLOOM_BITS_PER_KEY = 10; |
||||||
|
public static final double DEFAULT_HASH_TABLE_RATIO = 0.75; |
||||||
|
public static final int DEFAULT_INDEX_SPARSENESS = 16; |
||||||
|
|
||||||
|
public PlainTableConfig() { |
||||||
|
keySize_ = VARIABLE_LENGTH; |
||||||
|
bloomBitsPerKey_ = DEFAULT_BLOOM_BITS_PER_KEY; |
||||||
|
hashTableRatio_ = DEFAULT_HASH_TABLE_RATIO; |
||||||
|
indexSparseness_ = DEFAULT_INDEX_SPARSENESS; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set the length of the user key. If it is set to be VARIABLE_LENGTH, |
||||||
|
* then it indicates the user keys are variable-lengthed. Otherwise, |
||||||
|
* all the keys need to have the same length in byte. |
||||||
|
* DEFAULT: VARIABLE_LENGTH |
||||||
|
* |
||||||
|
* @param keySize the length of the user key. |
||||||
|
* @return the reference to the current config. |
||||||
|
*/ |
||||||
|
public PlainTableConfig setKeySize(int keySize) { |
||||||
|
keySize_ = keySize; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the specified size of the user key. If VARIABLE_LENGTH, |
||||||
|
* then it indicates variable-length key. |
||||||
|
*/ |
||||||
|
public int keySize() { |
||||||
|
return keySize_; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set the number of bits per key used by the internal bloom filter |
||||||
|
* in the plain table sst format. |
||||||
|
* |
||||||
|
* @param bitsPerKey the number of bits per key for bloom filer. |
||||||
|
* @return the reference to the current config. |
||||||
|
*/ |
||||||
|
public PlainTableConfig setBloomBitsPerKey(int bitsPerKey) { |
||||||
|
bloomBitsPerKey_ = bitsPerKey; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the number of bits per key used for the bloom filter. |
||||||
|
*/ |
||||||
|
public int bloomBitsPerKey() { |
||||||
|
return bloomBitsPerKey_; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* hashTableRatio is the desired utilization of the hash table used |
||||||
|
* for prefix hashing. The ideal ratio would be the number of |
||||||
|
* prefixes / the number of hash buckets. If this value is set to |
||||||
|
* zero, then hash table will not be used. |
||||||
|
* |
||||||
|
* @param ratio the hash table ratio. |
||||||
|
* @return the reference to the current config. |
||||||
|
*/ |
||||||
|
public PlainTableConfig setHashTableRatio(double ratio) { |
||||||
|
hashTableRatio_ = ratio; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the hash table ratio. |
||||||
|
*/ |
||||||
|
public double hashTableRatio() { |
||||||
|
return hashTableRatio_; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Index sparseness determines the index interval for keys inside the |
||||||
|
* same prefix. This number is equal to the maximum number of linear |
||||||
|
* search required after hash and binary search. If it's set to 0, |
||||||
|
* then each key will be indexed. |
||||||
|
* |
||||||
|
* @param sparseness the index sparseness. |
||||||
|
* @return the reference to the current config. |
||||||
|
*/ |
||||||
|
public PlainTableConfig setIndexSparseness(int sparseness) { |
||||||
|
indexSparseness_ = sparseness; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the index sparseness. |
||||||
|
*/ |
||||||
|
public int indexSparseness() { |
||||||
|
return indexSparseness_; |
||||||
|
} |
||||||
|
|
||||||
|
@Override protected long newTableFactoryHandle() { |
||||||
|
return newTableFactoryHandle(keySize_, bloomBitsPerKey_, |
||||||
|
hashTableRatio_, indexSparseness_); |
||||||
|
} |
||||||
|
|
||||||
|
private native long newTableFactoryHandle( |
||||||
|
int keySize, int bloomBitsPerKey, |
||||||
|
double hashTableRatio, int indexSparseness); |
||||||
|
|
||||||
|
private int keySize_; |
||||||
|
private int bloomBitsPerKey_; |
||||||
|
private double hashTableRatio_; |
||||||
|
private int indexSparseness_; |
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
package org.rocksdb; |
||||||
|
|
||||||
|
/** |
||||||
|
* The config for skip-list memtable representation. |
||||||
|
*/ |
||||||
|
public class SkipListMemTableConfig extends MemTableConfig { |
||||||
|
public SkipListMemTableConfig() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override protected long newMemTableFactoryHandle() { |
||||||
|
return newMemTableFactoryHandle0(); |
||||||
|
} |
||||||
|
|
||||||
|
private native long newMemTableFactoryHandle0(); |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
// 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; |
||||||
|
|
||||||
|
/** |
||||||
|
* TableFormatConfig is used to config the internal Table format of a RocksDB. |
||||||
|
* To make a RocksDB to use a specific Table format, its associated |
||||||
|
* TableFormatConfig should be properly set and passed into Options via |
||||||
|
* Options.setTableFormatConfig() and open the db using that Options. |
||||||
|
*/ |
||||||
|
public abstract class TableFormatConfig { |
||||||
|
/** |
||||||
|
* This function should only be called by Options.setTableFormatConfig(), |
||||||
|
* which will create a c++ shared-pointer to the c++ TableFactory |
||||||
|
* that associated with the Java TableFormatConfig. |
||||||
|
*/ |
||||||
|
abstract protected long newTableFactoryHandle(); |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
package org.rocksdb; |
||||||
|
|
||||||
|
/** |
||||||
|
* The config for vector memtable representation. |
||||||
|
*/ |
||||||
|
public class VectorMemTableConfig extends MemTableConfig { |
||||||
|
public static final int DEFAULT_RESERVED_SIZE = 0; |
||||||
|
public VectorMemTableConfig() { |
||||||
|
reservedSize_ = DEFAULT_RESERVED_SIZE; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set the initial size of the vector that will be used |
||||||
|
* by the memtable created based on this config. |
||||||
|
* |
||||||
|
* @param size the initial size of the vector. |
||||||
|
* @return the reference to the current config. |
||||||
|
*/ |
||||||
|
public VectorMemTableConfig setReservedSize(int size) { |
||||||
|
reservedSize_ = size; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns the initial size of the vector used by the memtable |
||||||
|
* created based on this config. |
||||||
|
* |
||||||
|
* @return the initial size of the vector. |
||||||
|
*/ |
||||||
|
public int reservedSize() { |
||||||
|
return reservedSize_; |
||||||
|
} |
||||||
|
|
||||||
|
@Override protected long newMemTableFactoryHandle() { |
||||||
|
return newMemTableFactoryHandle(reservedSize_); |
||||||
|
} |
||||||
|
|
||||||
|
private native long newMemTableFactoryHandle(long reservedSize); |
||||||
|
private int reservedSize_; |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// This file implements the "bridge" between Java and C++ for MemTables.
|
||||||
|
|
||||||
|
#include "include/org_rocksdb_HashSkipListMemTableConfig.h" |
||||||
|
#include "include/org_rocksdb_HashLinkedListMemTableConfig.h" |
||||||
|
#include "include/org_rocksdb_VectorMemTableConfig.h" |
||||||
|
#include "include/org_rocksdb_SkipListMemTableConfig.h" |
||||||
|
#include "rocksdb/memtablerep.h" |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_rocksdb_HashSkipListMemTableConfig |
||||||
|
* Method: newMemTableFactoryHandle |
||||||
|
* Signature: (JII)J |
||||||
|
*/ |
||||||
|
jlong Java_org_rocksdb_HashSkipListMemTableConfig_newMemTableFactoryHandle( |
||||||
|
JNIEnv* env, jobject jobj, jlong jbucket_count, |
||||||
|
jint jheight, jint jbranching_factor) { |
||||||
|
return reinterpret_cast<jlong>(rocksdb::NewHashSkipListRepFactory( |
||||||
|
static_cast<size_t>(jbucket_count), |
||||||
|
static_cast<int32_t>(jheight), |
||||||
|
static_cast<int32_t>(jbranching_factor))); |
||||||
|
} |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_rocksdb_HashLinkedListMemTableConfig |
||||||
|
* Method: newMemTableFactoryHandle |
||||||
|
* Signature: (J)J |
||||||
|
*/ |
||||||
|
jlong Java_org_rocksdb_HashLinkedListMemTableConfig_newMemTableFactoryHandle( |
||||||
|
JNIEnv* env, jobject jobj, jlong jbucket_count) { |
||||||
|
return reinterpret_cast<jlong>(rocksdb::NewHashLinkListRepFactory( |
||||||
|
static_cast<size_t>(jbucket_count))); |
||||||
|
} |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_rocksdb_VectorMemTableConfig |
||||||
|
* Method: newMemTableFactoryHandle |
||||||
|
* Signature: (J)J |
||||||
|
*/ |
||||||
|
jlong Java_org_rocksdb_VectorMemTableConfig_newMemTableFactoryHandle( |
||||||
|
JNIEnv* env, jobject jobj, jlong jreserved_size) { |
||||||
|
return reinterpret_cast<jlong>(new rocksdb::VectorRepFactory( |
||||||
|
static_cast<size_t>(jreserved_size))); |
||||||
|
} |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_rocksdb_SkipListMemTableConfig |
||||||
|
* Method: newMemTableFactoryHandle0 |
||||||
|
* Signature: ()J |
||||||
|
*/ |
||||||
|
jlong Java_org_rocksdb_SkipListMemTableConfig_newMemTableFactoryHandle0( |
||||||
|
JNIEnv* env, jobject jobj) { |
||||||
|
return reinterpret_cast<jlong>(new rocksdb::SkipListFactory()); |
||||||
|
} |
@ -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.
|
||||||
|
//
|
||||||
|
// This file implements the "bridge" between Java and C++ for rocksdb::Options.
|
||||||
|
|
||||||
|
#include <jni.h> |
||||||
|
#include "include/org_rocksdb_PlainTableConfig.h" |
||||||
|
#include "rocksdb/table.h" |
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_rocksdb_PlainTableConfig |
||||||
|
* Method: newTableFactoryHandle |
||||||
|
* Signature: (IIDI)J |
||||||
|
*/ |
||||||
|
jlong Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle( |
||||||
|
JNIEnv* env, jobject jobj, jint jkey_size, jint jbloom_bits_per_key, |
||||||
|
jdouble jhash_table_ratio, jint jindex_sparseness) { |
||||||
|
return reinterpret_cast<jlong>(rocksdb::NewPlainTableFactory( |
||||||
|
static_cast<uint32_t>(jkey_size), |
||||||
|
static_cast<int>(jbloom_bits_per_key), |
||||||
|
static_cast<double>(jhash_table_ratio), |
||||||
|
static_cast<size_t>(jindex_sparseness))); |
||||||
|
} |
Loading…
Reference in new issue