Class NamespaceService
java.lang.Object
org.apache.pulsar.broker.namespace.NamespaceService
- All Implemented Interfaces:
AutoCloseable
The
NamespaceService provides resource ownership lookup as well as resource ownership claiming services
for the PulsarService.
The PulsarService relies on this service for resource ownership operations.
The focus of this phase is to bring up the system and be able to iterate and improve the services effectively.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final Stringstatic final Stringstatic final Patternstatic final Patternstatic final Stringstatic final io.opentelemetry.api.common.Attributesstatic final io.opentelemetry.api.common.Attributesstatic final io.opentelemetry.api.common.Attributesstatic final Stringstatic final Patternstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddNamespaceBundleSplitListener(NamespaceBundleSplitListener... listeners) static StringcheckHeartbeatNamespace(org.apache.pulsar.common.naming.ServiceUnitId ns) static StringcheckHeartbeatNamespaceV2(org.apache.pulsar.common.naming.ServiceUnitId ns) checkNonPartitionedTopicExists(org.apache.pulsar.common.naming.TopicName topic) Check non-partitioned topic exists.Regarding non-persistent topic, we do not know whether it exists or not.booleancheckOwnershipPresent(NamespaceBundle bundle) checkTopicExists(org.apache.pulsar.common.naming.TopicName topic) Check topic exists( partitioned or non-partitioned ).checkTopicOwnership(org.apache.pulsar.common.naming.TopicName topicName) voidclose()createLookupResult(String candidateBroker, boolean authoritativeRedirect, String advertisedListenerName) getAllPartitions(org.apache.pulsar.common.naming.NamespaceName namespaceName) getBrokerServiceUrlAsync(org.apache.pulsar.common.naming.TopicName topic, LookupOptions options) getBundle(org.apache.pulsar.common.naming.TopicName topicName) getBundleAsync(org.apache.pulsar.common.naming.TopicName topic) intgetBundleCount(org.apache.pulsar.common.naming.NamespaceName namespace) getBundleIfPresent(org.apache.pulsar.common.naming.TopicName topicName) getFullListOfPartitionedTopic(org.apache.pulsar.common.naming.NamespaceName namespaceName) getFullListOfTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName) static org.apache.pulsar.common.naming.NamespaceNamegetHeartbeatNamespace(String lookupBroker, ServiceConfiguration config) static org.apache.pulsar.common.naming.NamespaceNamegetHeartbeatNamespaceV2(String lookupBroker, ServiceConfiguration config) getHeartbeatOrSLAMonitorBrokerId(org.apache.pulsar.common.naming.ServiceUnitId serviceUnit, Function<String, CompletableFuture<Boolean>> isBrokerActive) Check if this is Heartbeat or SLAMonitor namespace and return the broker id.getListOfNonPersistentTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName) getListOfPersistentTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName) List persistent topics names under a namespace, the topic name contains the partition suffix.getListOfTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode mode) getListOfUserTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode mode) getNamespaceBundleSplitAlgorithmByName(String algorithmName) getNamespaceClient(org.apache.pulsar.common.policies.data.ClusterDataImpl cluster) CompletableFuture<Map<String,org.apache.pulsar.common.policies.data.NamespaceOwnershipStatus>> getOwnerAsync(NamespaceBundle bundle) getPartitions(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.naming.TopicDomain topicDomain) org.apache.pulsar.common.naming.ServiceUnitIdgetServiceUnitId(org.apache.pulsar.common.naming.TopicName topicName) static StringgetSLAMonitorBrokerName(org.apache.pulsar.common.naming.ServiceUnitId ns) static org.apache.pulsar.common.naming.NamespaceNamegetSLAMonitorNamespace(String lookupBroker, ServiceConfiguration config) getSplitBoundary(NamespaceBundle bundle, List<Long> boundaries, NamespaceBundleSplitAlgorithm nsBundleSplitAlgorithm) CompletableFuture<org.apache.commons.lang3.tuple.Pair<NamespaceBundles,List<NamespaceBundle>>> getSplitBoundary(NamespaceBundle bundle, NamespaceBundleSplitAlgorithm nsBundleSplitAlgorithm, List<Long> boundaries) Get the split boundary's.getWebServiceUrl(org.apache.pulsar.common.naming.ServiceUnitId suName, LookupOptions options) Return the URL of the broker who's owning a particular service unit.getWebServiceUrlAsync(org.apache.pulsar.common.naming.ServiceUnitId suName, LookupOptions options) Return the URL of the broker who's owning a particular service unit in asynchronous way.voidbooleanisBrokerActive(String candidateBroker) static booleanisHeartbeatNamespace(org.apache.pulsar.common.naming.ServiceUnitId ns) booleanbooleanisServiceUnitActive(org.apache.pulsar.common.naming.TopicName topicName) Deprecated.This method is only used in test now.isServiceUnitActiveAsync(org.apache.pulsar.common.naming.TopicName topicName) booleanisServiceUnitOwned(org.apache.pulsar.common.naming.ServiceUnitId suName) isServiceUnitOwnedAsync(org.apache.pulsar.common.naming.ServiceUnitId suName) static booleanisSLAOrHeartbeatNamespace(String namespace) used for filtering bundles in special namespace.static booleanisSystemServiceNamespace(String namespace) voidvoidvoidvoidRegister all the bootstrap name spaces including the heartbeat namespace.booleanregisterNamespace(org.apache.pulsar.common.naming.NamespaceName nsname, boolean ensureOwned) Tries to register a namespace to this instance.booleanremoveOwnedServiceUnitAsync(NamespaceBundle nsBundle) splitAndOwnBundle(NamespaceBundle bundle, boolean unload, NamespaceBundleSplitAlgorithm splitAlgorithm, List<Long> boundaries) 1.unloadNamespaceBundle(NamespaceBundle bundle) unloadNamespaceBundle(NamespaceBundle bundle, long timeout, TimeUnit timeoutUnit) unloadNamespaceBundle(NamespaceBundle bundle, long timeout, TimeUnit timeoutUnit, boolean closeWithoutWaitingClientDisconnect) unloadNamespaceBundle(NamespaceBundle bundle, Optional<String> destinationBroker) unloadNamespaceBundle(NamespaceBundle bundle, Optional<String> destinationBroker, long timeout, TimeUnit timeoutUnit) unloadNamespaceBundle(NamespaceBundle bundle, Optional<String> destinationBroker, long timeout, TimeUnit timeoutUnit, boolean closeWithoutWaitingClientDisconnect) voidupdateNamespaceBundles(org.apache.pulsar.common.naming.NamespaceName nsname, NamespaceBundles nsBundles) Update new bundle-range to LocalZk (create a new node if not present).updateNamespaceBundlesForPolicies(org.apache.pulsar.common.naming.NamespaceName nsname, NamespaceBundles nsBundles) Update new bundle-range to admin/policies/namespace.
-
Field Details
-
BUNDLE_SPLIT_RETRY_LIMIT
public static final int BUNDLE_SPLIT_RETRY_LIMIT- See Also:
-
SLA_NAMESPACE_PROPERTY
- See Also:
-
HEARTBEAT_NAMESPACE_PATTERN
-
HEARTBEAT_NAMESPACE_PATTERN_V2
-
SLA_NAMESPACE_PATTERN
-
HEARTBEAT_NAMESPACE_FMT
- See Also:
-
HEARTBEAT_NAMESPACE_FMT_V2
- See Also:
-
SLA_NAMESPACE_FMT
- See Also:
-
LOOKUP_REQUEST_DURATION_METRIC_NAME
- See Also:
-
PULSAR_LOOKUP_RESPONSE_BROKER_ATTRIBUTES
public static final io.opentelemetry.api.common.Attributes PULSAR_LOOKUP_RESPONSE_BROKER_ATTRIBUTES -
PULSAR_LOOKUP_RESPONSE_REDIRECT_ATTRIBUTES
public static final io.opentelemetry.api.common.Attributes PULSAR_LOOKUP_RESPONSE_REDIRECT_ATTRIBUTES -
PULSAR_LOOKUP_RESPONSE_FAILURE_ATTRIBUTES
public static final io.opentelemetry.api.common.Attributes PULSAR_LOOKUP_RESPONSE_FAILURE_ATTRIBUTES
-
-
Constructor Details
-
NamespaceService
Default constructor.
-
-
Method Details
-
initialize
public void initialize() -
getBrokerServiceUrlAsync
public CompletableFuture<Optional<LookupResult>> getBrokerServiceUrlAsync(org.apache.pulsar.common.naming.TopicName topic, LookupOptions options) -
getBundleAsync
public CompletableFuture<NamespaceBundle> getBundleAsync(org.apache.pulsar.common.naming.TopicName topic) -
getBundleIfPresent
public Optional<NamespaceBundle> getBundleIfPresent(org.apache.pulsar.common.naming.TopicName topicName) -
getBundle
-
getBundleCount
- Throws:
Exception
-
getWebServiceUrlAsync
public CompletableFuture<Optional<URL>> getWebServiceUrlAsync(org.apache.pulsar.common.naming.ServiceUnitId suName, LookupOptions options) Return the URL of the broker who's owning a particular service unit in asynchronous way.If the service unit is not owned, return a CompletableFuture with empty optional.
-
getWebServiceUrl
public Optional<URL> getWebServiceUrl(org.apache.pulsar.common.naming.ServiceUnitId suName, LookupOptions options) throws Exception Return the URL of the broker who's owning a particular service unit.If the service unit is not owned, return an empty optional
- Throws:
Exception
-
registerBootstrapNamespaces
Register all the bootstrap name spaces including the heartbeat namespace.- Throws:
PulsarServerException- if an unexpected error occurs
-
registerNamespace
public boolean registerNamespace(org.apache.pulsar.common.naming.NamespaceName nsname, boolean ensureOwned) throws PulsarServerException Tries to register a namespace to this instance.- Parameters:
nsname- namespace nameensureOwned- sets the behavior when the namespace is already owned by another broker. If this flag is set to true, then the method will throw an exception. If this flag is set to false, then the method will return false.- Returns:
- true if the namespace was successfully registered, false otherwise
- Throws:
PulsarServerException- if an error occurs when registering the namespace
-
getHeartbeatOrSLAMonitorBrokerId
public CompletableFuture<String> getHeartbeatOrSLAMonitorBrokerId(org.apache.pulsar.common.naming.ServiceUnitId serviceUnit, Function<String, CompletableFuture<Boolean>> isBrokerActive) Check if this is Heartbeat or SLAMonitor namespace and return the broker id.- Parameters:
serviceUnit- the service unitisBrokerActive- the function to check if the broker is active- Returns:
- the broker id
-
createLookupResult
public CompletableFuture<LookupResult> createLookupResult(String candidateBroker, boolean authoritativeRedirect, String advertisedListenerName) -
isBrokerActive
-
unloadNamespaceBundle
-
unloadNamespaceBundle
public CompletableFuture<Void> unloadNamespaceBundle(NamespaceBundle bundle, Optional<String> destinationBroker) -
unloadNamespaceBundle
public CompletableFuture<Void> unloadNamespaceBundle(NamespaceBundle bundle, Optional<String> destinationBroker, long timeout, TimeUnit timeoutUnit) -
unloadNamespaceBundle
public CompletableFuture<Void> unloadNamespaceBundle(NamespaceBundle bundle, long timeout, TimeUnit timeoutUnit) -
unloadNamespaceBundle
public CompletableFuture<Void> unloadNamespaceBundle(NamespaceBundle bundle, long timeout, TimeUnit timeoutUnit, boolean closeWithoutWaitingClientDisconnect) -
unloadNamespaceBundle
public CompletableFuture<Void> unloadNamespaceBundle(NamespaceBundle bundle, Optional<String> destinationBroker, long timeout, TimeUnit timeoutUnit, boolean closeWithoutWaitingClientDisconnect) -
isNamespaceBundleOwned
-
getOwnedNameSpacesStatusAsync
public CompletableFuture<Map<String,org.apache.pulsar.common.policies.data.NamespaceOwnershipStatus>> getOwnedNameSpacesStatusAsync() -
isNamespaceBundleDisabled
- Throws:
Exception
-
splitAndOwnBundle
public CompletableFuture<Void> splitAndOwnBundle(NamespaceBundle bundle, boolean unload, NamespaceBundleSplitAlgorithm splitAlgorithm, List<Long> boundaries) 1. split the given bundle into two bundles 2. assign ownership of both the bundles to current broker 3. update policies with newly created bundles into LocalZK 4. disable original bundle and refresh the cache.It will call splitAndOwnBundleOnceAndRetry to do the real retry work, which will retry "retryTimes".
- Parameters:
bundle- the bundle to splitunload- whether to unload the new split bundlessplitAlgorithm- the algorithm to split the bundleboundaries- the boundaries to split the bundle- Returns:
- a future that will complete when the bundle is split and owned
-
getSplitBoundary
public CompletableFuture<org.apache.commons.lang3.tuple.Pair<NamespaceBundles,List<NamespaceBundle>>> getSplitBoundary(NamespaceBundle bundle, NamespaceBundleSplitAlgorithm nsBundleSplitAlgorithm, List<Long> boundaries) Get the split boundary's.- Parameters:
bundle- The bundle to split.boundaries- The specified positions, use forSpecifiedPositionsBundleSplitAlgorithm.- Returns:
- A pair, left is target namespace bundle, right is split bundles.
-
getSplitBoundary
public CompletableFuture<List<Long>> getSplitBoundary(NamespaceBundle bundle, List<Long> boundaries, NamespaceBundleSplitAlgorithm nsBundleSplitAlgorithm) -
getNamespaceBundleSplitAlgorithmByName
-
updateNamespaceBundlesForPolicies
public CompletableFuture<Void> updateNamespaceBundlesForPolicies(org.apache.pulsar.common.naming.NamespaceName nsname, NamespaceBundles nsBundles) Update new bundle-range to admin/policies/namespace. Update may fail because of concurrent write to Zookeeper.- Parameters:
nsname- the namespace namensBundles- the new namespace bundles
-
updateNamespaceBundles
public CompletableFuture<Void> updateNamespaceBundles(org.apache.pulsar.common.naming.NamespaceName nsname, NamespaceBundles nsBundles) Update new bundle-range to LocalZk (create a new node if not present). Update may fail because of concurrent write to Zookeeper.- Parameters:
nsname- the namespace namensBundles- the new namespace bundles
-
getOwnershipCache
-
getOwnedServiceUnits
-
isServiceUnitOwned
public boolean isServiceUnitOwned(org.apache.pulsar.common.naming.ServiceUnitId suName) throws Exception - Throws:
Exception
-
isServiceUnitOwnedAsync
public CompletableFuture<Boolean> isServiceUnitOwnedAsync(org.apache.pulsar.common.naming.ServiceUnitId suName) -
isServiceUnitActive
Deprecated.This method is only used in test now. -
isServiceUnitActiveAsync
public CompletableFuture<Boolean> isServiceUnitActiveAsync(org.apache.pulsar.common.naming.TopicName topicName) -
checkTopicOwnership
public CompletableFuture<Boolean> checkTopicOwnership(org.apache.pulsar.common.naming.TopicName topicName) -
removeOwnedServiceUnitAsync
-
onNamespaceBundleOwned
-
onNamespaceBundleUnload
-
onNamespaceBundleSplit
-
addNamespaceBundleOwnershipListener
-
addNamespaceBundleSplitListener
-
getNamespaceBundleFactory
-
getServiceUnitId
public org.apache.pulsar.common.naming.ServiceUnitId getServiceUnitId(org.apache.pulsar.common.naming.TopicName topicName) throws Exception - Throws:
Exception
-
getFullListOfTopics
public CompletableFuture<List<String>> getFullListOfTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName) -
getFullListOfPartitionedTopic
public CompletableFuture<List<String>> getFullListOfPartitionedTopic(org.apache.pulsar.common.naming.NamespaceName namespaceName) -
getOwnedTopicListForNamespaceBundle
-
checkTopicExists
public CompletableFuture<TopicExistsInfo> checkTopicExists(org.apache.pulsar.common.naming.TopicName topic) Check topic exists( partitioned or non-partitioned ). -
checkNonPartitionedTopicExists
public CompletableFuture<Boolean> checkNonPartitionedTopicExists(org.apache.pulsar.common.naming.TopicName topic) Check non-partitioned topic exists. -
checkNonPersistentNonPartitionedTopicExists
Regarding non-persistent topic, we do not know whether it exists or not. Redirect the request to the ownership broker of this topic. HTTP API has implemented the mechanism that redirect to ownership broker, so just call HTTP API here. -
getListOfTopics
public CompletableFuture<List<String>> getListOfTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode mode) -
getListOfUserTopics
public CompletableFuture<List<String>> getListOfUserTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode mode) -
getAllPartitions
public CompletableFuture<List<String>> getAllPartitions(org.apache.pulsar.common.naming.NamespaceName namespaceName) -
getPartitions
public CompletableFuture<List<String>> getPartitions(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.naming.TopicDomain topicDomain) -
getListOfPersistentTopics
public CompletableFuture<List<String>> getListOfPersistentTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName) List persistent topics names under a namespace, the topic name contains the partition suffix. -
getListOfNonPersistentTopics
public CompletableFuture<List<String>> getListOfNonPersistentTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName) -
getNamespaceClient
public PulsarClientImpl getNamespaceClient(org.apache.pulsar.common.policies.data.ClusterDataImpl cluster) -
getOwnerAsync
-
checkOwnershipPresent
- Throws:
Exception
-
checkOwnershipPresentAsync
-
unloadSLANamespace
- Throws:
Exception
-
getHeartbeatNamespace
public static org.apache.pulsar.common.naming.NamespaceName getHeartbeatNamespace(String lookupBroker, ServiceConfiguration config) -
getHeartbeatNamespaceV2
public static org.apache.pulsar.common.naming.NamespaceName getHeartbeatNamespaceV2(String lookupBroker, ServiceConfiguration config) -
getSLAMonitorNamespace
public static org.apache.pulsar.common.naming.NamespaceName getSLAMonitorNamespace(String lookupBroker, ServiceConfiguration config) -
checkHeartbeatNamespace
-
checkHeartbeatNamespaceV2
-
getSLAMonitorBrokerName
-
isSystemServiceNamespace
-
isSLAOrHeartbeatNamespace
used for filtering bundles in special namespace.- Parameters:
namespace- the namespace name- Returns:
- True if namespace is HEARTBEAT_NAMESPACE or SLA_NAMESPACE
-
isHeartbeatNamespace
public static boolean isHeartbeatNamespace(org.apache.pulsar.common.naming.ServiceUnitId ns) -
registerSLANamespace
- Throws:
PulsarServerException
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-