1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 // This file implements the "bridge" between Java and C++ for
7 // ROCKSDB_NAMESPACE::Options.
9 #include "rocksdb/table.h"
11 #include "include/org_rocksdb_BlockBasedTableConfig.h"
12 #include "include/org_rocksdb_PlainTableConfig.h"
14 #include "rocksdb/cache.h"
15 #include "rocksdb/filter_policy.h"
18 * Class: org_rocksdb_PlainTableConfig
19 * Method: newTableFactoryHandle
20 * Signature: (IIDIIBZZ)J
22 jlong
Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle(
23 JNIEnv
* /*env*/, jobject
/*jobj*/, jint jkey_size
,
24 jint jbloom_bits_per_key
, jdouble jhash_table_ratio
, jint jindex_sparseness
,
25 jint jhuge_page_tlb_size
, jbyte jencoding_type
, jboolean jfull_scan_mode
,
26 jboolean jstore_index_in_file
) {
27 ROCKSDB_NAMESPACE::PlainTableOptions options
=
28 ROCKSDB_NAMESPACE::PlainTableOptions();
29 options
.user_key_len
= jkey_size
;
30 options
.bloom_bits_per_key
= jbloom_bits_per_key
;
31 options
.hash_table_ratio
= jhash_table_ratio
;
32 options
.index_sparseness
= jindex_sparseness
;
33 options
.huge_page_tlb_size
= jhuge_page_tlb_size
;
34 options
.encoding_type
=
35 static_cast<ROCKSDB_NAMESPACE::EncodingType
>(jencoding_type
);
36 options
.full_scan_mode
= jfull_scan_mode
;
37 options
.store_index_in_file
= jstore_index_in_file
;
38 return reinterpret_cast<jlong
>(
39 ROCKSDB_NAMESPACE::NewPlainTableFactory(options
));
43 * Class: org_rocksdb_BlockBasedTableConfig
44 * Method: newTableFactoryHandle
45 * Signature: (ZZZZBBDBZJJJJIIIJZZJZZIIZZJIJI)J
47 jlong
Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
48 JNIEnv
*, jobject
, jboolean jcache_index_and_filter_blocks
,
49 jboolean jcache_index_and_filter_blocks_with_high_priority
,
50 jboolean jpin_l0_filter_and_index_blocks_in_cache
,
51 jboolean jpin_top_level_index_and_filter
, jbyte jindex_type_value
,
52 jbyte jdata_block_index_type_value
,
53 jdouble jdata_block_hash_table_util_ratio
, jbyte jchecksum_type_value
,
54 jboolean jno_block_cache
, jlong jblock_cache_handle
,
55 jlong jpersistent_cache_handle
,
56 jlong jblock_cache_compressed_handle
, jlong jblock_size
,
57 jint jblock_size_deviation
, jint jblock_restart_interval
,
58 jint jindex_block_restart_interval
, jlong jmetadata_block_size
,
59 jboolean jpartition_filters
, jboolean juse_delta_encoding
,
60 jlong jfilter_policy_handle
, jboolean jwhole_key_filtering
,
61 jboolean jverify_compression
, jint jread_amp_bytes_per_bit
,
62 jint jformat_version
, jboolean jenable_index_compression
,
63 jboolean jblock_align
, jlong jblock_cache_size
,
64 jint jblock_cache_num_shard_bits
, jlong jblock_cache_compressed_size
,
65 jint jblock_cache_compressed_num_shard_bits
) {
66 ROCKSDB_NAMESPACE::BlockBasedTableOptions options
;
67 options
.cache_index_and_filter_blocks
=
68 static_cast<bool>(jcache_index_and_filter_blocks
);
69 options
.cache_index_and_filter_blocks_with_high_priority
=
70 static_cast<bool>(jcache_index_and_filter_blocks_with_high_priority
);
71 options
.pin_l0_filter_and_index_blocks_in_cache
=
72 static_cast<bool>(jpin_l0_filter_and_index_blocks_in_cache
);
73 options
.pin_top_level_index_and_filter
=
74 static_cast<bool>(jpin_top_level_index_and_filter
);
76 ROCKSDB_NAMESPACE::IndexTypeJni::toCppIndexType(jindex_type_value
);
77 options
.data_block_index_type
=
78 ROCKSDB_NAMESPACE::DataBlockIndexTypeJni::toCppDataBlockIndexType(
79 jdata_block_index_type_value
);
80 options
.data_block_hash_table_util_ratio
=
81 static_cast<double>(jdata_block_hash_table_util_ratio
);
82 options
.checksum
= ROCKSDB_NAMESPACE::ChecksumTypeJni::toCppChecksumType(
83 jchecksum_type_value
);
84 options
.no_block_cache
= static_cast<bool>(jno_block_cache
);
85 if (options
.no_block_cache
) {
86 options
.block_cache
= nullptr;
88 if (jblock_cache_handle
> 0) {
89 std::shared_ptr
<ROCKSDB_NAMESPACE::Cache
> *pCache
=
90 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::Cache
> *>(
92 options
.block_cache
= *pCache
;
93 } else if (jblock_cache_size
>= 0) {
94 if (jblock_cache_num_shard_bits
> 0) {
95 options
.block_cache
= ROCKSDB_NAMESPACE::NewLRUCache(
96 static_cast<size_t>(jblock_cache_size
),
97 static_cast<int>(jblock_cache_num_shard_bits
));
99 options
.block_cache
= ROCKSDB_NAMESPACE::NewLRUCache(
100 static_cast<size_t>(jblock_cache_size
));
103 options
.no_block_cache
= true;
104 options
.block_cache
= nullptr;
107 if (jpersistent_cache_handle
> 0) {
108 std::shared_ptr
<ROCKSDB_NAMESPACE::PersistentCache
> *pCache
=
109 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::PersistentCache
> *>(
110 jpersistent_cache_handle
);
111 options
.persistent_cache
= *pCache
;
113 if (jblock_cache_compressed_handle
> 0) {
114 std::shared_ptr
<ROCKSDB_NAMESPACE::Cache
> *pCache
=
115 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::Cache
> *>(
116 jblock_cache_compressed_handle
);
117 options
.block_cache_compressed
= *pCache
;
118 } else if (jblock_cache_compressed_size
> 0) {
119 if (jblock_cache_compressed_num_shard_bits
> 0) {
120 options
.block_cache_compressed
= ROCKSDB_NAMESPACE::NewLRUCache(
121 static_cast<size_t>(jblock_cache_compressed_size
),
122 static_cast<int>(jblock_cache_compressed_num_shard_bits
));
124 options
.block_cache_compressed
= ROCKSDB_NAMESPACE::NewLRUCache(
125 static_cast<size_t>(jblock_cache_compressed_size
));
128 options
.block_size
= static_cast<size_t>(jblock_size
);
129 options
.block_size_deviation
= static_cast<int>(jblock_size_deviation
);
130 options
.block_restart_interval
= static_cast<int>(jblock_restart_interval
);
131 options
.index_block_restart_interval
= static_cast<int>(jindex_block_restart_interval
);
132 options
.metadata_block_size
= static_cast<uint64_t>(jmetadata_block_size
);
133 options
.partition_filters
= static_cast<bool>(jpartition_filters
);
134 options
.use_delta_encoding
= static_cast<bool>(juse_delta_encoding
);
135 if (jfilter_policy_handle
> 0) {
136 std::shared_ptr
<ROCKSDB_NAMESPACE::FilterPolicy
> *pFilterPolicy
=
137 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::FilterPolicy
> *>(
138 jfilter_policy_handle
);
139 options
.filter_policy
= *pFilterPolicy
;
141 options
.whole_key_filtering
= static_cast<bool>(jwhole_key_filtering
);
142 options
.verify_compression
= static_cast<bool>(jverify_compression
);
143 options
.read_amp_bytes_per_bit
= static_cast<uint32_t>(jread_amp_bytes_per_bit
);
144 options
.format_version
= static_cast<uint32_t>(jformat_version
);
145 options
.enable_index_compression
= static_cast<bool>(jenable_index_compression
);
146 options
.block_align
= static_cast<bool>(jblock_align
);
148 return reinterpret_cast<jlong
>(
149 ROCKSDB_NAMESPACE::NewBlockBasedTableFactory(options
));