Optimistic concurrency control (sometimes referred to as optimistic locking) is a method where instead of locking a piece of data and preventing it from being read or updated while the lock is in place, the piece of data includes a version number.
All k8s resources include a metadata.resourceVersion field, which clients need to pass back to the API server when updating an object.
If the version doesn’t match the one stored in etcd, the API server rejects the update.
In C++ memory model, which is referred in transactional memory as implementation detail.
Every time the data is updated, the version number increases.
Since version number can be used with the scalar type, which can be add/minus with single instruction without lock.
When updating the data, the version number is checked to see if it has increased between the time the client read the data and the time it submits the update.
(perfect use case for atomic compare and exchange)
If this happens, the update is rejected and the client must re-read the new data and try to update it again.
The result is that when two clients try to update the same data entry, only the first one succeeds.
The result is that when two clients try to update the same data entry, only the first one succeeds.
All k8s resources include a metadata.resourceVersion field, which clients need to pass back to the API server when updating an object.
If the version doesn’t match the one stored in etcd, the API server rejects the update.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.