dao-jun commented on code in PR #22751:
URL: https://github.com/apache/pulsar/pull/22751#discussion_r1714755122
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java:
##########
@@ -891,10 +897,29 @@ private boolean sendChunkedMessagesToConsumers(ReadType
readType,
@Override
public synchronized void readEntriesFailed(ManagedLedgerException
exception, Object ctx) {
-
ReadType readType = (ReadType) ctx;
- long waitTimeMillis = readFailureBackoff.next();
+ if (readType == ReadType.Normal) {
+ havePendingRead = false;
+ } else {
+ havePendingReplayRead = false;
+ if (exception instanceof
ManagedLedgerException.InvalidReplayPositionException) {
+ PositionImpl markDeletePosition = (PositionImpl)
cursor.getMarkDeletedPosition();
+
redeliveryMessages.removeAllUpTo(markDeletePosition.getLedgerId(),
markDeletePosition.getEntryId());
+ }
+ }
+ if (shouldRewindBeforeReadingOrReplaying) {
+ shouldRewindBeforeReadingOrReplaying = false;
+ cursor.rewind();
+ }
+ readBatchSize = serviceConfig.getDispatcherMinReadBatchSize();
+ // Do not keep reading more entries if the cursor is already closed.
+ if (exception instanceof
ManagedLedgerException.CursorAlreadyClosedException) {
+ log.warn("[{}] Cursor was already closed when reading entries",
name);
+ return;
+ }
+
+ long waitTimeMillis = readFailureBackoff.next();
Review Comment:
Because the previous implementation will "not" break the calling chain, it
will calculate a "waitTimeMillis" and retry to read entries from BK. But when
`CursorAlreadyClosedException` happens, we dont need to retry to read entries.
Move these before the exception is for cleanup of the job.
Of course, there is an alternative: if the exception is
`CursorAlreadyClosedException`, set `waitTimeMillis` to -1
```java
// If waitTimeMillis < 0, which means we no need to retry to read
entries.
if (waitTimeMillis < 0) {
return;
}
topic.getBrokerService().executor().schedule(() -> {
synchronized (PersistentDispatcherMultipleConsumers.this) {
// If it's a replay read we need to retry even if there's
already
// another scheduled read, otherwise we'd be stuck until
// more messages are published.
if (!havePendingRead || readType == ReadType.Replay) {
log.info("[{}] Retrying read operation", name);
readMoreEntries();
} else {
log.info("[{}] Skipping read retry: havePendingRead {}",
name, havePendingRead, exception);
}
}
}, waitTimeMillis, TimeUnit.MILLISECONDS);
```
--
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]