From 2fd7caafa08a83adab3de53943ebd7cf0e453554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dziepak?= Date: Fri, 18 Dec 2015 15:19:32 +0100 Subject: [PATCH] sstables: respect range inclusiveness in key_reader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When choosing a relevant range of buckets it wasn't taken into account whether the range bounds are inclusive or not. That may have resulted in more buckets being read than necessary which was a condition not expected by the code responsible from looking for a relevant keys inside the buckets. Signed-off-by: Paweł Dziepak --- sstables/partition.cc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/sstables/partition.cc b/sstables/partition.cc index d669f5be7c..ecd6f2d816 100644 --- a/sstables/partition.cc +++ b/sstables/partition.cc @@ -650,11 +650,19 @@ public: : _s(s), _sst(std::move(sst)), _range(range) { auto& summary = _sst->_summary; + using summary_entries_type = std::decay_t; _begin_bucket_id = 0; if (range.start()) { - auto pos = std::lower_bound(summary.entries.begin(), summary.entries.end(), - range.start()->value(), index_comparator(*s)); + summary_entries_type::iterator pos; + if (range.start()->is_inclusive()) { + pos = std::lower_bound(summary.entries.begin(), summary.entries.end(), + range.start()->value(), index_comparator(*s)); + + } else { + pos = std::upper_bound(summary.entries.begin(), summary.entries.end(), + range.start()->value(), index_comparator(*s)); + } _begin_bucket_id = std::distance(summary.entries.begin(), pos); if (_begin_bucket_id) { _begin_bucket_id--; @@ -664,8 +672,14 @@ public: _end_bucket_id = summary.header.size; if (range.end()) { - auto pos = std::upper_bound(summary.entries.begin(), summary.entries.end(), - range.end()->value(), index_comparator(*s)); + summary_entries_type::iterator pos; + if (range.end()->is_inclusive()) { + pos = std::upper_bound(summary.entries.begin(), summary.entries.end(), + range.end()->value(), index_comparator(*s)); + } else { + pos = std::lower_bound(summary.entries.begin(), summary.entries.end(), + range.end()->value(), index_comparator(*s)); + } _end_bucket_id = std::distance(summary.entries.begin(), pos); if (_end_bucket_id) { _end_bucket_id--;