liangyepianzhou commented on code in PR #21423:
URL: https://github.com/apache/pulsar/pull/21423#discussion_r1435792739


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedCursor.java:
##########
@@ -862,4 +862,8 @@ default void skipNonRecoverableLedger(long ledgerId){}
      * @return whether this cursor is closed.
      */
     boolean isClosed();
+
+    default boolean isCursorDataFullyPersistable() {
+        return true;

Review Comment:
   Why the default value is `true`?



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/BlockDispatcherSignatureOnCursorDataCanNotFullyPersist.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.service.persistent;
+
+/***
+ * A signature that relate to the check of "Dispatching has paused on cursor 
data can fully persist".
+ * Note: do not use this field to confirm whether the delivery should be 
paused,
+ *      please call {@link 
PersistentDispatcherMultipleConsumers#shouldPauseOnAckStatePersist}.
+ */
+public class BlockDispatcherSignatureOnCursorDataCanNotFullyPersist {
+
+    /**
+     * Used to mark that dispatching was paused at least once in the earlier 
time, due to the cursor data can not be
+     * fully persistent.
+     * Why need this filed? It just prevents that
+     * {@link 
PersistentDispatcherMultipleConsumers#afterAckMessages(Throwable, Object)} calls
+     * {@link PersistentDispatcherMultipleConsumers#readMoreEntries()} every 
time, it can avoid too many CPU circles.
+     * We just call {@link 
PersistentDispatcherMultipleConsumers#readMoreEntries()} after the dispatching 
has been
+     * paused at least once earlier.
+     */
+    private volatile boolean markerPausedAtLeastOnce;
+
+    /**
+     * Used to mark some acknowledgements were executed.
+     * Because there is a race condition might cause dispatching stuck, the 
steps to reproduce the issue is like below:
+     * - {@link #markerPausedAtLeastOnce} is "false" now.
+     * - Thread-reading-entries: there are too many ack holes, so start to 
pause dispatching
+     * - Thread-ack: acked all messages.

Review Comment:
   This does not seems to have any effect.
   1. `afterAckMessages`
   ```java
   blockSignatureOnCursorDataCanNotFullyPersist.markNewAcknowledged();
   ```
   2. `shouldPauseOnAckStatePersist: `
   ```java
   blockSignatureOnCursorDataCanNotFullyPersist.clearMakerNewAcknowledged();
   ```
   3. `afterAckMessages`
   ```java
           if 
(blockSignatureOnCursorDataCanNotFullyPersist.hasPausedAtLeastOnce()
                   && cursor.isCursorDataFullyPersistable()) {
               // clear paused count, and trigger a new reading.
               blockSignatureOnCursorDataCanNotFullyPersist.clearMarkerPaused();
               readMoreEntriesAsync();
           }
   ```
   4. `shouldPauseOnAckStatePersist`
   ```
    blockSignatureOnCursorDataCanNotFullyPersist.markPaused();
   ```
   



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java:
##########
@@ -113,6 +113,13 @@ public class PersistentDispatcherMultipleConsumers extends 
AbstractDispatcherMul
             
AtomicIntegerFieldUpdater.newUpdater(PersistentDispatcherMultipleConsumers.class,
                     "totalUnackedMessages");
     protected volatile int totalUnackedMessages = 0;
+    /**
+     * A signature that relate to the check of "Dispatching has paused on 
cursor data can fully persist".
+     * Note: do not use this field to confirm whether the delivery should be 
paused,

Review Comment:
   Why not? Could you please add an explanation here?



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