1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
6 // This file implements the "bridge" between Java and C++ for rocksdb::Options.
9 #include "include/org_rocksdb_PlainTableConfig.h"
10 #include "include/org_rocksdb_BlockBasedTableConfig.h"
11 #include "rocksdb/table.h"
12 #include "rocksdb/cache.h"
13 #include "rocksdb/filter_policy.h"
16 * Class: org_rocksdb_PlainTableConfig
17 * Method: newTableFactoryHandle
18 * Signature: (IIDIIBZZ)J
20 jlong
Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle(
21 JNIEnv
* env
, jobject jobj
, jint jkey_size
, jint jbloom_bits_per_key
,
22 jdouble jhash_table_ratio
, jint jindex_sparseness
,
23 jint jhuge_page_tlb_size
, jbyte jencoding_type
,
24 jboolean jfull_scan_mode
, jboolean jstore_index_in_file
) {
25 rocksdb::PlainTableOptions options
= rocksdb::PlainTableOptions();
26 options
.user_key_len
= jkey_size
;
27 options
.bloom_bits_per_key
= jbloom_bits_per_key
;
28 options
.hash_table_ratio
= jhash_table_ratio
;
29 options
.index_sparseness
= jindex_sparseness
;
30 options
.huge_page_tlb_size
= jhuge_page_tlb_size
;
31 options
.encoding_type
= static_cast<rocksdb::EncodingType
>(
33 options
.full_scan_mode
= jfull_scan_mode
;
34 options
.store_index_in_file
= jstore_index_in_file
;
35 return reinterpret_cast<jlong
>(rocksdb::NewPlainTableFactory(options
));
39 * Class: org_rocksdb_BlockBasedTableConfig
40 * Method: newTableFactoryHandle
41 * Signature: (ZJIJIIZIZZZJIBBI)J
43 jlong
Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
44 JNIEnv
* env
, jobject jobj
, jboolean no_block_cache
, jlong block_cache_size
,
45 jint block_cache_num_shardbits
, jlong block_size
, jint block_size_deviation
,
46 jint block_restart_interval
, jboolean whole_key_filtering
,
47 jlong jfilterPolicy
, jboolean cache_index_and_filter_blocks
,
48 jboolean pin_l0_filter_and_index_blocks_in_cache
,
49 jboolean hash_index_allow_collision
, jlong block_cache_compressed_size
,
50 jint block_cache_compressd_num_shard_bits
, jbyte jchecksum_type
,
51 jbyte jindex_type
, jint jformat_version
) {
52 rocksdb::BlockBasedTableOptions options
;
53 options
.no_block_cache
= no_block_cache
;
55 if (!no_block_cache
&& block_cache_size
> 0) {
56 if (block_cache_num_shardbits
> 0) {
58 rocksdb::NewLRUCache(block_cache_size
, block_cache_num_shardbits
);
60 options
.block_cache
= rocksdb::NewLRUCache(block_cache_size
);
63 options
.block_size
= block_size
;
64 options
.block_size_deviation
= block_size_deviation
;
65 options
.block_restart_interval
= block_restart_interval
;
66 options
.whole_key_filtering
= whole_key_filtering
;
67 if (jfilterPolicy
> 0) {
68 std::shared_ptr
<rocksdb::FilterPolicy
> *pFilterPolicy
=
69 reinterpret_cast<std::shared_ptr
<rocksdb::FilterPolicy
> *>(
71 options
.filter_policy
= *pFilterPolicy
;
73 options
.cache_index_and_filter_blocks
= cache_index_and_filter_blocks
;
74 options
.pin_l0_filter_and_index_blocks_in_cache
=
75 pin_l0_filter_and_index_blocks_in_cache
;
76 options
.hash_index_allow_collision
= hash_index_allow_collision
;
77 if (block_cache_compressed_size
> 0) {
78 if (block_cache_compressd_num_shard_bits
> 0) {
80 rocksdb::NewLRUCache(block_cache_compressed_size
,
81 block_cache_compressd_num_shard_bits
);
83 options
.block_cache
= rocksdb::NewLRUCache(block_cache_compressed_size
);
86 options
.checksum
= static_cast<rocksdb::ChecksumType
>(jchecksum_type
);
87 options
.index_type
= static_cast<
88 rocksdb::BlockBasedTableOptions::IndexType
>(jindex_type
);
89 options
.format_version
= jformat_version
;
91 return reinterpret_cast<jlong
>(rocksdb::NewBlockBasedTableFactory(options
));