Skip to content

Commit

Permalink
storage: remove FirstRangeKeyAbove() and HasRangeKeyBetween()
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
erikgrinaker committed Jul 29, 2022
1 parent 8fba5b2 commit 2210add
Showing 1 changed file with 2 additions and 39 deletions.
41 changes: 2 additions & 39 deletions pkg/storage/mvcc_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,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
Expand Down Expand Up @@ -673,40 +673,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
}

0 comments on commit 2210add

Please sign in to comment.