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

Allow changing multiple key values atomically #26

Open
mthenw opened this issue Sep 1, 2017 · 4 comments
Open

Allow changing multiple key values atomically #26

mthenw opened this issue Sep 1, 2017 · 4 comments

Comments

@mthenw
Copy link

mthenw commented Sep 1, 2017

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?

@abronan
Copy link
Owner

abronan commented Sep 1, 2017

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.

@mthenw
Copy link
Author

mthenw commented Sep 1, 2017

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

@mthenw
Copy link
Author

mthenw commented Sep 25, 2017

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

@abronan
Copy link
Owner

abronan commented Oct 13, 2017

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants