Package org.apache.pulsar.broker.service
Class BrokerService
java.lang.Object
org.apache.pulsar.broker.service.BrokerService
- All Implemented Interfaces:
Closeable,AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DispatchRateLimiterprotected final PublishRateLimiterstatic final Stringprotected final AtomicReference<Semaphore>static final Stringfinal intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected final AtomicReference<Semaphore> -
Constructor Summary
ConstructorsConstructorDescriptionBrokerService(PulsarService pulsar, io.netty.channel.EventLoopGroup eventLoopGroup) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTopicEventListener(TopicEventsListener... listeners) voidaddUnAckedMessages(AbstractPersistentDispatcherMultipleConsumers dispatcher, int numberOfMessages) If per-broker unacked message reached to limit then it blocks dispatcher if its unacked message limit has been reached tomaxUnackedMsgsPerDispatcher.voidcacheOfflineTopicStats(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.PersistentOfflineTopicStats offlineTopicStats) voidvoidvoidcheckGC()voidvoidvoidvoidcheckTopicNsOwnership(String topic) voidAdds given dispatcher's unackMessage count to broker-unack message count and if it reaches to themaxUnackedMessagesthen it blocks all the dispatchers which has unack-messages higher thanmaxUnackedMsgsPerDispatcher.voidcleanUnloadedTopicFromCache(NamespaceBundle serviceUnit) voidclose()closeAndRemoveReplicationClient(String clusterName) voidcreatePersistentTopic0(String topic, boolean createIfMissing, CompletableFuture<Optional<Topic>> topicFuture, Map<String, String> properties) CompletableFuture<org.apache.pulsar.common.protocol.schema.SchemaVersion>deleteSchema(org.apache.pulsar.common.naming.TopicName topicName) deleteTopic(String topic, boolean forceDelete) voiddeleteTopicAuthenticationWithRetry(String topic, CompletableFuture<Void> future, int count) io.netty.channel.EventLoopGroupexecutor()extractTopic(CompletableFuture<Optional<Topic>> topicFuture) Safely extract optional topic instance from a future, in a way to avoid unchecked exceptions and race conditions.CompletableFuture<org.apache.pulsar.common.partition.PartitionedTopicMetadata>fetchPartitionedTopicMetadataAsync(org.apache.pulsar.common.naming.TopicName topicName) CompletableFuture<org.apache.pulsar.common.partition.PartitionedTopicMetadata>fetchPartitionedTopicMetadataAsync(org.apache.pulsar.common.naming.TopicName topicName, boolean refreshCacheAndGet) CompletableFuture<org.apache.pulsar.common.partition.PartitionedTopicMetadata>fetchPartitionedTopicMetadataCheckAllowAutoCreationAsync(org.apache.pulsar.common.naming.TopicName topicName) protected CompletableFuture<Map<String,String>> fetchTopicPropertiesAsync(org.apache.pulsar.common.naming.TopicName topicName) voidforEachPersistentTopic(Consumer<PersistentTopic> consumer) voidforEachTopic(Consumer<Topic> consumer) Iterates over all loaded topics in the broker.getAllTopicsFromNamespaceBundle(String namespace, String bundle) Set<org.apache.pulsar.common.intercept.BrokerEntryMetadataInterceptor>getClusterPulsarAdmin(String cluster, Optional<org.apache.pulsar.common.policies.data.ClusterData> clusterDataOp) intgetDefaultNumPartitions(org.apache.pulsar.common.naming.TopicName topicName, Optional<org.apache.pulsar.common.policies.data.Policies> policies) voidgetDimensionMetrics(Consumer<io.netty.buffer.ByteBuf> consumer) intgetManagedLedgerConfig(org.apache.pulsar.common.naming.TopicName topicName) getManagedLedgerFactoryForTopic(org.apache.pulsar.common.naming.TopicName topicName) getManagedLedgerFactoryForTopic(org.apache.pulsar.common.naming.TopicName topicName, String storageClassName) longorg.apache.pulsar.common.policies.data.PersistentOfflineTopicStatsgetOfflineTopicStat(org.apache.pulsar.common.naming.TopicName topicName) getOrCreateTopic(String topic) org.apache.pulsar.client.api.PulsarClientgetReplicationClient(String cluster, Optional<org.apache.pulsar.common.policies.data.ClusterData> clusterDataOp) getTopic(org.apache.pulsar.common.naming.TopicName topicName, boolean createIfMissing, Map<String, String> properties) Retrieves or creates a topic based on the specified parameters.getTopicIfExists(String topic) List<org.apache.pulsar.common.stats.Metrics>org.apache.bookkeeper.common.util.OrderedExecutorgetTopicReference(String topic) Get a reference to a topic that is currently loaded in the broker.getTopicStats(NamespaceBundle bundle) voidInitializes the in-memory delayed delivery tracker factory when BucketDelayedDeliveryTrackerFactory.newTracker failed.protected voidvoidinvalidateOfflineTopicStatCache(org.apache.pulsar.common.naming.TopicName topicName) isAllowAutoSubscriptionCreationAsync(org.apache.pulsar.common.naming.TopicName tpName) isAllowAutoTopicCreationAsync(org.apache.pulsar.common.naming.TopicName topicName) booleanbooleanbooleanbooleanbooleanbooleanisDefaultTopicTypePartitioned(org.apache.pulsar.common.naming.TopicName topicName, Optional<org.apache.pulsar.common.policies.data.Policies> policies) booleanbooleanisSystemTopic(String topic) booleanisSystemTopic(org.apache.pulsar.common.naming.TopicName topicName) isTopicNsOwnedByBrokerAsync(org.apache.pulsar.common.naming.TopicName topicName) protected CompletableFuture<Optional<Topic>>loadOrCreatePersistentTopic(String topic, boolean createIfMissing, Map<String, String> properties, org.apache.pulsar.common.policies.data.TopicPolicies topicPolicies) It creates a topic async and returns CompletableFuture.void<T extends Topic>
TnewTopic(String topic, ManagedLedger ledger, BrokerService brokerService, Class<T> topicClazz) pulsar()voidvoidvoidvoidvoidrefreshTopicToStatsMaps(NamespaceBundle oldBundle) <T> voidregisterConfigurationListener(String configKey, Consumer<T> listener) Allows a listener to listen on update ofServiceConfigurationchange, so listener can take appropriate action if any specific config-field value has been changed.voidregisterCustomDynamicConfiguration(String key, Predicate<String> validator) Allows the third-party plugin to register a custom dynamic configuration.voidremoveTopicEventListener(TopicEventsListener... listeners) removeTopicFromCache(Topic topic) voidsetInterceptor(BrokerInterceptor interceptor) voidvoidstart()protected voidprotected voidprotected voidprotected voidprotected voidprotected voidprotected voidprotected voidvoidstartProtocolHandlers(Map<String, Map<InetSocketAddress, io.netty.channel.ChannelInitializer<io.netty.channel.socket.SocketChannel>>> protocolHandlers) protected voidstartStatsUpdater(int statsUpdateInitialDelayInSecs, int statsUpdateFrequencyInSecs) voidunblockDispatchersOnUnAckMessages(List<AbstractPersistentDispatcherMultipleConsumers> dispatcherList) Unblocks the dispatchers and removes it from theblockedDispatcherslist.voidIt unloads all owned namespacebundles gracefully.voidunloadNamespaceBundlesGracefully(int maxConcurrentUnload, boolean closeWithoutWaitingClientDisconnect) unloadServiceUnit(NamespaceBundle serviceUnit, boolean disconnectClients, boolean closeWithoutWaitingClientDisconnect, long timeout, TimeUnit unit) voidbooleanvalidateDynamicConfiguration(String key, String value)
-
Field Details
-
lookupRequestSemaphore
-
topicLoadRequestSemaphore
-
TOPIC_LOOKUP_USAGE_METRIC_NAME
- See Also:
-
TOPIC_LOOKUP_LIMIT_METRIC_NAME
- See Also:
-
TOPIC_LOAD_USAGE_METRIC_NAME
- See Also:
-
TOPIC_LOAD_LIMIT_METRIC_NAME
- See Also:
-
CONNECTION_RATE_LIMIT_COUNT_METRIC_NAME
- See Also:
-
brokerPublishRateLimiter
-
brokerDispatchRateLimiter
-
PRODUCER_NAME_GENERATOR_PATH
- See Also:
-
MANAGED_LEDGER_PATH_ZNODE
- See Also:
-
maxUnackedMsgsPerDispatcher
public final int maxUnackedMsgsPerDispatcher
-
-
Constructor Details
-
BrokerService
public BrokerService(PulsarService pulsar, io.netty.channel.EventLoopGroup eventLoopGroup) throws Exception - Throws:
Exception
-
-
Method Details
-
addTopicEventListener
-
removeTopicEventListener
-
startProtocolHandlers
public void startProtocolHandlers(Map<String, Map<InetSocketAddress, io.netty.channel.ChannelInitializer<io.netty.channel.socket.SocketChannel>>> protocolHandlers) -
getTopicStats
public Map<String,org.apache.pulsar.common.policies.data.stats.TopicStatsImpl> getTopicStats(NamespaceBundle bundle) -
start
- Throws:
Exception
-
startClearInvalidateTopicNameCacheTask
protected void startClearInvalidateTopicNameCacheTask() -
startStatsUpdater
protected void startStatsUpdater(int statsUpdateInitialDelayInSecs, int statsUpdateFrequencyInSecs) -
initializeHealthChecker
protected void initializeHealthChecker() -
checkHealth
-
startDeduplicationSnapshotMonitor
protected void startDeduplicationSnapshotMonitor() -
startInactivityMonitor
protected void startInactivityMonitor() -
startMessageExpiryMonitor
protected void startMessageExpiryMonitor() -
startCheckReplicationPolicies
protected void startCheckReplicationPolicies() -
startCompactionMonitor
protected void startCompactionMonitor() -
startConsumedLedgersMonitor
protected void startConsumedLedgersMonitor() -
startBacklogQuotaChecker
protected void startBacklogQuotaChecker() -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
closeAndRemoveReplicationClient
-
closeAsync
-
unloadNamespaceBundlesGracefully
public void unloadNamespaceBundlesGracefully()It unloads all owned namespacebundles gracefully.- First it makes current broker unavailable and isolates from the clusters so, it will not serve any new requests.
- Second it starts unloading namespace bundle one by one without closing the connection in order to avoid disruption for other namespacebundles which are sharing the same connection from the same client.
-
unloadNamespaceBundlesGracefully
public void unloadNamespaceBundlesGracefully(int maxConcurrentUnload, boolean closeWithoutWaitingClientDisconnect) -
getTopicIfExists
-
getOrCreateTopic
-
getTopic
-
getTopic
-
getTopic
public CompletableFuture<Optional<Topic>> getTopic(org.apache.pulsar.common.naming.TopicName topicName, boolean createIfMissing, Map<String, String> properties) Retrieves or creates a topic based on the specified parameters. 0. If disable PersistentTopics or NonPersistentTopics, it will return a failed future with NotAllowedException. 1. If topic future exists in the cache returned directly regardless of whether it fails or timeout. 2. If the topic metadata exists, the topic is created regardless ofcreateIfMissing. 3. If the topic metadata not exists, andcreateIfMissingis false, returns an empty Optional in a CompletableFuture. And this empty future not be added to the map. 4. Otherwise, use computeIfAbsent. It returns the existing topic or creates and adds a new topicFuture. Any exceptions will remove the topicFuture from the map.- Parameters:
topicName- The name of the topic, potentially including partition information.createIfMissing- If true, creates the topic if it does not exist.properties- Topic configuration properties used during creation.- Returns:
- CompletableFuture with an Optional of the topic if found or created, otherwise empty.
-
deleteTopic
-
getManagedLedgerFactoryForTopic
public CompletableFuture<ManagedLedgerFactory> getManagedLedgerFactoryForTopic(org.apache.pulsar.common.naming.TopicName topicName) -
getManagedLedgerFactoryForTopic
public ManagedLedgerFactory getManagedLedgerFactoryForTopic(org.apache.pulsar.common.naming.TopicName topicName, String storageClassName) -
deleteTopicAuthenticationWithRetry
public void deleteTopicAuthenticationWithRetry(String topic, CompletableFuture<Void> future, int count) -
getReplicationClient
-
getClusterPulsarAdmin
public PulsarAdmin getClusterPulsarAdmin(String cluster, Optional<org.apache.pulsar.common.policies.data.ClusterData> clusterDataOp) -
loadOrCreatePersistentTopic
protected CompletableFuture<Optional<Topic>> loadOrCreatePersistentTopic(String topic, boolean createIfMissing, Map<String, String> properties, @Nullable org.apache.pulsar.common.policies.data.TopicPolicies topicPolicies) It creates a topic async and returns CompletableFuture. It also throttles down configured max-concurrent topic loading and puts them into queue once in-process topics are created.- Parameters:
topic- persistent-topic name- Returns:
- CompletableFuture
- Throws:
RuntimeException
-
fetchTopicPropertiesAsync
protected CompletableFuture<Map<String,String>> fetchTopicPropertiesAsync(org.apache.pulsar.common.naming.TopicName topicName) -
createPersistentTopic0
-
getManagedLedgerConfig
public CompletableFuture<ManagedLedgerConfig> getManagedLedgerConfig(@Nonnull org.apache.pulsar.common.naming.TopicName topicName) -
refreshTopicToStatsMaps
-
getOfflineTopicStat
public org.apache.pulsar.common.policies.data.PersistentOfflineTopicStats getOfflineTopicStat(org.apache.pulsar.common.naming.TopicName topicName) -
cacheOfflineTopicStats
public void cacheOfflineTopicStats(org.apache.pulsar.common.naming.TopicName topicName, org.apache.pulsar.common.policies.data.PersistentOfflineTopicStats offlineTopicStats) -
invalidateOfflineTopicStatCache
public void invalidateOfflineTopicStatCache(org.apache.pulsar.common.naming.TopicName topicName) -
getTopicReference
Get a reference to a topic that is currently loaded in the broker. This method will not make the broker attempt to load the topic if it's not already. -
updateRates
public void updateRates() -
getDimensionMetrics
-
getTopicMetrics
-
getBundleStats
-
getLookupRequestSemaphore
-
checkGC
public void checkGC() -
checkClusterMigration
public void checkClusterMigration() -
checkMessageExpiry
public void checkMessageExpiry() -
checkReplicationPolicies
public void checkReplicationPolicies() -
checkCompaction
public void checkCompaction() -
checkMessageDeduplicationInfo
public void checkMessageDeduplicationInfo() -
checkInactiveSubscriptions
public void checkInactiveSubscriptions() -
forEachTopic
Iterates over all loaded topics in the broker. -
forEachPersistentTopic
-
getBacklogQuotaManager
-
monitorBacklogQuota
public void monitorBacklogQuota() -
isTopicNsOwnedByBrokerAsync
public CompletableFuture<Boolean> isTopicNsOwnedByBrokerAsync(org.apache.pulsar.common.naming.TopicName topicName) -
checkTopicNsOwnership
-
unloadServiceUnit
public CompletableFuture<Integer> unloadServiceUnit(NamespaceBundle serviceUnit, boolean disconnectClients, boolean closeWithoutWaitingClientDisconnect, long timeout, TimeUnit unit) -
cleanUnloadedTopicFromCache
-
getAuthorizationService
-
removeTopicFromCache
-
getNumberOfNamespaceBundles
public long getNumberOfNamespaceBundles() -
pulsar
-
executor
public io.netty.channel.EventLoopGroup executor() -
isAuthenticationEnabled
public boolean isAuthenticationEnabled() -
isAuthorizationEnabled
public boolean isAuthorizationEnabled() -
getKeepAliveIntervalSeconds
public int getKeepAliveIntervalSeconds() -
generateUniqueProducerName
-
getTopicStats
-
getAuthenticationService
-
getAllTopicsFromNamespaceBundle
-
registerConfigurationListener
Allows a listener to listen on update ofServiceConfigurationchange, so listener can take appropriate action if any specific config-field value has been changed. On notification, listener should first check if config value has been changed and after taking appropriate action, listener should update config value with new value if it has been changed (so, next time listener can compare values on configMap change). Note: The new value that the may accept could be a null value.- Type Parameters:
T-- Parameters:
configKey- : configuration field namelistener- : listener which takes appropriate action on config-value change
-
registerCustomDynamicConfiguration
Allows the third-party plugin to register a custom dynamic configuration. -
getDelayedDeliveryTrackerFactory
-
getDynamicConfiguration
-
getRuntimeConfiguration
-
isDynamicConfiguration
-
validateDynamicConfiguration
-
fetchPartitionedTopicMetadataCheckAllowAutoCreationAsync
public CompletableFuture<org.apache.pulsar.common.partition.PartitionedTopicMetadata> fetchPartitionedTopicMetadataCheckAllowAutoCreationAsync(org.apache.pulsar.common.naming.TopicName topicName) -
fetchPartitionedTopicMetadataAsync
public CompletableFuture<org.apache.pulsar.common.partition.PartitionedTopicMetadata> fetchPartitionedTopicMetadataAsync(org.apache.pulsar.common.naming.TopicName topicName) -
fetchPartitionedTopicMetadataAsync
public CompletableFuture<org.apache.pulsar.common.partition.PartitionedTopicMetadata> fetchPartitionedTopicMetadataAsync(org.apache.pulsar.common.naming.TopicName topicName, boolean refreshCacheAndGet) -
getTopicOrderedExecutor
public org.apache.bookkeeper.common.util.OrderedExecutor getTopicOrderedExecutor() -
addUnAckedMessages
public void addUnAckedMessages(AbstractPersistentDispatcherMultipleConsumers dispatcher, int numberOfMessages) If per-broker unacked message reached to limit then it blocks dispatcher if its unacked message limit has been reached tomaxUnackedMsgsPerDispatcher.- Parameters:
dispatcher-numberOfMessages-
-
checkUnAckMessageDispatching
public void checkUnAckMessageDispatching()Adds given dispatcher's unackMessage count to broker-unack message count and if it reaches to themaxUnackedMessagesthen it blocks all the dispatchers which has unack-messages higher thanmaxUnackedMsgsPerDispatcher. It unblocks all dispatchers once broker-unack message counts decreased to (maxUnackedMessages/2) -
isBrokerDispatchingBlocked
public boolean isBrokerDispatchingBlocked() -
unblockDispatchersOnUnAckMessages
public void unblockDispatchersOnUnAckMessages(List<AbstractPersistentDispatcherMultipleConsumers> dispatcherList) Unblocks the dispatchers and removes it from theblockedDispatcherslist.- Parameters:
dispatcherList-
-
initializeFallbackDelayedDeliveryTrackerFactory
public void initializeFallbackDelayedDeliveryTrackerFactory()Initializes the in-memory delayed delivery tracker factory when BucketDelayedDeliveryTrackerFactory.newTracker failed. -
extractTopic
Safely extract optional topic instance from a future, in a way to avoid unchecked exceptions and race conditions. -
getListenPort
-
getListenPortTls
-
isAllowAutoTopicCreationAsync
-
isAllowAutoTopicCreationAsync
public CompletableFuture<Boolean> isAllowAutoTopicCreationAsync(org.apache.pulsar.common.naming.TopicName topicName) -
isDefaultTopicTypePartitioned
public boolean isDefaultTopicTypePartitioned(org.apache.pulsar.common.naming.TopicName topicName, Optional<org.apache.pulsar.common.policies.data.Policies> policies) -
getDefaultNumPartitions
public int getDefaultNumPartitions(org.apache.pulsar.common.naming.TopicName topicName, Optional<org.apache.pulsar.common.policies.data.Policies> policies) -
isAllowAutoSubscriptionCreationAsync
@Nonnull public CompletableFuture<Boolean> isAllowAutoSubscriptionCreationAsync(@Nonnull org.apache.pulsar.common.naming.TopicName tpName) -
isSystemTopic
-
isSystemTopic
public boolean isSystemTopic(org.apache.pulsar.common.naming.TopicName topicName) -
deleteSchema
public CompletableFuture<org.apache.pulsar.common.protocol.schema.SchemaVersion> deleteSchema(org.apache.pulsar.common.naming.TopicName topicName) -
setInterceptor
-
getBrokerEntryMetadataInterceptors
public Set<org.apache.pulsar.common.intercept.BrokerEntryMetadataInterceptor> getBrokerEntryMetadataInterceptors() -
isBrokerEntryMetadataEnabled
public boolean isBrokerEntryMetadataEnabled() -
isBrokerPayloadProcessorEnabled
public boolean isBrokerPayloadProcessorEnabled() -
recordConnectionPaused
public void recordConnectionPaused() -
recordConnectionResumed
public void recordConnectionResumed() -
recordConnectionThrottled
public void recordConnectionThrottled() -
recordConnectionUnthrottled
public void recordConnectionUnthrottled() -
newTopic
public <T extends Topic> T newTopic(String topic, ManagedLedger ledger, BrokerService brokerService, Class<T> topicClazz) throws PulsarServerException - Throws:
PulsarServerException
-
setPulsarChannelInitializerFactory
-