From 0e487b34993e8bc8a5358468ef15b01f7cc30cbb Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Mon, 19 Dec 2016 13:39:24 +0100 Subject: [PATCH] db: Compute key hash once in partition_presence_checker I measured reduction of cache update time by 20% for 6 sstables and by 40% for 16. Refs #1943. --- database.cc | 3 ++- sstables/sstables.cc | 4 ++++ sstables/sstables.hh | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/database.cc b/database.cc index 1c2e488d00..a84b4d85c3 100644 --- a/database.cc +++ b/database.cc @@ -146,8 +146,9 @@ column_family::make_partition_presence_checker(lw_shared_ptrfilter_has_key(*_schema, key.key())) { + if (s->filter_has_key(hk)) { return partition_presence_checker_result::maybe_exists; } } diff --git a/sstables/sstables.cc b/sstables/sstables.cc index b46c9ccb48..0760df9df4 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -2627,6 +2627,10 @@ sstable::get_shards_for_this_sstable() const { return boost::copy_range>(shards); } +utils::hashed_key sstable::make_hashed_key(const schema& s, const partition_key& key) { + return utils::make_hashed_key(static_cast(key::from_partition_key(s, key))); +} + std::ostream& operator<<(std::ostream& os, const sstable_to_delete& std) { return os << std.name << "(" << (std.shared ? "shared" : "unshared") << ")"; diff --git a/sstables/sstables.hh b/sstables/sstables.hh index 8fdcd3c9e0..749476280d 100644 --- a/sstables/sstables.hh +++ b/sstables/sstables.hh @@ -607,10 +607,16 @@ public: return _filter->is_present(bytes_view(key)); } + bool filter_has_key(utils::hashed_key key) { + return _filter->is_present(key); + } + bool filter_has_key(const schema& s, partition_key_view key) { return filter_has_key(key::from_partition_key(s, key)); } + static utils::hashed_key make_hashed_key(const schema& s, const partition_key& key); + uint64_t filter_get_false_positive() { return _filter_tracker.false_positive; }