lhotari commented on code in PR #23903:
URL: https://github.com/apache/pulsar/pull/23903#discussion_r1932885264


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/util/RangeCache.java:
##########
@@ -116,7 +148,11 @@ V getValue(K key) {
                 localValue = this.value;
                 lock.unlockRead(stamp);
             }
-            if (localKey != key) {
+            // check that the given key matches the key associated with the 
value in the entry

Review Comment:
   > Don' we need to wrap void recycle() with the write lock?
   
   That's not necessary since the solution already prevents race reads. In Java 
on 64 bit JVMs, there's no data corruption problems with racy writes and reads 
to fields. The problem to solve is about consistency across multiple fields and 
about visibility of the changes. When recycling, it would just be unnecessary 
overhead to add a write lock. The `getRetainedValueMatchingKey` will detect if 
the key and value don't match by calling the `matchesKey` method, which in 
`EntryImpl` is implemented in this way:
   ```java
       public boolean matchesKey(Position key) {
           return key.compareTo(ledgerId, entryId) == 0;
       }
   ```
   One of the goals of RangeCache is to avoid exclusive locks as much as 
possible. The write lock on StampedLock is cheap, but we can also avoid that 
cost in this case.



-- 
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]

Reply via email to