From 30285ee31c31e873136eadaf037931200ab1e3bc Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Mon, 20 Nov 2017 13:16:04 -0800 Subject: [PATCH] Fix calculating filter partition target size Summary: block_size_deviation is in percentage while the partition size is in bytes. The current code fails to take that into account resulting into very large target size for filter partitions. Closes https://github.com/facebook/rocksdb/pull/3187 Differential Revision: D6376069 Pulled By: maysamyabandeh fbshipit-source-id: 276546fc68f50e0da32c462abb46f6cf676db9b2 --- table/block_based_table_builder.cc | 4 ++-- table/partitioned_filter_block_test.cc | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/table/block_based_table_builder.cc b/table/block_based_table_builder.cc index 9185c607c..81cc2d07d 100644 --- a/table/block_based_table_builder.cc +++ b/table/block_based_table_builder.cc @@ -78,8 +78,8 @@ FilterBlockBuilder* CreateFilterBlockBuilder( // as partition size. assert(table_opt.block_size_deviation <= 100); auto partition_size = static_cast( - table_opt.metadata_block_size * - (100 - table_opt.block_size_deviation)); + ((table_opt.metadata_block_size * + (100 - table_opt.block_size_deviation)) + 99) / 100); partition_size = std::max(partition_size, static_cast(1)); return new PartitionedFilterBlockBuilder( opt.prefix_extractor, table_opt.whole_key_filtering, diff --git a/table/partitioned_filter_block_test.cc b/table/partitioned_filter_block_test.cc index 1bc529ed9..0a8943feb 100644 --- a/table/partitioned_filter_block_test.cc +++ b/table/partitioned_filter_block_test.cc @@ -75,7 +75,8 @@ class PartitionedFilterBlockTest : public testing::Test { auto partition_size = filter_bits_reader->CalculateSpace(num_keys, &dont_care1, &dont_care2); delete filter_bits_reader; - return partition_size + table_options_.block_size_deviation; + return partition_size + + partition_size * table_options_.block_size_deviation / 100; } int last_offset = 10; @@ -94,8 +95,10 @@ class PartitionedFilterBlockTest : public testing::Test { PartitionedIndexBuilder* const p_index_builder) { assert(table_options_.block_size_deviation <= 100); auto partition_size = static_cast( - table_options_.metadata_block_size * - ( 100 - table_options_.block_size_deviation)); + ((table_options_.metadata_block_size * + (100 - table_options_.block_size_deviation)) + + 99) / + 100); partition_size = std::max(partition_size, static_cast(1)); return new PartitionedFilterBlockBuilder( nullptr, table_options_.whole_key_filtering,