Skip to content

Commit

Permalink
Paired-Bloom-Filter: Balancing rounding to batches between the bottom…
Browse files Browse the repository at this point in the history
…most level and rest of the levels (#369)
  • Loading branch information
noamhaham authored and udi-speedb committed Nov 13, 2023
1 parent 6f5ceff commit 08c6c46
Showing 3 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion plugin/speedb/paired_filter/speedb_paired_bloom.cc
Original file line number Diff line number Diff line change
@@ -75,7 +75,8 @@ FilterBitsBuilder* SpdbPairedBloomFilterPolicy::GetBuilderWithContext(
millibits_per_key_, offm ? &aggregate_rounding_balance_ : nullptr,
cache_res_mgr, context.table_options.detect_filter_construct_corruption,
std::bind(&SpdbPairedBloomFilterPolicy::GetFilterBitsReader, this,
std::placeholders::_1));
std::placeholders::_1),
context.is_bottommost);
}

FilterBitsReader* SpdbPairedBloomFilterPolicy::GetFilterBitsReader(
26 changes: 20 additions & 6 deletions plugin/speedb/paired_filter/speedb_paired_bloom_internal.cc
Original file line number Diff line number Diff line change
@@ -433,11 +433,12 @@ SpdbPairedBloomBitsBuilder::SpdbPairedBloomBitsBuilder(
std::atomic<int64_t>* aggregate_rounding_balance,
const std::shared_ptr<CacheReservationManager>& cache_res_mgr,
bool detect_filter_construct_corruption,
const FilterBitsReaderCreateFunc& reader_create_func)
const FilterBitsReaderCreateFunc& reader_create_func, bool is_bottomost)
: XXPH3FilterBitsBuilder(aggregate_rounding_balance,
std::move(cache_res_mgr),
detect_filter_construct_corruption),
millibits_per_key_(millibits_per_key),
is_bottomost_(is_bottomost),
reader_create_func_(reader_create_func) {
assert(millibits_per_key >= speedb_filter::kMinMillibitsPerKey);
}
@@ -452,7 +453,13 @@ void SpdbPairedBloomBitsBuilder::InitVars(uint64_t len_no_metadata) {
assert(num_blocks_ % 2 == 0);
assert(num_blocks_ % speedb_filter::kPairedBloomBatchSizeInBlocks == 0);

num_batches_ = num_blocks_ / speedb_filter::kPairedBloomBatchSizeInBlocks;
if (is_bottomost_) {
num_batches_ = (num_blocks_ / speedb_filter::kPairedBloomBatchSizeInBlocks);
} else {
num_batches_ = static_cast<size_t>(
std::ceil(static_cast<double>(num_blocks_) /
speedb_filter::kPairedBloomBatchSizeInBlocks));
}
// There must be at least 1 batch
assert(num_batches_ > 0U);

@@ -567,15 +574,22 @@ double SpdbPairedBloomBitsBuilder::EstimatedFpRate(
size_t SpdbPairedBloomBitsBuilder::RoundDownUsableSpace(size_t available_size) {
size_t rv = available_size - speedb_filter::FilterMetadata::kMetadataLen;

// round down to multiple of a Batch for bottomost level, and round up for
// other levels
if (is_bottomost_) {
rv = std::max<size_t>((rv / kBatchSizeInBytes) * kBatchSizeInBytes,
kBatchSizeInBytes);
} else {
rv = static_cast<size_t>(
std::ceil(static_cast<double>(rv) / kBatchSizeInBytes) *
kBatchSizeInBytes);
}

if (rv >= kMaxSupportedSizeNoMetadata) {
// Max supported for this data structure implementation
rv = kMaxSupportedSizeNoMetadata;
}

// round down to multiple of a Batch
rv = std::max<size_t>((rv / kBatchSizeInBytes) * kBatchSizeInBytes,
kBatchSizeInBytes);

return rv + speedb_filter::FilterMetadata::kMetadataLen;
}

3 changes: 2 additions & 1 deletion plugin/speedb/paired_filter/speedb_paired_bloom_internal.h
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ class SpdbPairedBloomBitsBuilder : public XXPH3FilterBitsBuilder {
std::atomic<int64_t>* aggregate_rounding_balance,
const std::shared_ptr<CacheReservationManager>& cache_res_mgr,
bool detect_filter_construct_corruption,
const FilterBitsReaderCreateFunc& reader_create_func);
const FilterBitsReaderCreateFunc& reader_create_func, bool is_bottomost);

~SpdbPairedBloomBitsBuilder() override {}

@@ -163,6 +163,7 @@ class SpdbPairedBloomBitsBuilder : public XXPH3FilterBitsBuilder {
// Target allocation per added key, in thousandths of a bit.
int millibits_per_key_;

bool is_bottomost_;
size_t num_blocks_ = 0U;
size_t num_batches_ = 0U;
size_t num_probes_ = 0U;

0 comments on commit 08c6c46

Please sign in to comment.