You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/10/19 06:40:14 UTC

[GitHub] [pulsar] lhotari opened a new issue #8293: Race condition in updating ManagedCursorImpl.readPosition

lhotari opened a new issue #8293:
URL: https://github.com/apache/pulsar/issues/8293


   **Describe the bug**
   #8229 seems to have been caused by a race condition in updating `ManagedCursorImpl.readPosition`
   
   **To Reproduce**
   Since this is a concurrency issue, it's hard to reproduce and there isn't yet a publicly shared way to reproduce.
   
   **Expected behavior**
   Updates to `ManagedCursorImpl.readPosition` field should not lead to inconsistent state. It's not clear without understanding the code how concurrent updates should be handled.
   
   **Additional context**
   Please refer to #8229 for additional context. There's a link to a Slack thread for more discussions.
   
   There's a fix for #8229 which prevents the infinite loop: #8284 . This fix doesn't specifically address the race condition that happens in updating the ManagedCursorImpl.readPosition field. 
   
   There seems to be quite a few past issues where a race condition in updating readPosition has been an issue. For example https://github.com/apache/pulsar/pull/1478 , https://github.com/apache/pulsar/pull/3015 & https://github.com/apache/pulsar/pull/287 .
   
   There is also a change https://github.com/apache/pulsar/pull/6606 which adds `READ_POSITION_UPDATER` for `ManagedCursorImpl.readPosition`.
   
   Regarding the race condition in #8229, it seems that `ManagedCursorImpl.readPosition` could get out of sync from `OpReadEntry.readPosition` if `ManagedCursorImpl.readPosition` gets updated after the `OpReadEntry` has been created since `OpReadEntry`'s `readPosition` gets initialized from `ManagedCursorImpl.readPosition`.
   
   The race condition seems to happen in this code in the `setAcknowledgePosition` method:
   
   https://github.com/apache/pulsar/blob/825fdd4222dd65ef3099f1a975a1555226297379/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java#L1512-L1523
   
   In other locations, whenever `readPosition` field is modified, it is locked. In this particular location, there is no lock.
   
   However https://github.com/apache/pulsar/pull/6606 introduced another method for handling race condition. So there are 2 ways to handle race conditions for `ManagedCursorImpl.readPosition` field: `ManagedCursorImpl.lock.writeLock()` and there's also `ManagedCursorImpl.READ_POSITION_UPDATER` which is used in one location to update  `ManagedCursorImpl.readPosition`.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] merlimat closed issue #8293: Race condition in updating ManagedCursorImpl.readPosition

Posted by GitBox <gi...@apache.org>.
merlimat closed issue #8293:
URL: https://github.com/apache/pulsar/issues/8293


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org