]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/rocksjni/table.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / java / rocksjni / table.cc
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
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).
7c673cae
FG
5//
6// This file implements the "bridge" between Java and C++ for rocksdb::Options.
7
11fdf7f2 8#include "rocksdb/table.h"
7c673cae 9#include <jni.h>
7c673cae 10#include "include/org_rocksdb_BlockBasedTableConfig.h"
11fdf7f2 11#include "include/org_rocksdb_PlainTableConfig.h"
7c673cae
FG
12#include "rocksdb/cache.h"
13#include "rocksdb/filter_policy.h"
14
15/*
16 * Class: org_rocksdb_PlainTableConfig
17 * Method: newTableFactoryHandle
18 * Signature: (IIDIIBZZ)J
19 */
20jlong Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle(
11fdf7f2
TL
21 JNIEnv * /*env*/, jobject /*jobj*/, jint jkey_size,
22 jint jbloom_bits_per_key, jdouble jhash_table_ratio, jint jindex_sparseness,
23 jint jhuge_page_tlb_size, jbyte jencoding_type, jboolean jfull_scan_mode,
24 jboolean jstore_index_in_file) {
7c673cae
FG
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;
11fdf7f2 31 options.encoding_type = static_cast<rocksdb::EncodingType>(jencoding_type);
7c673cae
FG
32 options.full_scan_mode = jfull_scan_mode;
33 options.store_index_in_file = jstore_index_in_file;
34 return reinterpret_cast<jlong>(rocksdb::NewPlainTableFactory(options));
35}
36
37/*
38 * Class: org_rocksdb_BlockBasedTableConfig
39 * Method: newTableFactoryHandle
11fdf7f2 40 * Signature: (ZJIJJIIZIZZZJIBBI)J
7c673cae
FG
41 */
42jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
11fdf7f2
TL
43 JNIEnv * /*env*/, jobject /*jobj*/, jboolean no_block_cache,
44 jlong block_cache_size, jint block_cache_num_shardbits, jlong jblock_cache,
45 jlong block_size, jint block_size_deviation, jint block_restart_interval,
46 jboolean whole_key_filtering, jlong jfilter_policy,
47 jboolean cache_index_and_filter_blocks,
7c673cae
FG
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;
54
11fdf7f2
TL
55 if (!no_block_cache) {
56 if (jblock_cache > 0) {
57 std::shared_ptr<rocksdb::Cache> *pCache =
58 reinterpret_cast<std::shared_ptr<rocksdb::Cache> *>(jblock_cache);
59 options.block_cache = *pCache;
60 } else if (block_cache_size > 0) {
61 if (block_cache_num_shardbits > 0) {
62 options.block_cache =
63 rocksdb::NewLRUCache(block_cache_size, block_cache_num_shardbits);
64 } else {
65 options.block_cache = rocksdb::NewLRUCache(block_cache_size);
66 }
7c673cae
FG
67 }
68 }
69 options.block_size = block_size;
70 options.block_size_deviation = block_size_deviation;
71 options.block_restart_interval = block_restart_interval;
72 options.whole_key_filtering = whole_key_filtering;
11fdf7f2 73 if (jfilter_policy > 0) {
7c673cae
FG
74 std::shared_ptr<rocksdb::FilterPolicy> *pFilterPolicy =
75 reinterpret_cast<std::shared_ptr<rocksdb::FilterPolicy> *>(
11fdf7f2 76 jfilter_policy);
7c673cae
FG
77 options.filter_policy = *pFilterPolicy;
78 }
79 options.cache_index_and_filter_blocks = cache_index_and_filter_blocks;
80 options.pin_l0_filter_and_index_blocks_in_cache =
81 pin_l0_filter_and_index_blocks_in_cache;
82 options.hash_index_allow_collision = hash_index_allow_collision;
83 if (block_cache_compressed_size > 0) {
84 if (block_cache_compressd_num_shard_bits > 0) {
11fdf7f2
TL
85 options.block_cache = rocksdb::NewLRUCache(
86 block_cache_compressed_size, block_cache_compressd_num_shard_bits);
7c673cae
FG
87 } else {
88 options.block_cache = rocksdb::NewLRUCache(block_cache_compressed_size);
89 }
90 }
91 options.checksum = static_cast<rocksdb::ChecksumType>(jchecksum_type);
11fdf7f2
TL
92 options.index_type =
93 static_cast<rocksdb::BlockBasedTableOptions::IndexType>(jindex_type);
7c673cae
FG
94 options.format_version = jformat_version;
95
96 return reinterpret_cast<jlong>(rocksdb::NewBlockBasedTableFactory(options));
97}