michaeljmarshall opened a new pull request, #4306:
URL: https://github.com/apache/bookkeeper/pull/4306
### Motivation
When tryOptimisticRead returns 0, the lock is acquired by another thread and
we will fail the validation step. We can therefore skip the eager cache
insertion.
Relevant javadocs from `StampedLock`:
```java
/**
* Returns a stamp that can later be validated, or zero
* if exclusively locked.
*
* @return a valid optimistic read stamp, or zero if exclusively locked
*/
public long tryOptimisticRead() {
long s;
return (((s = state) & WBIT) == 0L) ? (s & SBITS) : 0L;
}
/**
* Returns true if the lock has not been exclusively acquired
* since issuance of the given stamp. Always returns false if the
* stamp is zero. Always returns true if the stamp represents a
* currently held lock. Invoking this method with a value not
* obtained from {@link #tryOptimisticRead} or a locking method
* for this lock has no defined effect or result.
*
* @param stamp a stamp
* @return {@code true} if the lock has not been exclusively acquired
* since issuance of the given stamp; else false
*/
public boolean validate(long stamp) {
VarHandle.acquireFence();
return (stamp & SBITS) == (state & SBITS);
}
```
### Changes
Check for `stamp == 0` since it is a special case in the `StampedLock` class.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]