Browse Source

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.
master
Andras Banki-Horvath 3 years ago
parent
commit
11a44a94b1
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8
  1. 12
      kvdb/etcd/readwrite_cursor.go

12
kvdb/etcd/readwrite_cursor.go

@ -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
}

Loading…
Cancel
Save