Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces the third type of lock, the APPEND lock. (I'd like to solicit a better name!)
It doesn't check the lock high-water mark for the lock compatibility, but it always updates the lock high-water mark. Here is the summary of three lock types.
WRITE => checks the lock high-water mark and updates the lock high-water mark
READ => checks the lock high-water mark but doesn't update the lock high-water mark
APPEND => doesn't check the lock high-water mark but always updates the lock high-water mark
APPEND lock alone may not seem so useful. It is meant to be used with other locks.
Suppose you have a hierarchical resource (parent/child). You want to update the child resource in rapid succession, and you don't want other processes to update the child while doing it. Using a write lock on the parent for every child update is inefficient. It causes self-imposed lock contentions. One solution is to mark the parent resource with the ownership. It tells who is owning the resource. This transaction uses a write lock. A child update transaction uses a read lock to ensure that the current process still owns the resource. It will fail when the ownership is taken by another process.
This seems to work. But there is a potential issue. There is no way for the new owner to ensure that the child update is not in-flight when taking the ownership. The new owner may commit a transaction changing the ownership before a child update become visible to it.
An APPEND lock can be used when this is a concern. The ownership change transaction takes WRITE locks on the parent resource and the child resource. The child update transaction takes a READ lock on the parent and an APPEND lock on the child. This ensures that child updates are not causing lock contentions, and there is no in-flight transactions when the ownership changes.