Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support partion filters #37

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ REBAR ?= $(shell which rebar3 2>/dev/null)
TEST_DIR=$(CURDIR)/test


TEST_MODULES="db,db_range,iterators,batch,snapshot,column_family,batch,cache,blob_db,checkpoint,db_backup,cleanup,in_mem,merge,rate_limiter,sst_file_manager,transaction,transaction_log,ttl,write_buffer_manager,statistics,fifo_compaction"
TEST_MODULES="db,db_range,iterators,batch,snapshot,column_family,batch,cache,blob_db,checkpoint,db_backup,cleanup,in_mem,merge,rate_limiter,sst_file_manager,transaction,transaction_log,ttl,write_buffer_manager,statistics,fifo_compaction,bbt"

TEST_ALL_MODULES="${TEST_MODULES},compression"

Expand Down
2 changes: 2 additions & 0 deletions c_src/atoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ extern ERL_NIF_TERM ATOM_WRITE_BUFFER_SIZE;
extern ERL_NIF_TERM ATOM_MAX_WRITE_BUFFER_NUMBER;
extern ERL_NIF_TERM ATOM_MIN_WRITE_BUFFER_NUMBER_TO_MERGE;
extern ERL_NIF_TERM ATOM_COMPRESSION;
extern ERL_NIF_TERM ATOM_PARTITION_FILTERS;
extern ERL_NIF_TERM ATOM_PIN_L0_FILTER_AND_INDEX_BLOCKS_IN_CACHE;

// CFOptions blob
extern ERL_NIF_TERM ATOM_ENABLE_BLOB_FILES;
Expand Down
5 changes: 4 additions & 1 deletion c_src/erocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ ERL_NIF_TERM ATOM_BLOCK_CACHE_SIZE;
ERL_NIF_TERM ATOM_BLOOM_FILTER_POLICY;
ERL_NIF_TERM ATOM_FORMAT_VERSION;
ERL_NIF_TERM ATOM_CACHE_INDEX_AND_FILTER_BLOCKS;
ERL_NIF_TERM ATOM_PARTITION_FILTERS;
ERL_NIF_TERM ATOM_PIN_L0_FILTER_AND_INDEX_BLOCKS_IN_CACHE;

// Related to ReadTier
ERL_NIF_TERM ATOM_READ_TIER;
ERL_NIF_TERM ATOM_READ_ALL_TIER;
ERL_NIF_TERM ATOM_BLOCK_CACHE_TIER;
Expand Down Expand Up @@ -707,6 +708,8 @@ try
ATOM(erocksdb::ATOM_BLOOM_FILTER_POLICY, "bloom_filter_policy");
ATOM(erocksdb::ATOM_FORMAT_VERSION, "format_version");
ATOM(erocksdb::ATOM_CACHE_INDEX_AND_FILTER_BLOCKS, "cache_index_and_filter_blocks");
ATOM(erocksdb::ATOM_PARTITION_FILTERS, "partition_filters");
ATOM(erocksdb::ATOM_PIN_L0_FILTER_AND_INDEX_BLOCKS_IN_CACHE, "pin_l0_filter_and_index_blocks_in_cache");

// Related to ReadTier
ATOM(erocksdb::ATOM_READ_TIER, "read_tier");
Expand Down
11 changes: 11 additions & 0 deletions c_src/erocksdb_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ ERL_NIF_TERM parse_bbt_option(ErlNifEnv* env, ERL_NIF_TERM item, rocksdb::BlockB
else if (option[0] == erocksdb::ATOM_CACHE_INDEX_AND_FILTER_BLOCKS) {
opts.cache_index_and_filter_blocks = (option[1] == erocksdb::ATOM_TRUE);
}
else if (option[0] == erocksdb::ATOM_PIN_L0_FILTER_AND_INDEX_BLOCKS_IN_CACHE) {
opts.pin_l0_filter_and_index_blocks_in_cache = (option[1] == erocksdb::ATOM_TRUE);
}
else if (option[0] == erocksdb::ATOM_PARTITION_FILTERS) {
bool val = (option[1] == erocksdb::ATOM_TRUE);
opts.partition_filters = val;
if (val) {
opts.index_type = rocksdb::BlockBasedTableOptions::kTwoLevelIndexSearch;
}
}
}

