Class ServiceUnitStateChannelImpl
java.lang.Object
org.apache.pulsar.broker.loadbalance.extensions.channel.ServiceUnitStateChannelImpl
- All Implemented Interfaces:
Closeable,AutoCloseable,ServiceUnitStateChannel
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCancels the ownership monitor.voidCleans(gives up) any service unit ownerships from this broker.voidclose()Closes the ServiceUnitStateChannel.protected voiddisable()protected voidenable()static ServiceUnitStateChannelget(PulsarService pulsar) getAssigned(String serviceUnit) Asynchronously gets the assigned broker of the service unit.protected BrokerRegistryAsynchronously gets the current owner broker of this channel.protected LoadManagerContextprotected LeaderElectionServiceprotected ExtensibleLoadManagerImplList<org.apache.pulsar.common.stats.Metrics>Generates the metrics to monitor.Asynchronously returns service units owned by this broker.getOwnerAsync(String serviceUnit) Case 1: If the service unit is owned, it returns the completed future object with the current owner.Asynchronously returns service unit ownership entry set.protected PulsarAdminprotected voidhandleBrokerRegistrationEvent(String broker, org.apache.pulsar.metadata.api.NotificationType type) Case 1: If NotificationType is Deleted, it will schedule a clean-up operation to release the ownerships of the deleted broker.protected voidhandleMetadataSessionEvent(org.apache.pulsar.metadata.api.extended.SessionEvent e) The stability of the metadata connection is important to determine how to handle the broker deletion(unavailable) event notified from the metadata store.booleanChecks if the current broker is the owner broker of this channel.Asynchronously checks if the current broker is the owner broker of this channel.booleanChecks if the current broker is the owner of the service unit.booleanChecks if the target broker is the owner of the service unit.voidlisten(StateChangeListener listener) Adds a state change listener.protected voidmonitorOwnerships(List<String> brokers) publishAssignEventAsync(String serviceUnit, String brokerId) Asynchronously publishes the service unit assignment event to this channel.publishSplitEventAsync(Split split) Asynchronously publishes the bundle split event to this channel.publishUnloadEventAsync(Unload unload) Asynchronously publishes the service unit unload event to this channel.voidSchedules ownership monitor to periodically check and correct invalid ownership states.protected voidsplitServiceUnitOnceAndRetry(NamespaceService namespaceService, NamespaceBundleFactory bundleFactory, NamespaceBundleSplitAlgorithm algorithm, NamespaceBundle parentBundle, List<NamespaceBundle> childBundles, List<Long> boundaries, ServiceUnitStateData parentData, AtomicInteger counter, long startTime, CompletableFuture<Void> completionFuture) voidstart()Starts the ServiceUnitStateChannel.booleanstarted()Whether the channel started.
-
Field Details
-
VERSION_ID_INIT
public static final long VERSION_ID_INIT- See Also:
-
MAX_CLEAN_UP_DELAY_TIME_IN_SECS
public static final long MAX_CLEAN_UP_DELAY_TIME_IN_SECS- See Also:
-
-
Constructor Details
-
ServiceUnitStateChannelImpl
-
-
Method Details
-
scheduleOwnershipMonitor
public void scheduleOwnershipMonitor()Description copied from interface:ServiceUnitStateChannelSchedules ownership monitor to periodically check and correct invalid ownership states.- Specified by:
scheduleOwnershipMonitorin interfaceServiceUnitStateChannel
-
cancelOwnershipMonitor
public void cancelOwnershipMonitor()Description copied from interface:ServiceUnitStateChannelCancels the ownership monitor.- Specified by:
cancelOwnershipMonitorin interfaceServiceUnitStateChannel
-
cleanOwnerships
public void cleanOwnerships()Description copied from interface:ServiceUnitStateChannelCleans(gives up) any service unit ownerships from this broker.- Specified by:
cleanOwnershipsin interfaceServiceUnitStateChannel
-
started
public boolean started()Description copied from interface:ServiceUnitStateChannelWhether the channel started.- Specified by:
startedin interfaceServiceUnitStateChannel
-
start
Description copied from interface:ServiceUnitStateChannelStarts the ServiceUnitStateChannel.- Specified by:
startin interfaceServiceUnitStateChannel- Throws:
PulsarServerException- if it fails to start the channel.
-
getBrokerRegistry
-
getContext
-
getLoadManager
-
getLeaderElectionService
-
getPulsarAdmin
- Throws:
PulsarServerException
-
close
Description copied from interface:ServiceUnitStateChannelCloses the ServiceUnitStateChannel.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceServiceUnitStateChannel- Throws:
PulsarServerException- if it fails to close the channel.
-
getChannelOwnerAsync
Description copied from interface:ServiceUnitStateChannelAsynchronously gets the current owner broker of this channel.- Specified by:
getChannelOwnerAsyncin interfaceServiceUnitStateChannel- Returns:
- a future of owner brokerId to track the completion of the operation
-
isChannelOwnerAsync
Description copied from interface:ServiceUnitStateChannelAsynchronously checks if the current broker is the owner broker of this channel.- Specified by:
isChannelOwnerAsyncin interfaceServiceUnitStateChannel- Returns:
- a future of check result to track the completion of the operation
-
isChannelOwner
Description copied from interface:ServiceUnitStateChannelChecks if the current broker is the owner broker of this channel.- Specified by:
isChannelOwnerin interfaceServiceUnitStateChannel- Returns:
- True if the current broker is the owner. Otherwise, false.
- Throws:
ExecutionExceptionInterruptedExceptionTimeoutException
-
isOwner
Description copied from interface:ServiceUnitStateChannelChecks if the target broker is the owner of the service unit.- Specified by:
isOwnerin interfaceServiceUnitStateChannel- Parameters:
serviceUnit- (e.g. bundle)- Returns:
- true if the target brokerId is the owner brokerId. false if unknown.
-
isOwner
Description copied from interface:ServiceUnitStateChannelChecks if the current broker is the owner of the service unit.- Specified by:
isOwnerin interfaceServiceUnitStateChannel- Parameters:
serviceUnit- (e.g. bundle))- Returns:
- true if the current broker is the owner. false if unknown.
-
getOwnerAsync
Case 1: If the service unit is owned, it returns the completed future object with the current owner. Case 2: If the service unit's assignment is ongoing, it returns the non-completed future object. Sub-case1: If the assigned broker is available and finally takes the ownership, the future object will complete and return the owner broker. Sub-case2: If the assigned broker does not take the ownership in time, the future object will time out. Case 3: If none of them, it returns Optional.empty().- Specified by:
getOwnerAsyncin interfaceServiceUnitStateChannel- Parameters:
serviceUnit- (e.g. bundle)- Returns:
- a future of owner brokerId to track the completion of the operation
-
getAssigned
Description copied from interface:ServiceUnitStateChannelAsynchronously gets the assigned broker of the service unit.- Specified by:
getAssignedin interfaceServiceUnitStateChannel- Parameters:
serviceUnit- (e.g. bundle))- Returns:
- assigned brokerId
-
publishAssignEventAsync
Description copied from interface:ServiceUnitStateChannelAsynchronously publishes the service unit assignment event to this channel.- Specified by:
publishAssignEventAsyncin interfaceServiceUnitStateChannel- Parameters:
serviceUnit- (e.g bundle)brokerId- the assigned brokerId- Returns:
- a future of owner brokerId to track the completion of the operation
-
publishUnloadEventAsync
Description copied from interface:ServiceUnitStateChannelAsynchronously publishes the service unit unload event to this channel.- Specified by:
publishUnloadEventAsyncin interfaceServiceUnitStateChannel- Parameters:
unload- (unload specification object)- Returns:
- a future to track the completion of the operation
-
publishSplitEventAsync
Description copied from interface:ServiceUnitStateChannelAsynchronously publishes the bundle split event to this channel.- Specified by:
publishSplitEventAsyncin interfaceServiceUnitStateChannel- Parameters:
split- (split specification object)- Returns:
- a future to track the completion of the operation
-
splitServiceUnitOnceAndRetry
protected void splitServiceUnitOnceAndRetry(NamespaceService namespaceService, NamespaceBundleFactory bundleFactory, NamespaceBundleSplitAlgorithm algorithm, NamespaceBundle parentBundle, List<NamespaceBundle> childBundles, List<Long> boundaries, ServiceUnitStateData parentData, AtomicInteger counter, long startTime, CompletableFuture<Void> completionFuture) -
handleMetadataSessionEvent
protected void handleMetadataSessionEvent(org.apache.pulsar.metadata.api.extended.SessionEvent e) The stability of the metadata connection is important to determine how to handle the broker deletion(unavailable) event notified from the metadata store. -
handleBrokerRegistrationEvent
protected void handleBrokerRegistrationEvent(String broker, org.apache.pulsar.metadata.api.NotificationType type) Case 1: If NotificationType is Deleted, it will schedule a clean-up operation to release the ownerships of the deleted broker. Sub-case1: If the metadata connection has been stable for long time, it will immediately execute the cleanup operation to guarantee high-availability. Sub-case2: If the metadata connection has been stable only for short time, it will defer the clean-up operation for some time and execute it. This is to gracefully handle the case when metadata connection is flaky -- If the deleted broker comes back very soon, we better cancel the clean-up operation for high-availability. Sub-case3: If the metadata connection is unstable, it will not schedule the clean-up operation, as the broker-metadata connection is lost. The brokers will continue to serve existing topics connections, and we better not to interrupt the existing topic connections for high-availability. Case 2: If NotificationType is Created, it will cancel any scheduled clean-up operation if still not executed. -
monitorOwnerships
-
getMetrics
Description copied from interface:ServiceUnitStateChannelGenerates the metrics to monitor.- Specified by:
getMetricsin interfaceServiceUnitStateChannel- Returns:
- a list of the metrics
-
listen
Description copied from interface:ServiceUnitStateChannelAdds a state change listener.- Specified by:
listenin interfaceServiceUnitStateChannel- Parameters:
listener- State change listener.
-
getOwnershipEntrySet
Description copied from interface:ServiceUnitStateChannelAsynchronously returns service unit ownership entry set.- Specified by:
getOwnershipEntrySetin interfaceServiceUnitStateChannel- Returns:
- a set of service unit ownership entries to track the completion of the operation
-
getOwnedServiceUnits
Description copied from interface:ServiceUnitStateChannelAsynchronously returns service units owned by this broker.- Specified by:
getOwnedServiceUnitsin interfaceServiceUnitStateChannel- Returns:
- a set of owned service units to track the completion of the operation
-
get
-
disable
protected void disable() -
enable
protected void enable()
-