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 2021/09/22 04:38:45 UTC

[GitHub] [pulsar] michaeljmarshall commented on a change in pull request #12123: Fix the potential race condition in the BlobStore readhandler

michaeljmarshall commented on a change in pull request #12123:
URL: https://github.com/apache/pulsar/pull/12123#discussion_r713583729



##########
File path: tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java
##########
@@ -54,6 +56,15 @@
     private final DataInputStream dataStream;
     private final ExecutorService executor;
 
+    enum State {
+        Opened,
+        Closed
+    }
+
+    private AtomicReferenceFieldUpdater<BlobStoreBackedReadHandleImpl, State> STATE_UPDATER = AtomicReferenceFieldUpdater
+        .newUpdater(BlobStoreBackedReadHandleImpl.class, State.class, "state");
+    private volatile State state = null;

Review comment:
       I'm not sure that we need these concurrency controls. The `executor` in this class is a single thread. Therefore, a local `state` variable should be sufficient as long as we only update the variable from within the `executor`'s thread.

##########
File path: tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java
##########
@@ -105,6 +118,11 @@ public LedgerMetadata getLedgerMetadata() {
                 long nextExpectedId = firstEntry;
                 try {
                     while (entriesToRead > 0) {
+                        State state = STATE_UPDATER.get(this);
+                        if (state == State.Closed) {
+                            log.warn("Reading a closed read handler. Ledger ID: {}, Read range: {}-{}", ledgerId, firstEntry, lastEntry);
+                            throw new BKException.BKUnexpectedConditionException();

Review comment:
       Should this complete the `promise` exceptionally?




-- 
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: commits-unsubscribe@pulsar.apache.org

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