Package org.apache.pulsar.broker.service
Class BrokerService
java.lang.Object
org.apache.pulsar.broker.service.BrokerService
- All Implemented Interfaces:
Closeable,AutoCloseable
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DispatchRateLimiterprotected PublishRateLimiterprotected final BrokerService.PublishRateLimiterMonitorprotected final AtomicReference<Semaphore>static final Stringfinal intstatic final Stringprotected final AtomicReference<Semaphore>protected final BrokerService.PublishRateLimiterMonitor -
Constructor Summary
ConstructorsConstructorDescriptionBrokerService(PulsarService pulsar, io.netty.channel.EventLoopGroup eventLoopGroup) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddUnAckedMessages(PersistentDispatcherMultipleConsumers 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) voidvoidAdds 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) deleteTopic(String topic, boolean forceDelete) voiddeleteTopicAuthenticationWithRetry(String topic, CompletableFuture<Void> future, int count) deleteTopicPolicies(org.apache.pulsar.common.naming.TopicName topicName) 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>fetchPartitionedTopicMetadataCheckAllowAutoCreationAsync(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) org.apache.pulsar.broker.authentication.AuthenticationServiceorg.apache.pulsar.broker.authorization.AuthorizationServiceSet<org.apache.pulsar.common.intercept.BrokerEntryMetadataInterceptor>org.apache.pulsar.client.admin.PulsarAdmingetClusterPulsarAdmin(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) intCompletableFuture<org.apache.bookkeeper.mledger.ManagedLedgerConfig>getManagedLedgerConfig(org.apache.pulsar.common.naming.TopicName topicName) org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap<String,org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap<String, org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap<String, Topic>>> intorg.apache.pulsar.common.policies.data.PersistentOfflineTopicStatsgetOfflineTopicStat(org.apache.pulsar.common.naming.TopicName topicName) getOrCreateTopic(String topic) longorg.apache.pulsar.client.api.PulsarClientgetReplicationClient(String cluster, Optional<org.apache.pulsar.common.policies.data.ClusterData> clusterDataOp) org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap<String,org.apache.pulsar.client.api.PulsarClient> getTopic(org.apache.pulsar.common.naming.TopicName topicName, boolean createIfMissing, Map<String, String> properties) getTopicIfExists(String topic) List<org.apache.pulsar.common.stats.Metrics>org.apache.bookkeeper.common.util.OrderedExecutorOptional<org.apache.pulsar.common.policies.data.TopicPolicies>getTopicPolicies(org.apache.pulsar.common.naming.TopicName topicName) GetTopicPoliciesfor the parameterized topic.getTopicReference(String topic) Get a reference to a topic that is currently loaded in the broker.org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap<String,CompletableFuture<Optional<Topic>>> voidinvalidateOfflineTopicStatCache(org.apache.pulsar.common.naming.TopicName topicName) booleanbooleanisAllowAutoSubscriptionCreation(org.apache.pulsar.common.naming.TopicName topicName) booleanisAllowAutoTopicCreation(String topic) booleanisAllowAutoTopicCreation(org.apache.pulsar.common.naming.TopicName topicName) booleanisAllowAutoTopicCreation(org.apache.pulsar.common.naming.TopicName topicName, Optional<org.apache.pulsar.common.policies.data.Policies> policies) booleanbooleanbooleanbooleanbooleanbooleanisDefaultTopicTypePartitioned(org.apache.pulsar.common.naming.TopicName topicName, Optional<org.apache.pulsar.common.policies.data.Policies> policies) static booleanbooleanisSystemTopic(String topic) booleanisSystemTopic(org.apache.pulsar.common.naming.TopicName topicName) booleanisTopicNsOwnedByBroker(org.apache.pulsar.common.naming.TopicName topicName) protected CompletableFuture<Optional<Topic>>loadOrCreatePersistentTopic(String topic, boolean createIfMissing, Map<String, String> properties) It creates a topic async and returns CompletableFuture.void<T extends Topic>
TnewTopic(String topic, org.apache.bookkeeper.mledger.ManagedLedger ledger, BrokerService brokerService, Class<T> topicClazz) voidpausedConnections(int numberOfConnections) pulsar()voidrefreshTopicToStatsMaps(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.removeTopicFromCache(String topicName) removeTopicFromCache(Topic topic) voidresumedConnections(int numberOfConnections) voidsetInterceptor(BrokerInterceptor interceptor) voidvoidSchedules and monitors publish-throttling for broker that has publish-throttling configured.voidSchedules and monitors publish-throttling for all owned topics that has publish-throttling configured.voidstart()protected 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<PersistentDispatcherMultipleConsumers> dispatcherList) Unblocks the dispatchers and removes it from theblockedDispatcherslist.voidIt unloads all owned namespacebundles gracefully.voidunloadNamespaceBundlesGracefully(int maxConcurrentUnload, boolean closeWithoutWaitingClientDisconnect) unloadServiceUnit(NamespaceBundle serviceUnit, boolean closeWithoutWaitingClientDisconnect, long timeout, TimeUnit unit) voidstatic booleanvalidateDynamicConfiguration(String key, String value)
-
Field Details
-
lookupRequestSemaphore
-
topicLoadRequestSemaphore
-
topicPublishRateLimiterMonitor
-
brokerPublishRateLimiterMonitor
-
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
-
startProtocolHandlers
public void startProtocolHandlers(Map<String, Map<InetSocketAddress, io.netty.channel.ChannelInitializer<io.netty.channel.socket.SocketChannel>>> protocolHandlers) -
start
- Throws:
Exception
-
startStatsUpdater
protected void startStatsUpdater(int statsUpdateInitialDelayInSecs, int statsUpdateFrequencyInSecs) -
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() -
setupTopicPublishRateLimiterMonitor
public void setupTopicPublishRateLimiterMonitor()Schedules and monitors publish-throttling for all owned topics that has publish-throttling configured. It also disables and shutdowns publish-rate-limiter monitor task if broker disables it. -
setupBrokerPublishRateLimiterMonitor
public void setupBrokerPublishRateLimiterMonitor()Schedules and monitors publish-throttling for broker that has publish-throttling configured. It also disables and shutdowns publish-rate-limiter monitor for broker task if broker disables it. -
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
-
deleteTopic
-
deleteTopicAuthenticationWithRetry
public void deleteTopicAuthenticationWithRetry(String topic, CompletableFuture<Void> future, int count) -
getReplicationClient
-
getClusterPulsarAdmin
-
loadOrCreatePersistentTopic
protected CompletableFuture<Optional<Topic>> loadOrCreatePersistentTopic(String topic, boolean createIfMissing, Map<String, String> properties) throws RuntimeExceptionIt 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
-
createPersistentTopic0
-
getManagedLedgerConfig
public CompletableFuture<org.apache.bookkeeper.mledger.ManagedLedgerConfig> getManagedLedgerConfig(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() -
checkMessageExpiry
public void checkMessageExpiry() -
checkReplicationPolicies
public void checkReplicationPolicies() -
checkCompaction
public void checkCompaction() -
checkMessageDeduplicationInfo
public void checkMessageDeduplicationInfo() -
checkInactiveSubscriptions
public void checkInactiveSubscriptions() -
checkTopicPublishThrottlingRate
public void checkTopicPublishThrottlingRate() -
checkBrokerPublishThrottlingRate
public void checkBrokerPublishThrottlingRate() -
forEachTopic
Iterates over all loaded topics in the broker. -
forEachPersistentTopic
-
getBacklogQuotaManager
-
monitorBacklogQuota
public void monitorBacklogQuota() -
isTopicNsOwnedByBroker
public boolean isTopicNsOwnedByBroker(org.apache.pulsar.common.naming.TopicName topicName) -
checkTopicNsOwnership
-
unloadServiceUnit
public CompletableFuture<Integer> unloadServiceUnit(NamespaceBundle serviceUnit, boolean closeWithoutWaitingClientDisconnect, long timeout, TimeUnit unit) -
cleanUnloadedTopicFromCache
-
getAuthorizationService
public org.apache.pulsar.broker.authorization.AuthorizationService getAuthorizationService() -
removeTopicFromCache
-
removeTopicFromCache
-
getNumberOfNamespaceBundles
public int getNumberOfNamespaceBundles() -
getTopics
public org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap<String,CompletableFuture<Optional<Topic>>> getTopics() -
pulsar
-
executor
public io.netty.channel.EventLoopGroup executor() -
getReplicationClients
public org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap<String,org.apache.pulsar.client.api.PulsarClient> getReplicationClients() -
isAuthenticationEnabled
public boolean isAuthenticationEnabled() -
isAuthorizationEnabled
public boolean isAuthorizationEnabled() -
getKeepAliveIntervalSeconds
public int getKeepAliveIntervalSeconds() -
generateUniqueProducerName
-
getTopicStats
-
getAuthenticationService
public org.apache.pulsar.broker.authentication.AuthenticationService 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).- Type Parameters:
T-- Parameters:
configKey- : configuration field namelistener- : listener which takes appropriate action on config-value change
-
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) -
getTopicOrderedExecutor
public org.apache.bookkeeper.common.util.OrderedExecutor getTopicOrderedExecutor() -
getMultiLayerTopicMap
-
addUnAckedMessages
public void addUnAckedMessages(PersistentDispatcherMultipleConsumers 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<PersistentDispatcherMultipleConsumers> dispatcherList) Unblocks the dispatchers and removes it from theblockedDispatcherslist.- Parameters:
dispatcherList-
-
extractTopic
Safely extract optional topic instance from a future, in a way to avoid unchecked exceptions and race conditions. -
getListenPort
-
getListenPortTls
-
isAllowAutoTopicCreation
-
isAllowAutoTopicCreation
public boolean isAllowAutoTopicCreation(org.apache.pulsar.common.naming.TopicName topicName) -
isAllowAutoTopicCreation
public boolean isAllowAutoTopicCreation(org.apache.pulsar.common.naming.TopicName topicName, Optional<org.apache.pulsar.common.policies.data.Policies> policies) -
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) -
isAllowAutoSubscriptionCreation
-
isAllowAutoSubscriptionCreation
public boolean isAllowAutoSubscriptionCreation(org.apache.pulsar.common.naming.TopicName topicName) -
isSystemTopic
-
isSystemTopic
public boolean isSystemTopic(org.apache.pulsar.common.naming.TopicName topicName) -
getTopicPolicies
public Optional<org.apache.pulsar.common.policies.data.TopicPolicies> getTopicPolicies(org.apache.pulsar.common.naming.TopicName topicName) GetTopicPoliciesfor the parameterized topic.- Parameters:
topicName-- Returns:
- TopicPolicies, if they exist. Otherwise, the value will not be present.
-
deleteTopicPolicies
public CompletableFuture<Void> deleteTopicPolicies(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() -
pausedConnections
public void pausedConnections(int numberOfConnections) -
resumedConnections
public void resumedConnections(int numberOfConnections) -
getPausedConnections
public long getPausedConnections() -
newTopic
public <T extends Topic> T newTopic(String topic, org.apache.bookkeeper.mledger.ManagedLedger ledger, BrokerService brokerService, Class<T> topicClazz) throws org.apache.pulsar.broker.PulsarServerException - Throws:
org.apache.pulsar.broker.PulsarServerException
-
setPulsarChannelInitializerFactory
-