etcd-io / etcd

Distributed reliable key-value store for the most critical data of a distributed system
https://etcd.io
Apache License 2.0
46.77k stars 9.64k forks source link

Allow revision filters on delete ops #18187

Open Alfus opened 1 week ago

Alfus commented 1 week ago

What would you like to be added?

I would like to be able to use clientv3.WithMaxModRev with clientv3.OpDelete.

Why is this needed?

I'd like to make deletes truly idempotent, by only deleting the value if it was the one read. For example, if a range of entries are read at revision R, it would be nice to only delete an entry if it's revision has not changed since R. I could use a transaction for this, but I am already using a txn to avoid errors.ErrTooManyRequests (see https://github.com/etcd-io/etcd/issues/18175). Consider the following sequence of events: 1) K1..KN are written at R1 2) K1..KN are read at R2 3) K1..KN are deleted in a single txn (to avoid https://github.com/etcd-io/etcd/issues/18175) 3) KX is written at R3, where 1 <= X <= N 4) The operation at (2) is retried, deleting KX@R3 by mistake!

More generally speaking it would be nice to support the rev filters on delete ops, so a key and revision combo can be specified for the delete.

I also have the use case where I would like to delete all the values before a specific revision for a given prefix. To do this right now, I have to list the keys with the revision filters, then delete each key. It would be much nicer to be able to just send a delete request for the prefix with the revision filters.

Thanks!