libkv icon indicating copy to clipboard operation
libkv copied to clipboard

Allow changing multiple key values atomically

Open mthenw opened this issue 8 years ago • 4 comments

Have you thought about having that in libkv? Simple transactions are possible with Consul, Zookeeper, etcd (v3) and Redis. Looks like pretty common use case?

mthenw avatar Sep 01 '17 13:09 mthenw

Yes, thought about this and ACLs, for now I'll focus on improving the tests and make the foundations more solid. Then if we can add more features such as transactions that would be nice indeed.

Let me know if you are interested in getting started with the implementation. It doesn't have to be for every store at first, we can throw an store.ErrCallNotSupported for other stores.

abronan avatar Sep 01 '17 13:09 abronan

Yes, I am. Would be great if you could propose some API for that. I would probably start with etcd.

mthenw avatar Sep 01 '17 13:09 mthenw

@abronan do you have any idea how the API could look like?

mthenw avatar Sep 25 '17 09:09 mthenw

@mthenw Sorry for the very long wait, was pretty busy with interviews recently. I think you could take a look at how etcd v3 API does transactions (I really like their API), specifically with Put/AtomicPut and how we use the client.Txn method. I think it gives a nice idea of what this might look like on our side.

For example:

ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second)
txn := client.Txn(ctx)
txn.Op(libkv.OpPut("firstKey", []byte("value")))
txn.Op(libkv.OpPut("secondKey", []byte("value")))
result, err := txn.Commit()
cancel()

We would get Op*** methods for Get/Put/AtomicPut, etc.

Will have to think about the AtomicPut case which might be a little trickier to implement (I don't think the solution of etcd v3 with Compare is very intuitive, although I'm not sure yet if there is a better way).

abronan avatar Oct 13 '17 17:10 abronan