pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] merlimat commented on a change in pull request #3015: Prevent race condition while calculating unack-msg offset stats
Date Mon, 19 Nov 2018 21:17:14 GMT
merlimat commented on a change in pull request #3015: Prevent race condition while calculating
unack-msg offset stats
URL: https://github.com/apache/pulsar/pull/3015#discussion_r234784498
 
 

 ##########
 File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
 ##########
 @@ -665,7 +665,11 @@ public long getNumberOfEntries() {
 
     @Override
     public long getNumberOfEntriesSinceFirstNotAckedMessage() {
-        return ledger.getNumberOfEntries(Range.openClosed(markDeletePosition, readPosition));
+        // sometimes for already caught up consumer: due to race condition markDeletePosition
> readPosition. so,
+        // validate it before preparing range
+        return (markDeletePosition.compareTo(readPosition) < 0)
+                ? ledger.getNumberOfEntries(Range.openClosed(markDeletePosition, readPosition))
 
 Review comment:
   The 2 variable can still change after the check. 
   
   I think we should add like: 
   
   ```java
   PositionImpl markDeletePosition = this.markDeletePosition;
   PositionImpl readPosition = this.readPosition;
   if (...) 
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message