I am developing an application that use ZooKeeper as the datastore. For one of the methods in the application, I need to use the optimistic concurrent control. For example, I need to implement a get method which get the znode data, and I use the znode data version for the optimistic concurrent control check. For what I understand, one can't get the znode data and znode data version in one single operation. If there is high contention to update the znode data, the get method will not work since the znode data might changed after getting the znode data. so I am asking - is there a way I get can the znode data and znode data version (or znode stat) in one single operation without any locking attempt in between?
can ZooKeeper get znode data and znode data version (stat) in one single operation?
2.9k Views Asked by jedli2006 At
2
There are 2 best solutions below
0
ReneSac
On
In Python using Kazoo it is also trivial to get both stats and implement some optmistic locking. Here a sketch:
while True:
data, stat = zk.get("/path")
# do something with the data and then:
try:
zk.set("/path", new_data, stat.version)
break
except BadVersionError:
continue # or pass
Also, do use pre-made recipes when you can, as they are already extensively debuged, and should treat all corner cases.
Related Questions in APACHE-ZOOKEEPER
- Is curator's persistent ephemeral nodes just regular ephemeral with retries?
- Supervisor node will not connect to storm cluster
- Read Data from HBase running on EMR Cluster with Spark installed on local machine
- Apache Curator (Scala) New Session On Reconnect Without LOST State Change
- Ansible: How can I set serial numbers for hosts
- will the watcher be set if async operation returns error with zookeeper client?
- NullPointerException while loading extension in linux
- ZooKeeper Recipes and Apache Curator
- kafka spout can't connect to kafka topic
- HACluster Config for Stardog
- How do config tools like Consul "push" config updates to clients?
- How namespaces/zookeeper chroots work together in Apache Curator
- Zookeeper error: Cannot open channel to X at election address
- java.nio.channels.UnresolvedAddressException when running druid sample app
- What's the differenet between three zkclient libraries on maven central repo
Related Questions in OPTIMISTIC-LOCKING
- Hibernate increments version on both sides of many to many association
- Optimistic locking and re-try
- RESTful optimistic locking in Restangular
- Optimistic lock in Doctrine2 doesn't work for many to many relation
- Optimistic Locking doesn't work - no version increment, no exception
- Hibernate: lockMode for criteria is not working
- Increment version column on update
- JSF/JPA/EJB Best practice for locking an entity from the "Edit" page
- javax.persistence.version causes the Id of an entity to remain null in the transaction
- Version property of Parent isn't incrementing if I update child
- simple design question about optimistic locking in spring/jpa/hibernate
- simple optimistic lock question in jpa/spring/hibernate
- Hibernate OptimisticLockingFailureException not throwing when it's supposed to
- OptimisticLockException - Sql Server - Handle
- Using ETag for optimistic locking in a Django REST application
Related Questions in OPTIMISTIC-CONCURRENCY
- RavenDB - concurrency exception without optimistic concurrency
- RavenDB concurrency, locking documents or the likes?
- What is an efficient way to handle inserts of unique "immutable" entities by multiple producers with optimistic concurrency approach?
- Entity Framework 6 Oracle and Optimistic Concurrency
- ASP.NET MVC OptimisticConcurrencyException
- Optimistic lock in Doctrine2 doesn't work for many to many relation
- Implementing an Event Store with optimistic concurrency checks over multiple clients
- Entity Framework formats DateTime SQL parameter without milliseconds for optimistic concurrency
- ProstgreSQL, MySQL optimistic concurrency
- Linq to Sql - How to update an object using a repository pattern?
- OptimisticLock Trying update the same object again
- Expecting Concurrency Exceptions
- How can we avoid losing writes when using lightweight transactions (CAS) in Cassandra?
- How to handle org.eclipse.persistence.exceptions.OptimisticLockExceptio
- How to handle DbUpdateConcurrencyException?
Related Questions in OPTIMISTIC
- Solving Nhibernate concurrency issues
- jboss javax.persistence.OptimisticLockException
- Optimistic service validation vs Pessimistic validation
- Type error when using onMutate in react query (Optimistic Updates)
- Django form update optimistic locking, version based
- optimistic update for like/dislike and like count with react native, redux
- can ZooKeeper get znode data and znode data version (stat) in one single operation?
- JPA optimistic lock with SQLServer TIMESTAMP
- fluent nhibernate automap version column
- Apollo - Using optimisticResponse for dates
- Can a optimistic lock give a deadlock?
- Business application - pessimistic concurrency using messaging
- Improving worldwide website performance without using a CDN?
- Why does activerecord optimistic locking work only once per row?
- Does hibernate a default optimistic locking for detached objects?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
In Java, you can can achieve what you want easily:
This does read data and version information (in the
statobject) in a single operation. When you write back the data, you pass the version number you got when you read it:If there is a version mismatch, the method will throw
KeeperException.BadVersionException, which gives you an optimistic lock.