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

[Feature Request] Pass-Through Transaction Read/WriteSet #30

Open
rrichardson opened this issue Feb 14, 2022 · 0 comments
Open

[Feature Request] Pass-Through Transaction Read/WriteSet #30

rrichardson opened this issue Feb 14, 2022 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rrichardson
Copy link

One feature of the Typescript etcd3 client is a Transaction class that offers the put*/get* API.

It does this by capturing every object (or at least its revision) in Read and Write sets, and passes them to conditional checks in the transaction execution itself.

This makes for a much more natural DB interaction experience.

e.g. in Rust it'd be something like:

let txn = client.txn()?; 

let foo = txn.get("bar/foo").await?; 
let baz = txn.get("bar/baz").await?;

let froboz = MyThing::merge(&[&foo, &baz]);
txn.put("bar/froboz", froboz.serialize()?)?;
txn.commit(); 

As mentioned above, the typescript implementation does this by capturing every object and the database's mod_revision
It then finds the lowest mod_revision and uses the Compare::mod_revision to ensure that the objects being written haven't been updated. This can be overly restrictive, but since it doesn't know the actual details of the updates, I think it's the best it can do.

We've been using this approach in hundreds of different service handlers across dozens of services and it has been working quite well.

We've not yet had to bypass this mechanism to create a Transaction object with the traditional fetch/compare/set operation.

Here are some pointers to the actual implementation:

WriteSet: https://github.com/microsoft/etcd3/blob/master/src/stm.ts#L100
ReadSet: https://github.com/microsoft/etcd3/blob/master/src/stm.ts#L100-L148
Txn Execution: https://github.com/microsoft/etcd3/blob/master/src/stm.ts#L497-L527

@davidli2010 davidli2010 added enhancement New feature or request help wanted Extra attention is needed labels Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants