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 rocksdb::Options.
8 #include "rocksdb/table.h"
10 #include "include/org_rocksdb_BlockBasedTableConfig.h"
11 #include "include/org_rocksdb_PlainTableConfig.h"
13 #include "rocksdb/cache.h"
14 #include "rocksdb/filter_policy.h"
17 * Class: org_rocksdb_PlainTableConfig
18 * Method: newTableFactoryHandle
19 * Signature: (IIDIIBZZ)J
21 jlong
Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle(
22 JNIEnv
* /*env*/, jobject
/*jobj*/, jint jkey_size
,
23 jint jbloom_bits_per_key
, jdouble jhash_table_ratio
, jint jindex_sparseness
,
24 jint jhuge_page_tlb_size
, jbyte jencoding_type
, jboolean jfull_scan_mode
,
25 jboolean jstore_index_in_file
) {
26 rocksdb::PlainTableOptions options
= rocksdb::PlainTableOptions();
27 options
.user_key_len
= jkey_size
;
28 options
.bloom_bits_per_key
= jbloom_bits_per_key
;
29 options
.hash_table_ratio
= jhash_table_ratio
;
30 options
.index_sparseness
= jindex_sparseness
;
31 options
.huge_page_tlb_size
= jhuge_page_tlb_size
;
32 options
.encoding_type
= static_cast<rocksdb::EncodingType
>(jencoding_type
);
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: (ZZZZBBDBZJJJJIIIJZZJZZIIZZJIJI)J
43 jlong
Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
44 JNIEnv
*, jobject
, jboolean jcache_index_and_filter_blocks
,
45 jboolean jcache_index_and_filter_blocks_with_high_priority
,
46 jboolean jpin_l0_filter_and_index_blocks_in_cache
,
47 jboolean jpin_top_level_index_and_filter
, jbyte jindex_type_value
,
48 jbyte jdata_block_index_type_value
,
49 jdouble jdata_block_hash_table_util_ratio
, jbyte jchecksum_type_value
,
50 jboolean jno_block_cache
, jlong jblock_cache_handle
,
51 jlong jpersistent_cache_handle
,
52 jlong jblock_cache_compressed_handle
, jlong jblock_size
,
53 jint jblock_size_deviation
, jint jblock_restart_interval
,
54 jint jindex_block_restart_interval
, jlong jmetadata_block_size
,
55 jboolean jpartition_filters
, jboolean juse_delta_encoding
,
56 jlong jfilter_policy_handle
, jboolean jwhole_key_filtering
,
57 jboolean jverify_compression
, jint jread_amp_bytes_per_bit
,
58 jint jformat_version
, jboolean jenable_index_compression
,
59 jboolean jblock_align
, jlong jblock_cache_size
,
60 jint jblock_cache_num_shard_bits
, jlong jblock_cache_compressed_size
,
61 jint jblock_cache_compressed_num_shard_bits
) {
62 rocksdb::BlockBasedTableOptions options
;
63 options
.cache_index_and_filter_blocks
=
64 static_cast<bool>(jcache_index_and_filter_blocks
);
65 options
.cache_index_and_filter_blocks_with_high_priority
=
66 static_cast<bool>(jcache_index_and_filter_blocks_with_high_priority
);
67 options
.pin_l0_filter_and_index_blocks_in_cache
=
68 static_cast<bool>(jpin_l0_filter_and_index_blocks_in_cache
);
69 options
.pin_top_level_index_and_filter
=
70 static_cast<bool>(jpin_top_level_index_and_filter
);
72 rocksdb::IndexTypeJni::toCppIndexType(jindex_type_value
);
73 options
.data_block_index_type
=
74 rocksdb::DataBlockIndexTypeJni::toCppDataBlockIndexType(
75 jdata_block_index_type_value
);
76 options
.data_block_hash_table_util_ratio
=
77 static_cast<double>(jdata_block_hash_table_util_ratio
);
79 rocksdb::ChecksumTypeJni::toCppChecksumType(jchecksum_type_value
);
80 options
.no_block_cache
= static_cast<bool>(jno_block_cache
);
81 if (options
.no_block_cache
) {
82 options
.block_cache
= nullptr;
84 if (jblock_cache_handle
> 0) {
85 std::shared_ptr
<rocksdb::Cache
> *pCache
=
86 reinterpret_cast<std::shared_ptr
<rocksdb::Cache
> *>(jblock_cache_handle
);
87 options
.block_cache
= *pCache
;
88 } else if (jblock_cache_size
> 0) {
89 if (jblock_cache_num_shard_bits
> 0) {
90 options
.block_cache
= rocksdb::NewLRUCache(
91 static_cast<size_t>(jblock_cache_size
),
92 static_cast<int>(jblock_cache_num_shard_bits
));
94 options
.block_cache
= rocksdb::NewLRUCache(
95 static_cast<size_t>(jblock_cache_size
));
99 if (jpersistent_cache_handle
> 0) {
100 std::shared_ptr
<rocksdb::PersistentCache
> *pCache
=
101 reinterpret_cast<std::shared_ptr
<rocksdb::PersistentCache
> *>(jpersistent_cache_handle
);
102 options
.persistent_cache
= *pCache
;
104 if (jblock_cache_compressed_handle
> 0) {
105 std::shared_ptr
<rocksdb::Cache
> *pCache
=
106 reinterpret_cast<std::shared_ptr
<rocksdb::Cache
> *>(jblock_cache_compressed_handle
);
107 options
.block_cache_compressed
= *pCache
;
108 } else if (jblock_cache_compressed_size
> 0) {
109 if (jblock_cache_compressed_num_shard_bits
> 0) {
110 options
.block_cache_compressed
= rocksdb::NewLRUCache(
111 static_cast<size_t>(jblock_cache_compressed_size
),
112 static_cast<int>(jblock_cache_compressed_num_shard_bits
));
114 options
.block_cache_compressed
= rocksdb::NewLRUCache(
115 static_cast<size_t>(jblock_cache_compressed_size
));
118 options
.block_size
= static_cast<size_t>(jblock_size
);
119 options
.block_size_deviation
= static_cast<int>(jblock_size_deviation
);
120 options
.block_restart_interval
= static_cast<int>(jblock_restart_interval
);
121 options
.index_block_restart_interval
= static_cast<int>(jindex_block_restart_interval
);
122 options
.metadata_block_size
= static_cast<uint64_t>(jmetadata_block_size
);
123 options
.partition_filters
= static_cast<bool>(jpartition_filters
);
124 options
.use_delta_encoding
= static_cast<bool>(juse_delta_encoding
);
125 if (jfilter_policy_handle
> 0) {
126 std::shared_ptr
<rocksdb::FilterPolicy
> *pFilterPolicy
=
127 reinterpret_cast<std::shared_ptr
<rocksdb::FilterPolicy
> *>(
128 jfilter_policy_handle
);
129 options
.filter_policy
= *pFilterPolicy
;
131 options
.whole_key_filtering
= static_cast<bool>(jwhole_key_filtering
);
132 options
.verify_compression
= static_cast<bool>(jverify_compression
);
133 options
.read_amp_bytes_per_bit
= static_cast<uint32_t>(jread_amp_bytes_per_bit
);
134 options
.format_version
= static_cast<uint32_t>(jformat_version
);
135 options
.enable_index_compression
= static_cast<bool>(jenable_index_compression
);
136 options
.block_align
= static_cast<bool>(jblock_align
);
138 return reinterpret_cast<jlong
>(rocksdb::NewBlockBasedTableFactory(options
));