2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2014-04-21 22:40:46 +00:00
|
|
|
// 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"
|
2014-08-25 21:22:55 +00:00
|
|
|
#include "include/org_rocksdb_BlockBasedTableConfig.h"
|
2014-04-21 22:40:46 +00:00
|
|
|
#include "rocksdb/table.h"
|
2014-08-25 21:22:55 +00:00
|
|
|
#include "rocksdb/cache.h"
|
|
|
|
#include "rocksdb/filter_policy.h"
|
2014-04-21 22:40:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_PlainTableConfig
|
|
|
|
* Method: newTableFactoryHandle
|
2014-10-20 20:42:32 +00:00
|
|
|
* Signature: (IIDIIBZZ)J
|
2014-04-21 22:40:46 +00:00
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle(
|
|
|
|
JNIEnv* env, jobject jobj, jint jkey_size, jint jbloom_bits_per_key,
|
2014-10-20 20:42:32 +00:00
|
|
|
jdouble jhash_table_ratio, jint jindex_sparseness,
|
|
|
|
jint jhuge_page_tlb_size, jbyte jencoding_type,
|
|
|
|
jboolean jfull_scan_mode, jboolean jstore_index_in_file) {
|
2014-07-21 16:19:28 +00:00
|
|
|
rocksdb::PlainTableOptions options = rocksdb::PlainTableOptions();
|
|
|
|
options.user_key_len = jkey_size;
|
|
|
|
options.bloom_bits_per_key = jbloom_bits_per_key;
|
|
|
|
options.hash_table_ratio = jhash_table_ratio;
|
|
|
|
options.index_sparseness = jindex_sparseness;
|
2014-10-20 20:42:32 +00:00
|
|
|
options.huge_page_tlb_size = jhuge_page_tlb_size;
|
|
|
|
options.encoding_type = static_cast<rocksdb::EncodingType>(
|
|
|
|
jencoding_type);
|
|
|
|
options.full_scan_mode = jfull_scan_mode;
|
|
|
|
options.store_index_in_file = jstore_index_in_file;
|
2014-07-21 16:19:28 +00:00
|
|
|
return reinterpret_cast<jlong>(rocksdb::NewPlainTableFactory(options));
|
2014-04-21 22:40:46 +00:00
|
|
|
}
|
2014-08-25 21:22:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BlockBasedTableConfig
|
|
|
|
* Method: newTableFactoryHandle
|
2015-01-16 22:00:30 +00:00
|
|
|
* Signature: (ZJIJIIZIZZJIBBI)J
|
2014-08-25 21:22:55 +00:00
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
|
|
|
|
JNIEnv* env, jobject jobj, jboolean no_block_cache, jlong block_cache_size,
|
2014-09-24 18:43:35 +00:00
|
|
|
jint block_cache_num_shardbits, jlong block_size, jint block_size_deviation,
|
2014-08-25 21:22:55 +00:00
|
|
|
jint block_restart_interval, jboolean whole_key_filtering,
|
2014-10-02 11:21:20 +00:00
|
|
|
jlong jfilterPolicy, jboolean cache_index_and_filter_blocks,
|
2014-09-24 18:43:35 +00:00
|
|
|
jboolean hash_index_allow_collision, jlong block_cache_compressed_size,
|
2014-10-20 20:42:32 +00:00
|
|
|
jint block_cache_compressd_num_shard_bits, jbyte jchecksum_type,
|
2015-01-16 22:00:30 +00:00
|
|
|
jbyte jindex_type, jint jformat_version) {
|
2014-08-25 21:22:55 +00:00
|
|
|
rocksdb::BlockBasedTableOptions options;
|
|
|
|
options.no_block_cache = no_block_cache;
|
|
|
|
|
|
|
|
if (!no_block_cache && block_cache_size > 0) {
|
2014-09-24 18:43:35 +00:00
|
|
|
if (block_cache_num_shardbits > 0) {
|
2014-08-25 21:22:55 +00:00
|
|
|
options.block_cache =
|
2014-09-24 18:43:35 +00:00
|
|
|
rocksdb::NewLRUCache(block_cache_size, block_cache_num_shardbits);
|
2014-08-25 21:22:55 +00:00
|
|
|
} else {
|
|
|
|
options.block_cache = rocksdb::NewLRUCache(block_cache_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
options.block_size = block_size;
|
|
|
|
options.block_size_deviation = block_size_deviation;
|
|
|
|
options.block_restart_interval = block_restart_interval;
|
|
|
|
options.whole_key_filtering = whole_key_filtering;
|
2014-10-02 11:21:20 +00:00
|
|
|
if (jfilterPolicy > 0) {
|
2014-10-14 16:38:50 +00:00
|
|
|
std::shared_ptr<rocksdb::FilterPolicy> *pFilterPolicy =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::FilterPolicy> *>(
|
|
|
|
jfilterPolicy);
|
|
|
|
options.filter_policy = *pFilterPolicy;
|
2014-08-25 21:22:55 +00:00
|
|
|
}
|
2014-09-24 18:43:35 +00:00
|
|
|
options.cache_index_and_filter_blocks = cache_index_and_filter_blocks;
|
|
|
|
options.hash_index_allow_collision = hash_index_allow_collision;
|
|
|
|
if (block_cache_compressed_size > 0) {
|
|
|
|
if (block_cache_compressd_num_shard_bits > 0) {
|
|
|
|
options.block_cache =
|
|
|
|
rocksdb::NewLRUCache(block_cache_compressed_size,
|
|
|
|
block_cache_compressd_num_shard_bits);
|
|
|
|
} else {
|
|
|
|
options.block_cache = rocksdb::NewLRUCache(block_cache_compressed_size);
|
|
|
|
}
|
|
|
|
}
|
2014-10-20 20:42:32 +00:00
|
|
|
options.checksum = static_cast<rocksdb::ChecksumType>(jchecksum_type);
|
|
|
|
options.index_type = static_cast<
|
|
|
|
rocksdb::BlockBasedTableOptions::IndexType>(jindex_type);
|
2015-01-16 22:00:30 +00:00
|
|
|
options.format_version = jformat_version;
|
2014-10-02 11:21:20 +00:00
|
|
|
|
2014-08-25 21:22:55 +00:00
|
|
|
return reinterpret_cast<jlong>(rocksdb::NewBlockBasedTableFactory(options));
|
|
|
|
}
|