return erocksdb::ATOM_OK;
Expand Down Expand Up @@ -700,6 +710,7 @@ ERL_NIF_TERM parse_cf_option(ErlNifEnv* env, ERL_NIF_TERM item, rocksdb::ColumnF
{
opts.optimize_filters_for_hits = (option[1] == erocksdb::ATOM_TRUE);
}

else if (option[0] == erocksdb::ATOM_MERGE_OPERATOR)
{
int a;
Expand Down
2 changes: 2 additions & 0 deletions src/rocksdb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@
{block_cache_size, pos_integer()} |
{bloom_filter_policy, BitsPerKey :: pos_integer()} |
{format_version, 0 | 1 | 2 | 3 | 4 | 5} |
{pin_l0_filter_and_index_blocks_in_cache, boolean()} |
{partition_filters, boolean()} |
{cache_index_and_filter_blocks, boolean()}].

-type compaction_options_fifo() :: [{allow_compaction, boolean()} |
Expand Down
108 changes: 108 additions & 0 deletions test/bbt.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
-module(bbt).
-include_lib("eunit/include/eunit.hrl").

-define(rm_rf(Dir), rocksdb_test_util:rm_rf(Dir)).

bbt_partion_filters_default_test() ->
DbName = "erocksdb.bbt.partition_filters.default",
?rm_rf(DbName),
{ok, Db} = rocksdb:open(
DbName,
[
{create_if_missing, true}
]
),
%% Check LOG file for check partition_filters set to 0
{ok, Log0} = file:read_file(lists:concat([DbName, "/LOG"])),
?assertMatch({match, _}, re:run(Log0, "partition_filters: 0")),

ok = rocksdb:close(Db),
?rm_rf(DbName).

bbt_partion_filters_false_test() ->
DbName = "erocksdb.bbt.partition_filters.false",
?rm_rf(DbName),
{ok, Db} = rocksdb:open(
DbName,
[
{create_if_missing, true}
]
),
%% Check LOG file for check partition_filters set to 0
{ok, Log0} = file:read_file(lists:concat([DbName, "/LOG"])),
?assertMatch({match, _}, re:run(Log0, "partition_filters: 0")),
?assertMatch({match, _}, re:run(Log0, "index_type: 0")),

ok = rocksdb:close(Db),
?rm_rf(DbName).


bbt_partion_filters_true_test() ->
DbName = "erocksdb.bbt.partition_filters.true",
?rm_rf(DbName),
{ok, Db} = rocksdb:open(
DbName,
[
{create_if_missing, true},
{block_based_table_options, [
{partition_filters, true}
]}
]
),
%% Check LOG file for check partition_filters set to 0
{ok, Log0} = file:read_file(lists:concat([DbName, "/LOG"])),
?assertMatch({match, _}, re:run(Log0, "partition_filters: 1")),
?assertMatch({match, _}, re:run(Log0, "index_type: 2")),
ok = rocksdb:close(Db),
?rm_rf(DbName).

bbt_pin_l0_filter_and_index_blocks_in_cache_default_test() ->
DbName = "erocksdb.bbt.pin_l0_filter_and_index_blocks_in_cache.default",
?rm_rf(DbName),
{ok, Db} = rocksdb:open(
DbName,
[
{create_if_missing, true}
]
),
%% Check LOG file for check pin_l0_filter_and_index_blocks_in_cache set to 0
{ok, Log0} = file:read_file(lists:concat([DbName, "/LOG"])),
?assertMatch({match, _}, re:run(Log0, "pin_l0_filter_and_index_blocks_in_cache: 0")),
ok = rocksdb:close(Db),
?rm_rf(DbName).

bbt_pin_l0_filter_and_index_blocks_in_cache_false_test() ->
DbName = "erocksdb.bbt.pin_l0_filter_and_index_blocks_in_cache.false",
?rm_rf(DbName),
{ok, Db} = rocksdb:open(
DbName,
[
{create_if_missing, true},
{block_based_table_options, [
{pin_l0_filter_and_index_blocks_in_cache, false}
]}
]
),
%% Check LOG file for check pin_l0_filter_and_index_blocks_in_cache set to 0
{ok, Log0} = file:read_file(lists:concat([DbName, "/LOG"])),
?assertMatch({match, _}, re:run(Log0, "pin_l0_filter_and_index_blocks_in_cache: 0")),
ok = rocksdb:close(Db),
?rm_rf(DbName).

bbt_pin_l0_filter_and_index_blocks_in_cache_true_test() ->
DbName = "erocksdb.bbt.pin_l0_filter_and_index_blocks_in_cache.true",
?rm_rf(DbName),
{ok, Db} = rocksdb:open(
DbName,
[
{create_if_missing, true},
{block_based_table_options, [
{pin_l0_filter_and_index_blocks_in_cache, true}
]}
]
),
%% Check LOG file for check pin_l0_filter_and_index_blocks_in_cache set to 1
{ok, Log0} = file:read_file(lists:concat([DbName, "/LOG"])),
?assertMatch({match, _}, re:run(Log0, "pin_l0_filter_and_index_blocks_in_cache: 1")),
ok = rocksdb:close(Db),
?rm_rf(DbName).