2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-04-22 00:40:46 +02:00
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ for rocksdb::Options.
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
#include "rocksdb/table.h"
|
2014-04-22 00:40:46 +02:00
|
|
|
#include <jni.h>
|
2014-08-25 23:22:55 +02:00
|
|
|
#include "include/org_rocksdb_BlockBasedTableConfig.h"
|
2018-04-13 02:55:14 +02:00
|
|
|
#include "include/org_rocksdb_PlainTableConfig.h"
|
2014-08-25 23:22:55 +02:00
|
|
|
#include "rocksdb/cache.h"
|
|
|
|
#include "rocksdb/filter_policy.h"
|
2014-04-22 00:40:46 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_PlainTableConfig
|
|
|
|
* Method: newTableFactoryHandle
|
2014-10-20 22:42:32 +02:00
|
|
|
* Signature: (IIDIIBZZ)J
|
2014-04-22 00:40:46 +02:00
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv * /*env*/, jobject /*jobj*/, jint jkey_size,
|
|
|
|
jint jbloom_bits_per_key, jdouble jhash_table_ratio, jint jindex_sparseness,
|
|
|
|
jint jhuge_page_tlb_size, jbyte jencoding_type, jboolean jfull_scan_mode,
|
|
|
|
jboolean jstore_index_in_file) {
|
2014-07-21 18:19:28 +02:00
|
|
|
rocksdb::PlainTableOptions options = rocksdb::PlainTableOptions();
|
|
|
|
options.user_key_len = jkey_size;
|
|
|
|
options.bloom_bits_per_key = jbloom_bits_per_key;
|
|
|
|
options.hash_table_ratio = jhash_table_ratio;
|
|
|
|
options.index_sparseness = jindex_sparseness;
|
2014-10-20 22:42:32 +02:00
|
|
|
options.huge_page_tlb_size = jhuge_page_tlb_size;
|
2018-04-13 02:55:14 +02:00
|
|
|
options.encoding_type = static_cast<rocksdb::EncodingType>(jencoding_type);
|
2014-10-20 22:42:32 +02:00
|
|
|
options.full_scan_mode = jfull_scan_mode;
|
|
|
|
options.store_index_in_file = jstore_index_in_file;
|
2014-07-21 18:19:28 +02:00
|
|
|
return reinterpret_cast<jlong>(rocksdb::NewPlainTableFactory(options));
|
2014-04-22 00:40:46 +02:00
|
|
|
}
|
2014-08-25 23:22:55 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BlockBasedTableConfig
|
|
|
|
* Method: newTableFactoryHandle
|
2018-10-30 21:08:26 +01:00
|
|
|
* Signature: (ZJIJJIIZJZZZZJZZJIBBI)J
|
2014-08-25 23:22:55 +02:00
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv * /*env*/, jobject /*jobj*/, jboolean no_block_cache,
|
|
|
|
jlong block_cache_size, jint block_cache_num_shardbits, jlong jblock_cache,
|
|
|
|
jlong block_size, jint block_size_deviation, jint block_restart_interval,
|
2018-03-22 02:31:21 +01:00
|
|
|
jboolean whole_key_filtering, jlong jfilter_policy,
|
|
|
|
jboolean cache_index_and_filter_blocks,
|
2018-10-30 21:08:26 +01:00
|
|
|
jboolean cache_index_and_filter_blocks_with_high_priority,
|
Adding pin_l0_filter_and_index_blocks_in_cache feature and related fixes.
Summary:
When a block based table file is opened, if prefetch_index_and_filter is true, it will prefetch the index and filter blocks, putting them into the block cache.
What this feature adds: when a L0 block based table file is opened, if pin_l0_filter_and_index_blocks_in_cache is true in the options (and prefetch_index_and_filter is true), then the filter and index blocks aren't released back to the block cache at the end of BlockBasedTableReader::Open(). Instead the table reader takes ownership of them, hence pinning them, ie. the LRU cache will never push them out. Meanwhile in the table reader, further accesses will not hit the block cache, thus avoiding lock contention.
Test Plan:
'export TEST_TMPDIR=/dev/shm/ && DISABLE_JEMALLOC=1 OPT=-g make all valgrind_check -j32' is OK.
I didn't run the Java tests, I don't have Java set up on my devserver.
Reviewers: sdong
Reviewed By: sdong
Subscribers: andrewkr, dhruba
Differential Revision: https://reviews.facebook.net/D56133
2016-04-01 19:42:39 +02:00
|
|
|
jboolean pin_l0_filter_and_index_blocks_in_cache,
|
2018-10-30 21:08:26 +01:00
|
|
|
jboolean partition_filters, jlong metadata_block_size,
|
|
|
|
jboolean pin_top_level_index_and_filter,
|
2014-09-24 20:43:35 +02:00
|
|
|
jboolean hash_index_allow_collision, jlong block_cache_compressed_size,
|
2014-10-20 22:42:32 +02:00
|
|
|
jint block_cache_compressd_num_shard_bits, jbyte jchecksum_type,
|
2015-01-16 23:00:30 +01:00
|
|
|
jbyte jindex_type, jint jformat_version) {
|
2014-08-25 23:22:55 +02:00
|
|
|
rocksdb::BlockBasedTableOptions options;
|
|
|
|
options.no_block_cache = no_block_cache;
|
|
|
|
|
2018-03-22 02:31:21 +01:00
|
|
|
if (!no_block_cache) {
|
|
|
|
if (jblock_cache > 0) {
|
|
|
|
std::shared_ptr<rocksdb::Cache> *pCache =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Cache> *>(jblock_cache);
|
|
|
|
options.block_cache = *pCache;
|
|
|
|
} else if (block_cache_size > 0) {
|
|
|
|
if (block_cache_num_shardbits > 0) {
|
|
|
|
options.block_cache =
|
|
|
|
rocksdb::NewLRUCache(block_cache_size, block_cache_num_shardbits);
|
|
|
|
} else {
|
|
|
|
options.block_cache = rocksdb::NewLRUCache(block_cache_size);
|
|
|
|
}
|
2014-08-25 23:22:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
options.block_size = block_size;
|
|
|
|
options.block_size_deviation = block_size_deviation;
|
|
|
|
options.block_restart_interval = block_restart_interval;
|
|
|
|
options.whole_key_filtering = whole_key_filtering;
|
2018-03-22 02:31:21 +01:00
|
|
|
if (jfilter_policy > 0) {
|
2014-10-14 18:38:50 +02:00
|
|
|
std::shared_ptr<rocksdb::FilterPolicy> *pFilterPolicy =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::FilterPolicy> *>(
|
2018-03-22 02:31:21 +01:00
|
|
|
jfilter_policy);
|
2014-10-14 18:38:50 +02:00
|
|
|
options.filter_policy = *pFilterPolicy;
|
2014-08-25 23:22:55 +02:00
|
|
|
}
|
2014-09-24 20:43:35 +02:00
|
|
|
options.cache_index_and_filter_blocks = cache_index_and_filter_blocks;
|
2018-10-30 21:08:26 +01:00
|
|
|
options.cache_index_and_filter_blocks_with_high_priority =
|
|
|
|
cache_index_and_filter_blocks_with_high_priority;
|
Adding pin_l0_filter_and_index_blocks_in_cache feature and related fixes.
Summary:
When a block based table file is opened, if prefetch_index_and_filter is true, it will prefetch the index and filter blocks, putting them into the block cache.
What this feature adds: when a L0 block based table file is opened, if pin_l0_filter_and_index_blocks_in_cache is true in the options (and prefetch_index_and_filter is true), then the filter and index blocks aren't released back to the block cache at the end of BlockBasedTableReader::Open(). Instead the table reader takes ownership of them, hence pinning them, ie. the LRU cache will never push them out. Meanwhile in the table reader, further accesses will not hit the block cache, thus avoiding lock contention.
Test Plan:
'export TEST_TMPDIR=/dev/shm/ && DISABLE_JEMALLOC=1 OPT=-g make all valgrind_check -j32' is OK.
I didn't run the Java tests, I don't have Java set up on my devserver.
Reviewers: sdong
Reviewed By: sdong
Subscribers: andrewkr, dhruba
Differential Revision: https://reviews.facebook.net/D56133
2016-04-01 19:42:39 +02:00
|
|
|
options.pin_l0_filter_and_index_blocks_in_cache =
|
|
|
|
pin_l0_filter_and_index_blocks_in_cache;
|
2018-10-30 21:08:26 +01:00
|
|
|
options.partition_filters = partition_filters;
|
|
|
|
options.metadata_block_size = metadata_block_size;
|
|
|
|
options.pin_top_level_index_and_filter = pin_top_level_index_and_filter;
|
2014-09-24 20:43:35 +02:00
|
|
|
options.hash_index_allow_collision = hash_index_allow_collision;
|
|
|
|
if (block_cache_compressed_size > 0) {
|
|
|
|
if (block_cache_compressd_num_shard_bits > 0) {
|
2018-04-13 02:55:14 +02:00
|
|
|
options.block_cache = rocksdb::NewLRUCache(
|
|
|
|
block_cache_compressed_size, block_cache_compressd_num_shard_bits);
|
2014-09-24 20:43:35 +02:00
|
|
|
} else {
|
|
|
|
options.block_cache = rocksdb::NewLRUCache(block_cache_compressed_size);
|
|
|
|
}
|
|
|
|
}
|
2014-10-20 22:42:32 +02:00
|
|
|
options.checksum = static_cast<rocksdb::ChecksumType>(jchecksum_type);
|
2018-04-13 02:55:14 +02:00
|
|
|
options.index_type =
|
|
|
|
static_cast<rocksdb::BlockBasedTableOptions::IndexType>(jindex_type);
|
2015-01-16 23:00:30 +01:00
|
|
|
options.format_version = jformat_version;
|
2014-10-02 13:21:20 +02:00
|
|
|
|
2014-08-25 23:22:55 +02:00
|
|
|
return reinterpret_cast<jlong>(rocksdb::NewBlockBasedTableFactory(options));
|
|
|
|
}
|