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 answers
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
- Changing kafka zookeeper.connect by adding chroot
- Suppress Log4j Output from org.apache.zookeeper.ZooKeeper
- Using Kazoo to interact with a ZK cluster
- Zookeeper timeout when upgrade flink 1.14 to 1.18
- Docker-compose Kafka: no brokers available
- Why I'm getting this error when implementing SSL security in zookeeper(kafka) and connecting using zookeeper-shell.sh - PKIX path building failed?
- Keeper Clickhouse Replication DDL on cluster, but no replication data, error "Table was in readonly mode"
- zkcli upconfig by using java service
- Error while running the zookeeper command on windows machine
- HBase Zookeeper Connection Error Docker Standalone 2.3.x and 2.4.x
- can't to start clickhouse service after restart
- The system cannot find the path specified. Unable to start Zookeeper
- Zookeeper integration with .Net c# getting error while fetching node
- log4j properties doesn't apply after upgrading zookeeper from 3.6.3 to 3.9.1
- kafka controllers + root cause of re-elect in worse case scenario
Related Questions in OPTIMISTIC-LOCKING
- Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) with @SqlListener using
- Optimistic locking in Spring boot REST application
- Set expected version (optimistic locking)
- Cannot force version increment on non-versioned entity
- Elasticsearch and spring data (optimistic locking)
- Spring Cassandra with optimistic lock, the entity immediately saved after deleting by the partition key will missing
- OptimisticLockException on entityManager.flush()
- Junit5 Optimistic locking exception
- Implementation of Optimistic Locking in Database Updates
- Generate sequential and distinct order numbers for vendors in PostgreSQL
- Correct way to deal with optimistic lock in jOOQ without records
- Jpa Optimistic locking without version attribute in database possible?
- Does MongoDB supports optimistic locks for bulk operations?
- React Query mutating individual items in table by switch buttons rapidly causes buttons to turning off and on again and affecting each other
- Why doesn't my optimistic lock implementation work with two competing requests?
Related Questions in OPTIMISTIC-CONCURRENCY
- How to handle DbUpdateConcurrencyException?
- Convert SQL Server Timestamp to query string
- Unable to reproduce DbUpdateConcurrencyException while debugging
- Does MongoDB supports optimistic locks for bulk operations?
- How do you solve concurrency issues when horizontally scaling microservices that are sharing a DB?
- How can I prevent a second user from overwriting an entity property(column) in EF Core?
- Handling DbUpdateConcurrencyException by simply aborting all operations
- Handling DbUpdateConcurrencyException with SaveChangesInterceptors
- ElasticSearch document is getting updated even after IfSeqNo and IfPrimaryTerm values don't match with assigned sequence number and primary term
- Optimistic Offline Lock: Achieve this in database offering Serializability without Linearizability? (i.e., DB does not provide strict serializability)
- create-two-separate-transactions-in-jpa-within-one-method-call spring boot jpa
- Configure IsConcurrencyToken(value) with annotations in EF Core
- SQL Server READ_COMMITTED_SNAPSHOT Isolation Level - Shared Lock Issue
- EF Core Rowversion Concurrency Check Not Handle DbConcurrency Error
- Implement Optimistic Concurrency Control in Golang for all entities
Related Questions in OPTIMISTIC
- SQL Server opportunistic locking
- Optimistic service validation vs Pessimistic validation
- Visual replication issue when moving tasks between columns using Angular and Firebase
- Django form update optimistic locking, version based
- Type error when using onMutate in react query (Optimistic Updates)
- prisma:Optimistic Concurrency Control Use UpdateMany Has Problems
- Optimistic Locking in Rails not allowing record to be modified in the console
- Can a optimistic lock give a deadlock?
- Apollo - Using optimisticResponse for dates
- Apollo Cache - Partially read from cache?
- optimistic update for like/dislike and like count with react native, redux
- React: Unique keys and optimistic updating
- JPA optimistic lock with SQLServer TIMESTAMP
- Is this a good first project for my low Java skill? *Age Detector*
- Do optimistic locks work for multiple applications
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?
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)
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.