sstable: Add has_partition_key method

This patch adds a helper function to sstable to check if it has a given
partition key.

Signed-off-by: Amnon Heiman <amnon@scylladb.com>
This commit is contained in:
Amnon Heiman
2018-05-13 17:18:18 +03:00
parent cd1f4ccb89
commit 1f28e97458
2 changed files with 19 additions and 0 deletions

View File

@@ -3914,6 +3914,17 @@ sstable::compute_shards_for_this_sstable() const {
return boost::copy_range<std::vector<unsigned>>(shards);
}
future<bool> sstable::has_partition_key(const utils::hashed_key& hk, const dht::decorated_key& dk) {
shared_sstable s = shared_from_this();
if (!filter_has_key(hk)) {
return make_ready_future<bool>(false);
}
seastar::shared_ptr<sstables::index_reader> lh_index = seastar::make_shared<sstables::index_reader>(s, default_priority_class());
return lh_index->advance_lower_and_check_if_present(dk).then([lh_index, s, this] (bool present) {
return make_ready_future<bool>(present);
});
}
utils::hashed_key sstable::make_hashed_key(const schema& s, const partition_key& key) {
return utils::make_hashed_key(static_cast<bytes_view>(key::from_partition_key(s, key)));
}

View File

@@ -604,6 +604,14 @@ public:
return _components->filter->is_present(bytes_view(key));
}
/*!
* \brief check if the sstable contains the given key.
* The method would search that the key is actually
* found in the sstable not just in the filter.
*
*/
future<bool> has_partition_key(const utils::hashed_key& hk, const dht::decorated_key& dk);
bool filter_has_key(utils::hashed_key key) {
return _components->filter->is_present(key);
}