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"
13 #include "include/org_rocksdb_BlockBasedTableConfig.h"
14 #include "include/org_rocksdb_PlainTableConfig.h"
16 #include "rocksdb/cache.h"
17 #include "rocksdb/filter_policy.h"
18 #include "rocksjni/cplusplus_to_java_convert.h"
21 * Class: org_rocksdb_PlainTableConfig
22 * Method: newTableFactoryHandle
23 * Signature: (IIDIIBZZ)J
25 jlong
Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle(
26 JNIEnv
* /*env*/, jobject
/*jobj*/, jint jkey_size
,
27 jint jbloom_bits_per_key
, jdouble jhash_table_ratio
, jint jindex_sparseness
,
28 jint jhuge_page_tlb_size
, jbyte jencoding_type
, jboolean jfull_scan_mode
,
29 jboolean jstore_index_in_file
) {
30 ROCKSDB_NAMESPACE::PlainTableOptions options
=
31 ROCKSDB_NAMESPACE::PlainTableOptions();
32 options
.user_key_len
= jkey_size
;
33 options
.bloom_bits_per_key
= jbloom_bits_per_key
;
34 options
.hash_table_ratio
= jhash_table_ratio
;
35 options
.index_sparseness
= jindex_sparseness
;
36 options
.huge_page_tlb_size
= jhuge_page_tlb_size
;
37 options
.encoding_type
=
38 static_cast<ROCKSDB_NAMESPACE::EncodingType
>(jencoding_type
);
39 options
.full_scan_mode
= jfull_scan_mode
;
40 options
.store_index_in_file
= jstore_index_in_file
;
41 return GET_CPLUSPLUS_POINTER(
42 ROCKSDB_NAMESPACE::NewPlainTableFactory(options
));
46 * Class: org_rocksdb_BlockBasedTableConfig
47 * Method: newTableFactoryHandle
48 * Signature: (ZZZZBBDBZJJJJIIIJZZZJZZIIZZBJIJI)J
50 jlong
Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
51 JNIEnv
*, jobject
, jboolean jcache_index_and_filter_blocks
,
52 jboolean jcache_index_and_filter_blocks_with_high_priority
,
53 jboolean jpin_l0_filter_and_index_blocks_in_cache
,
54 jboolean jpin_top_level_index_and_filter
, jbyte jindex_type_value
,
55 jbyte jdata_block_index_type_value
,
56 jdouble jdata_block_hash_table_util_ratio
, jbyte jchecksum_type_value
,
57 jboolean jno_block_cache
, jlong jblock_cache_handle
,
58 jlong jpersistent_cache_handle
, jlong jblock_cache_compressed_handle
,
59 jlong jblock_size
, jint jblock_size_deviation
, jint jblock_restart_interval
,
60 jint jindex_block_restart_interval
, jlong jmetadata_block_size
,
61 jboolean jpartition_filters
, jboolean joptimize_filters_for_memory
,
62 jboolean juse_delta_encoding
, jlong jfilter_policy_handle
,
63 jboolean jwhole_key_filtering
, jboolean jverify_compression
,
64 jint jread_amp_bytes_per_bit
, jint jformat_version
,
65 jboolean jenable_index_compression
, jboolean jblock_align
,
66 jbyte jindex_shortening
, jlong jblock_cache_size
,
67 jint jblock_cache_num_shard_bits
, jlong jblock_cache_compressed_size
,
68 jint jblock_cache_compressed_num_shard_bits
) {
69 ROCKSDB_NAMESPACE::BlockBasedTableOptions options
;
70 options
.cache_index_and_filter_blocks
=
71 static_cast<bool>(jcache_index_and_filter_blocks
);
72 options
.cache_index_and_filter_blocks_with_high_priority
=
73 static_cast<bool>(jcache_index_and_filter_blocks_with_high_priority
);
74 options
.pin_l0_filter_and_index_blocks_in_cache
=
75 static_cast<bool>(jpin_l0_filter_and_index_blocks_in_cache
);
76 options
.pin_top_level_index_and_filter
=
77 static_cast<bool>(jpin_top_level_index_and_filter
);
79 ROCKSDB_NAMESPACE::IndexTypeJni::toCppIndexType(jindex_type_value
);
80 options
.data_block_index_type
=
81 ROCKSDB_NAMESPACE::DataBlockIndexTypeJni::toCppDataBlockIndexType(
82 jdata_block_index_type_value
);
83 options
.data_block_hash_table_util_ratio
=
84 static_cast<double>(jdata_block_hash_table_util_ratio
);
85 options
.checksum
= ROCKSDB_NAMESPACE::ChecksumTypeJni::toCppChecksumType(
86 jchecksum_type_value
);
87 options
.no_block_cache
= static_cast<bool>(jno_block_cache
);
88 if (options
.no_block_cache
) {
89 options
.block_cache
= nullptr;
91 if (jblock_cache_handle
> 0) {
92 std::shared_ptr
<ROCKSDB_NAMESPACE::Cache
> *pCache
=
93 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::Cache
> *>(
95 options
.block_cache
= *pCache
;
96 } else if (jblock_cache_size
>= 0) {
97 if (jblock_cache_num_shard_bits
> 0) {
98 options
.block_cache
= ROCKSDB_NAMESPACE::NewLRUCache(
99 static_cast<size_t>(jblock_cache_size
),
100 static_cast<int>(jblock_cache_num_shard_bits
));
102 options
.block_cache
= ROCKSDB_NAMESPACE::NewLRUCache(
103 static_cast<size_t>(jblock_cache_size
));
106 options
.no_block_cache
= true;
107 options
.block_cache
= nullptr;
110 if (jpersistent_cache_handle
> 0) {
111 std::shared_ptr
<ROCKSDB_NAMESPACE::PersistentCache
> *pCache
=
112 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::PersistentCache
> *>(
113 jpersistent_cache_handle
);
114 options
.persistent_cache
= *pCache
;
116 if (jblock_cache_compressed_handle
> 0) {
117 std::shared_ptr
<ROCKSDB_NAMESPACE::Cache
> *pCache
=
118 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::Cache
> *>(
119 jblock_cache_compressed_handle
);
120 options
.block_cache_compressed
= *pCache
;
121 } else if (jblock_cache_compressed_size
> 0) {
122 if (jblock_cache_compressed_num_shard_bits
> 0) {
123 options
.block_cache_compressed
= ROCKSDB_NAMESPACE::NewLRUCache(
124 static_cast<size_t>(jblock_cache_compressed_size
),
125 static_cast<int>(jblock_cache_compressed_num_shard_bits
));
127 options
.block_cache_compressed
= ROCKSDB_NAMESPACE::NewLRUCache(
128 static_cast<size_t>(jblock_cache_compressed_size
));
131 options
.block_size
= static_cast<size_t>(jblock_size
);
132 options
.block_size_deviation
= static_cast<int>(jblock_size_deviation
);
133 options
.block_restart_interval
= static_cast<int>(jblock_restart_interval
);
134 options
.index_block_restart_interval
=
135 static_cast<int>(jindex_block_restart_interval
);
136 options
.metadata_block_size
= static_cast<uint64_t>(jmetadata_block_size
);
137 options
.partition_filters
= static_cast<bool>(jpartition_filters
);
138 options
.optimize_filters_for_memory
=
139 static_cast<bool>(joptimize_filters_for_memory
);
140 options
.use_delta_encoding
= static_cast<bool>(juse_delta_encoding
);
141 if (jfilter_policy_handle
> 0) {
142 std::shared_ptr
<ROCKSDB_NAMESPACE::FilterPolicy
> *pFilterPolicy
=
143 reinterpret_cast<std::shared_ptr
<ROCKSDB_NAMESPACE::FilterPolicy
> *>(
144 jfilter_policy_handle
);
145 options
.filter_policy
= *pFilterPolicy
;
147 options
.whole_key_filtering
= static_cast<bool>(jwhole_key_filtering
);
148 options
.verify_compression
= static_cast<bool>(jverify_compression
);
149 options
.read_amp_bytes_per_bit
=
150 static_cast<uint32_t>(jread_amp_bytes_per_bit
);
151 options
.format_version
= static_cast<uint32_t>(jformat_version
);
152 options
.enable_index_compression
=
153 static_cast<bool>(jenable_index_compression
);
154 options
.block_align
= static_cast<bool>(jblock_align
);
155 options
.index_shortening
=
156 ROCKSDB_NAMESPACE::IndexShorteningModeJni::toCppIndexShorteningMode(
159 return GET_CPLUSPLUS_POINTER(
160 ROCKSDB_NAMESPACE::NewBlockBasedTableFactory(options
));