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

Optimistic locking support #583

Open
hgrubst opened this issue Oct 23, 2016 · 3 comments
Open

Optimistic locking support #583

hgrubst opened this issue Oct 23, 2016 · 3 comments
Labels

Comments

@hgrubst
Copy link

hgrubst commented Oct 23, 2016

Question

Hi, after looking through the docs and code, I believe thinky does not support optimistic locking out of the box but I though I would still ask the question just in case I missed something.
The feature I am looking for is something as described here : rethinkdb/rethinkdb#5286 or even in the rethinkdb official docs here : https://rethinkdb.com/docs/consistency/ (under Linearizability and atomicity guarantees)

Basically the ability to add a field that would be checked prior to updating a document to be sure no other update has been performed between the moment we retrieved the document and wish to save it again.

The technique described here rethinkdb/rethinkdb#5286 would work fine. The only difference is that thinky does a replace when calling save (as opposed to update in the example) although it still works as expected.

What would be nice would be the ability to define the field that should be checked in the schema (if any). In the java world and hibernate, they use an annotation @Version to define such fields and the frameworks takes care of checking and incrementing that field automatically.

@neumino
Copy link
Owner

neumino commented Oct 24, 2016

You can do the same thing as in rethinkdb/rethinkdb#5286 with replace. Thinky doesn't provide a special API to do that though.

@cur3n4
Copy link
Collaborator

cur3n4 commented Nov 2, 2016

I have created a very crude implementation in #588. Besides the lack of tests and so on, this could be extended by providing a type (date, string, number) for the optimistic locking field. @neumino Would you accept a proper PR to include something like this into the library?

@hgrubst
Copy link
Author

hgrubst commented Nov 2, 2016

Sorry for the late reply, @neumino I agree you can use that approach, which works very well. The point of using a framework like thinky is to give you that layer of abstraction on top of the db to free you from some of the lower level APIs. Being able to call save on your document and have the check hapening transparently would make things so much easier. It's also a important feature in its own and would give thinky even more added value over a driver closer to the db.
Thanks @cur3n4 for the PR, this is very close to what I had tested and works nice. Also good that you have to opt in to avoid any disruption to previous versions.

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

No branches or pull requests

3 participants