diff --git a/pkg/storage/mvcc_key.go b/pkg/storage/mvcc_key.go index 54f21a63c35b..587c9ad2aa6b 100644 --- a/pkg/storage/mvcc_key.go +++ b/pkg/storage/mvcc_key.go @@ -501,8 +501,8 @@ func (s MVCCRangeKeyStack) AsRangeKeyValues() []MVCCRangeKeyValue { } // CanMergeRight returns true if the current stack will merge with the given -// right-hand stack. The key bounds must touch exactly, i.e. lhs.EndKey must -// equal rhs.Key. +// right-hand stack. The key bounds must touch exactly, i.e. the left-hand +// EndKey must equal the right-hand Key. func (s MVCCRangeKeyStack) CanMergeRight(r MVCCRangeKeyStack) bool { if s.IsEmpty() || s.Len() != r.Len() || !s.Bounds.EndKey.Equal(r.Bounds.Key) { return false @@ -669,40 +669,3 @@ func (v MVCCRangeKeyVersion) Clone() MVCCRangeKeyVersion { func (v MVCCRangeKeyVersion) Equal(o MVCCRangeKeyVersion) bool { return v.Timestamp.Equal(o.Timestamp) && bytes.Equal(v.Value, o.Value) } - -// FirstRangeKeyAbove does a binary search for the first range key at or above -// the given timestamp. It assumes the range keys are ordered in descending -// timestamp order, as returned by SimpleMVCCIterator.RangeKeys(). Returns false -// if no matching range key was found. -// -// TODO(erikgrinaker): Consider using a new type for []MVCCRangeKeyValue as -// returned by SimpleMVCCIterator.RangeKeys(), and add this as a method. -func FirstRangeKeyAbove(rangeKeys []MVCCRangeKeyValue, ts hlc.Timestamp) (MVCCRangeKeyValue, bool) { - // This is kind of odd due to sort.Search() semantics: we do a binary search - // for the first range tombstone that's below the timestamp, then return the - // previous range tombstone if any. - if i := sort.Search(len(rangeKeys), func(i int) bool { - return rangeKeys[i].RangeKey.Timestamp.Less(ts) - }); i > 0 { - return rangeKeys[i-1], true - } - return MVCCRangeKeyValue{}, false -} - -// HasRangeKeyBetween checks whether an MVCC range key exists between the two -// given timestamps (in order). It assumes the range keys are ordered in -// descending timestamp order, as returned by SimpleMVCCIterator.RangeKeys(). -func HasRangeKeyBetween(rangeKeys []MVCCRangeKeyValue, upper, lower hlc.Timestamp) bool { - if len(rangeKeys) == 0 { - return false - } - if util.RaceEnabled && upper.Less(lower) { - panic(errors.AssertionFailedf("HasRangeKeyBetween given upper %s <= lower %s", upper, lower)) - } - if rkv, ok := FirstRangeKeyAbove(rangeKeys, lower); ok { - // Consider equal timestamps to be "between". This shouldn't really happen, - // since MVCC enforces point and range keys can't have the same timestamp. - return rkv.RangeKey.Timestamp.LessEq(upper) - } - return false -}