Files
scylla/utils/i_filter.cc
Avi Kivity aa1270a00c treewide: change assert() to SCYLLA_ASSERT()
assert() is traditionally disabled in release builds, but not in
scylladb. This hasn't caused problems so far, but the latest abseil
release includes a commit [1] that causes a 1000 insn/op regression when
NDEBUG is not defined.

Clearly, we must move towards a build system where NDEBUG is defined in
release builds. But we can't just define it blindly without vetting
all the assert() calls, as some were written with the expectation that
they are enabled in release mode.

To solve the conundrum, change all assert() calls to a new SCYLLA_ASSERT()
macro in utils/assert.hh. This macro is always defined and is not conditional
on NDEBUG, so we can later (after vetting Seastar) enable NDEBUG in release
mode.

[1] 66ef711d68

Closes scylladb/scylladb#20006
2024-08-05 08:23:35 +03:00

54 lines
1.6 KiB
C++

/*
* Copyright (C) 2015-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "log.hh"
#include "bloom_filter.hh"
#include "bloom_calculations.hh"
#include "utils/assert.hh"
#include "utils/murmur_hash.hh"
#include <seastar/core/thread.hh>
namespace utils {
static logging::logger filterlog("bloom_filter");
filter_ptr i_filter::get_filter(int64_t num_elements, double max_false_pos_probability, filter_format fformat) {
SCYLLA_ASSERT(seastar::thread::running_in_thread());
if (max_false_pos_probability > 1.0) {
throw std::invalid_argument(format("Invalid probability {:f}: must be lower than 1.0", max_false_pos_probability));
}
if (max_false_pos_probability == 1.0) {
return std::make_unique<filter::always_present_filter>();
}
int buckets_per_element = bloom_calculations::max_buckets_per_element(num_elements);
auto spec = bloom_calculations::compute_bloom_spec(buckets_per_element, max_false_pos_probability);
return filter::create_filter(spec.K, num_elements, spec.buckets_per_element, fformat);
}
size_t i_filter::get_filter_size(int64_t num_elements, double max_false_pos_probability) {
if (max_false_pos_probability >= 1.0) {
return 0;
}
int buckets_per_element = bloom_calculations::max_buckets_per_element(num_elements);
auto spec = bloom_calculations::compute_bloom_spec(buckets_per_element, max_false_pos_probability);
return filter::get_bitset_size(num_elements, spec.buckets_per_element) / 8;
}
hashed_key make_hashed_key(bytes_view b) {
std::array<uint64_t, 2> h;
utils::murmur_hash::hash3_x64_128(b, 0, h);
return { h };
}
}