Class PersistentDispatcherMultipleConsumersClassic
java.lang.Object
org.apache.pulsar.broker.service.EntryFilterSupport
org.apache.pulsar.broker.service.AbstractBaseDispatcher
org.apache.pulsar.broker.service.AbstractDispatcherMultipleConsumers
org.apache.pulsar.broker.service.persistent.AbstractPersistentDispatcherMultipleConsumers
org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumersClassic
- All Implemented Interfaces:
AsyncCallbacks.ReadEntriesCallback,Dispatcher
- Direct Known Subclasses:
PersistentStickyKeyDispatcherMultipleConsumersClassic
public class PersistentDispatcherMultipleConsumersClassic
extends AbstractPersistentDispatcherMultipleConsumers
This is the "classic" dispatcher implementation for the Shared subscription that was used before
Pulsar 4.0.0 and PIP-379. When `subscriptionSharedUseClassicPersistentImplementation=true`,
this dispatcher will be used. The main purpose is to provide a way to rollback to the old behavior
in case of issues with the preferred implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final AtomicIntegerFieldUpdater<PersistentDispatcherMultipleConsumersClassic>A signature that relate to the check of "Dispatching has paused on cursor data can fully persist".protected static final AtomicIntegerFieldUpdater<PersistentDispatcherMultipleConsumersClassic>protected final ManagedCursorprotected final ExecutorServiceprotected Optional<DispatchRateLimiter>protected booleanprotected booleanprotected com.google.common.collect.Range<Position>protected Positionprotected final Stringprotected intprotected final org.apache.pulsar.common.util.Backoffprotected final MessageRedeliveryControllerprotected final RedeliveryTrackerprotected booleanprotected final PersistentTopicprotected static final AtomicIntegerFieldUpdater<PersistentDispatcherMultipleConsumersClassic>protected intprotected intFields inherited from class org.apache.pulsar.broker.service.AbstractDispatcherMultipleConsumers
consumerList, consumerSet, currentConsumerRoundRobinIndex, FALSE, IS_CLOSED_UPDATER, TRUEFields inherited from class org.apache.pulsar.broker.service.AbstractBaseDispatcher
dispatchThrottlingOnBatchMessageEnabled, serviceConfigFields inherited from class org.apache.pulsar.broker.service.EntryFilterSupport
entryFilters, filterContext, hasFilter, subscription -
Constructor Summary
ConstructorsConstructorDescriptionPersistentDispatcherMultipleConsumersClassic(PersistentTopic topic, ManagedCursor cursor, Subscription subscription) PersistentDispatcherMultipleConsumersClassic(PersistentTopic topic, ManagedCursor cursor, Subscription subscription, boolean allowOutOfOrderDelivery) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddConsumer(Consumer consumer) protected booleanaddMessageToReplay(long ledgerId, long entryId) protected booleanaddMessageToReplay(long ledgerId, long entryId, long stickyKeyHash) voidaddUnAckedMessages(int numberOfMessages) voidafterAckMessages(Throwable exOfDeletion, Object ctxOfDeletion) A callback hook after acknowledge messages.asyncReplayEntries(Set<? extends Position> positions) asyncReplayEntriesInOrder(Set<? extends Position> positions) voidcalculateToRead(int currentTotalAvailablePermits) protected voidbooleancanUnsubscribe(Consumer consumer) booleanTrigger a new "readMoreEntries" if the dispatching has been paused before.booleanChecks if dispatcher is stuck and unblocks the dispatch if needed.close(boolean disconnectConsumers, Optional<BrokerLookupData> assignedBrokerLookupData) voidconsumerFlow(Consumer consumer, int additionalNumberOfMessages) Indicates that this consumer is now ready to receive more messages.voiddisconnectActiveConsumers(boolean isResetCursor) Disconnect active consumers.disconnectAllConsumers(boolean isResetCursor, Optional<BrokerLookupData> assignedBrokerLookupData) protected NavigableSet<Position>This is a mode method designed for Key_Shared mode.longprotected intprotected NavigableSet<Position>getMessagesToReplayNow(int maxMessagesToRead) getName()longlongprotected intgetStickyKeyHash(Entry entry) getTopic()intorg.apache.pulsar.common.api.proto.CommandSubscribe.SubTypegetType()protected booleanThis is a mode method designed for Key_Shared mode, to avoid unnecessary stuck.booleanprotected booleanreturns true only ifAbstractDispatcherMultipleConsumers.consumerListhas atleast one unblocked consumer and have available permits.booleanbooleanbooleanisConsumerAvailable(Consumer consumer) booleanprotected booleanDetermine whether the number of consumers on the subscription reaches the threshold.booleanbooleanprotected booleanfinal voidreadEntriesComplete(List<Entry> entries, Object ctx) voidreadEntriesFailed(ManagedLedgerException exception, Object ctx) voidvoidWe should not call readMoreEntries() recursively in the same thread as there is a risk of StackOverflowError.voidredeliverUnacknowledgedMessages(Consumer consumer, long consumerEpoch) voidredeliverUnacknowledgedMessages(Consumer consumer, List<Position> positions) protected voidvoidremoveConsumer(Consumer consumer) protected voidvoidreset()mark dispatcher open to serve new incoming requests.voidprotected final booleansendMessagesToConsumers(PersistentDispatcherMultipleConsumersClassic.ReadType readType, List<Entry> entries, boolean needAcquireSendInProgress) protected booleanbooleantrackDelayedDelivery(long ledgerId, long entryId, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata) Check with dispatcher if the message should be added to the delayed delivery tracker.protected booleantrySendMessagesToConsumers(PersistentDispatcherMultipleConsumersClassic.ReadType readType, List<Entry> entries) Dispatch the messages to the Consumers.voidMethods inherited from class org.apache.pulsar.broker.service.AbstractDispatcherMultipleConsumers
getNextConsumer, getRandomConsumer, isClosedMethods inherited from class org.apache.pulsar.broker.service.AbstractBaseDispatcher
acquirePermitsForDeliveredMessages, checkAndApplyReachedEndOfTopicOrTopicMigration, checkAndApplyReachedEndOfTopicOrTopicMigration, computeReadLimits, filterEntriesForConsumer, filterEntriesForConsumer, getFilterAcceptedMsgCount, getFilterProcessedMsgCount, getFilterRejectedMsgCount, getFilterRescheduledMsgCount, getSubscriptionName, isConsumersExceededOnSubscription, peekStickyKey, updateMessagesToRead, updatePendingBytesToDispatchMethods inherited from class org.apache.pulsar.broker.service.EntryFilterSupport
runFiltersForEntryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.pulsar.broker.service.Dispatcher
close, disconnectAllConsumers, disconnectAllConsumers, getFilterAcceptedMsgCount, getFilterProcessedMsgCount, getFilterRejectedMsgCount, getFilterRescheduledMsgCount, isClosed, markDeletePositionMoveForward, updateRateLimiter
-
Field Details
-
topic
-
cursor
-
lastIndividualDeletedRangeFromCursorRecovery
protected volatile com.google.common.collect.Range<Position> lastIndividualDeletedRangeFromCursorRecovery -
redeliveryMessages
-
redeliveryTracker
-
havePendingRead
protected volatile boolean havePendingRead -
havePendingReplayRead
protected volatile boolean havePendingReplayRead -
minReplayedPosition
-
shouldRewindBeforeReadingOrReplaying
protected boolean shouldRewindBeforeReadingOrReplaying -
name
-
TOTAL_AVAILABLE_PERMITS_UPDATER
protected static final AtomicIntegerFieldUpdater<PersistentDispatcherMultipleConsumersClassic> TOTAL_AVAILABLE_PERMITS_UPDATER -
totalAvailablePermits
protected volatile int totalAvailablePermits -
readBatchSize
protected volatile int readBatchSize -
readFailureBackoff
protected final org.apache.pulsar.common.util.Backoff readFailureBackoff -
totalUnackedMessages
protected volatile int totalUnackedMessages -
BLOCKED_DISPATCHER_ON_CURSOR_DATA_CAN_NOT_FULLY_PERSIST_UPDATER
protected static final AtomicIntegerFieldUpdater<PersistentDispatcherMultipleConsumersClassic> BLOCKED_DISPATCHER_ON_CURSOR_DATA_CAN_NOT_FULLY_PERSIST_UPDATERA signature that relate to the check of "Dispatching has paused on cursor data can fully persist". Note: It is a tool that helps determine whether it should trigger a new reading after acknowledgments to avoid too many CPU circles, seeafterAckMessages(Throwable, Object)for more details. Do not use this to confirm whether the delivery should be paused, please callshouldPauseOnAckStatePersist(org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumersClassic.ReadType). -
BLOCKED_DISPATCHER_ON_UNACKMSG_UPDATER
protected static final AtomicIntegerFieldUpdater<PersistentDispatcherMultipleConsumersClassic> BLOCKED_DISPATCHER_ON_UNACKMSG_UPDATER -
dispatchRateLimiter
-
dispatchMessagesThread
-
-
Constructor Details
-
PersistentDispatcherMultipleConsumersClassic
public PersistentDispatcherMultipleConsumersClassic(PersistentTopic topic, ManagedCursor cursor, Subscription subscription) -
PersistentDispatcherMultipleConsumersClassic
public PersistentDispatcherMultipleConsumersClassic(PersistentTopic topic, ManagedCursor cursor, Subscription subscription, boolean allowOutOfOrderDelivery)
-
-
Method Details
-
addConsumer
-
isConsumersExceededOnSubscription
protected boolean isConsumersExceededOnSubscription()Description copied from class:AbstractBaseDispatcherDetermine whether the number of consumers on the subscription reaches the threshold.- Specified by:
isConsumersExceededOnSubscriptionin classAbstractBaseDispatcher- Returns:
-
removeConsumer
- Throws:
BrokerServiceException
-
consumerFlow
Description copied from interface:DispatcherIndicates that this consumer is now ready to receive more messages. -
readMoreEntriesAsync
public void readMoreEntriesAsync()We should not call readMoreEntries() recursively in the same thread as there is a risk of StackOverflowError.- Specified by:
readMoreEntriesAsyncin classAbstractPersistentDispatcherMultipleConsumers
-
readMoreEntries
public void readMoreEntries() -
reScheduleRead
protected void reScheduleRead()- Specified by:
reScheduleReadin classAbstractBaseDispatcher
-
calculateToRead
-
asyncReplayEntries
-
asyncReplayEntriesInOrder
-
isConsumerConnected
public boolean isConsumerConnected()- Specified by:
isConsumerConnectedin interfaceDispatcher- Overrides:
isConsumerConnectedin classAbstractDispatcherMultipleConsumers
-
getConsumers
- Specified by:
getConsumersin interfaceDispatcher- Overrides:
getConsumersin classAbstractDispatcherMultipleConsumers
-
canUnsubscribe
- Specified by:
canUnsubscribein interfaceDispatcher- Overrides:
canUnsubscribein classAbstractDispatcherMultipleConsumers
-
close
public CompletableFuture<Void> close(boolean disconnectConsumers, Optional<BrokerLookupData> assignedBrokerLookupData) -
disconnectAllConsumers
public CompletableFuture<Void> disconnectAllConsumers(boolean isResetCursor, Optional<BrokerLookupData> assignedBrokerLookupData) -
cancelPendingRead
protected void cancelPendingRead()- Overrides:
cancelPendingReadin classAbstractDispatcherMultipleConsumers
-
disconnectActiveConsumers
Description copied from interface:DispatcherDisconnect active consumers. -
resetCloseFuture
public void resetCloseFuture()- Specified by:
resetCloseFuturein interfaceDispatcher- Overrides:
resetCloseFuturein classAbstractBaseDispatcher
-
reset
public void reset()Description copied from interface:Dispatchermark dispatcher open to serve new incoming requests. -
getType
public org.apache.pulsar.common.api.proto.CommandSubscribe.SubType getType()- Specified by:
getTypein interfaceDispatcher- Overrides:
getTypein classAbstractDispatcherMultipleConsumers
-
readEntriesComplete
-
acquireSendInProgress
protected void acquireSendInProgress() -
releaseSendInProgress
protected void releaseSendInProgress() -
isSendInProgress
protected boolean isSendInProgress() -
sendMessagesToConsumers
protected final boolean sendMessagesToConsumers(PersistentDispatcherMultipleConsumersClassic.ReadType readType, List<Entry> entries, boolean needAcquireSendInProgress) -
trySendMessagesToConsumers
protected boolean trySendMessagesToConsumers(PersistentDispatcherMultipleConsumersClassic.ReadType readType, List<Entry> entries) Dispatch the messages to the Consumers.- Returns:
- true if you want to trigger a new read. This method is overridden by other classes, please take a look to other implementations if you need to change it.
-
readEntriesFailed
-
isAtleastOneConsumerAvailable
protected boolean isAtleastOneConsumerAvailable()returns true only ifAbstractDispatcherMultipleConsumers.consumerListhas atleast one unblocked consumer and have available permits.- Returns:
-
getFirstAvailableConsumerPermits
protected int getFirstAvailableConsumerPermits() -
isConsumerAvailable
- Specified by:
isConsumerAvailablein classAbstractDispatcherMultipleConsumers
-
redeliverUnacknowledgedMessages
-
redeliverUnacknowledgedMessages
-
addUnAckedMessages
public void addUnAckedMessages(int numberOfMessages) -
afterAckMessages
Description copied from interface:DispatcherA callback hook after acknowledge messages.- Parameters:
exOfDeletion- the ex ofManagedCursor.asyncDelete(org.apache.bookkeeper.mledger.Position, org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteCallback, java.lang.Object),ManagedCursor.asyncClearBacklog(org.apache.bookkeeper.mledger.AsyncCallbacks.ClearBacklogCallback, java.lang.Object)or {@link ManagedCursor#asyncSkipEntries)}.ctxOfDeletion- the param ctx of callingManagedCursor.asyncDelete(org.apache.bookkeeper.mledger.Position, org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteCallback, java.lang.Object),ManagedCursor.asyncClearBacklog(org.apache.bookkeeper.mledger.AsyncCallbacks.ClearBacklogCallback, java.lang.Object)or {@link ManagedCursor#asyncSkipEntries)}.
-
checkAndResumeIfPaused
public boolean checkAndResumeIfPaused()Description copied from interface:DispatcherTrigger a new "readMoreEntries" if the dispatching has been paused before. This method is only implemented inAbstractPersistentDispatcherMultipleConsumersright now, other implementations do not necessary implement this method.- Returns:
- did a resume.
-
isBlockedDispatcherOnUnackedMsgs
public boolean isBlockedDispatcherOnUnackedMsgs()- Specified by:
isBlockedDispatcherOnUnackedMsgsin classAbstractPersistentDispatcherMultipleConsumers
-
blockDispatcherOnUnackedMsgs
public void blockDispatcherOnUnackedMsgs()- Specified by:
blockDispatcherOnUnackedMsgsin classAbstractPersistentDispatcherMultipleConsumers
-
unBlockDispatcherOnUnackedMsgs
public void unBlockDispatcherOnUnackedMsgs()- Specified by:
unBlockDispatcherOnUnackedMsgsin classAbstractPersistentDispatcherMultipleConsumers
-
getTotalUnackedMessages
public int getTotalUnackedMessages()- Specified by:
getTotalUnackedMessagesin classAbstractPersistentDispatcherMultipleConsumers
-
getName
- Specified by:
getNamein classAbstractPersistentDispatcherMultipleConsumers
-
getRedeliveryTracker
-
getRateLimiter
-
initializeDispatchRateLimiterIfNeeded
public boolean initializeDispatchRateLimiterIfNeeded() -
trackDelayedDelivery
public boolean trackDelayedDelivery(long ledgerId, long entryId, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata) Description copied from interface:DispatcherCheck with dispatcher if the message should be added to the delayed delivery tracker. Return true if the message should be delayed and ignored at this point. -
getMessagesToReplayNow
-
hasConsumersNeededNormalRead
protected boolean hasConsumersNeededNormalRead()This is a mode method designed for Key_Shared mode, to avoid unnecessary stuck. See detailPersistentStickyKeyDispatcherMultipleConsumersClassic.hasConsumersNeededNormalRead(). -
shouldPauseDeliveryForDelayTracker
protected boolean shouldPauseDeliveryForDelayTracker() -
getNumberOfDelayedMessages
public long getNumberOfDelayedMessages() -
clearDelayedMessages
-
cursorIsReset
public void cursorIsReset() -
addMessageToReplay
protected boolean addMessageToReplay(long ledgerId, long entryId, long stickyKeyHash) -
addMessageToReplay
protected boolean addMessageToReplay(long ledgerId, long entryId) -
checkAndUnblockIfStuck
public boolean checkAndUnblockIfStuck()Description copied from interface:DispatcherChecks if dispatcher is stuck and unblocks the dispatch if needed. -
getTopic
- Specified by:
getTopicin classAbstractPersistentDispatcherMultipleConsumers
-
getDelayedTrackerMemoryUsage
public long getDelayedTrackerMemoryUsage()- Specified by:
getDelayedTrackerMemoryUsagein classAbstractPersistentDispatcherMultipleConsumers
-
getBucketDelayedIndexStats
public Map<String,org.apache.pulsar.common.policies.data.stats.TopicMetricBean> getBucketDelayedIndexStats()- Specified by:
getBucketDelayedIndexStatsin classAbstractPersistentDispatcherMultipleConsumers
-
isClassic
public boolean isClassic()- Specified by:
isClassicin classAbstractPersistentDispatcherMultipleConsumers
-
getCursor
- Specified by:
getCursorin classAbstractPersistentDispatcherMultipleConsumers
-
getStickyKeyHash
-
getSubscription
- Specified by:
getSubscriptionin classAbstractPersistentDispatcherMultipleConsumers
-
getNumberOfMessagesInReplay
public long getNumberOfMessagesInReplay()- Specified by:
getNumberOfMessagesInReplayin classAbstractPersistentDispatcherMultipleConsumers
-
isHavePendingRead
public boolean isHavePendingRead()- Specified by:
isHavePendingReadin classAbstractPersistentDispatcherMultipleConsumers
-
isHavePendingReplayRead
public boolean isHavePendingReplayRead()- Specified by:
isHavePendingReplayReadin classAbstractPersistentDispatcherMultipleConsumers
-