Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store/mockstore: Add raw delete range to mock store #6156

Closed
18 changes: 18 additions & 0 deletions store/mockstore/mocktikv/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ type RawKV interface {
RawScan(startKey, endKey []byte, limit int) []Pair
RawPut(key, value []byte)
RawDelete(key []byte)
RawDeleteRange(startKey, endKey []byte)
}

// MVCCDebugger is for debugging.
Expand Down Expand Up @@ -780,6 +781,23 @@ func (s *MvccStore) RawDelete(key []byte) {
s.rawkv.Delete(newRawEntry(key))
}

// RawDeleteRange deletes all key-value pairs in a given range
func (s *MvccStore) RawDeleteRange(startKey, endKey []byte) {
s.Lock()
defer s.Unlock()

var entriesToDelete []*rawEntry
iterator := func(item btree.Item) bool {
entriesToDelete = append(entriesToDelete, item.(*rawEntry))
return true
}
s.rawkv.AscendRange(newRawEntry(startKey), newRawEntry(endKey), iterator)

for _, entry := range entriesToDelete {
s.rawkv.Delete(entry)
}
}

// RawScan reads up to a limited number of rawkv Pairs.
func (s *MvccStore) RawScan(startKey, endKey []byte, limit int) []Pair {
s.RLock()
Expand Down