etcd: remove unnecessary iterator step from cursor Delete

The etcd cursor Delete stepped to the next item in the range before
Delete to not invalidate the iteation. This is unnecessary and not
compatible with bbolt, resulting in an extra fetch too.
This commit is contained in:
Andras Banki-Horvath 2021-06-25 17:16:30 +02:00
parent 8acbe177fa
commit 11a44a94b1
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8

@ -116,23 +116,11 @@ func (c *readWriteCursor) Seek(seek []byte) (key, value []byte) {
// invalidating the cursor. Returns ErrIncompatibleValue if attempted
// when the cursor points to a nested bucket.
func (c *readWriteCursor) Delete() error {
// Get the next key after the current one. We could do this
// after deletion too but it's one step more efficient here.
nextKey, err := c.bucket.tx.stm.Next(c.prefix, c.currKey)
if err != nil {
return err
}
if isBucketKey(c.currKey) {
c.bucket.DeleteNestedBucket(getKey(c.currKey))
} else {
c.bucket.Delete(getKey(c.currKey))
}
if nextKey != nil {
// Set current key to the next one.
c.currKey = nextKey.key
}
return nil
}