Class NamespaceService
- java.lang.Object
-
- org.apache.pulsar.broker.namespace.NamespaceService
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class NamespaceService extends java.lang.Object implements java.lang.AutoCloseableTheNamespaceServiceprovides resource ownership lookup as well as resource ownership claiming services for thePulsarService. ThePulsarServicerelies 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:
PulsarService
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNamespaceService.AddressType
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHEARTBEAT_NAMESPACE_FMTstatic java.lang.StringHEARTBEAT_NAMESPACE_FMT_V2static java.util.regex.PatternHEARTBEAT_NAMESPACE_PATTERNstatic java.util.regex.PatternHEARTBEAT_NAMESPACE_PATTERN_V2static java.lang.StringSLA_NAMESPACE_FMTstatic java.util.regex.PatternSLA_NAMESPACE_PATTERNstatic java.lang.StringSLA_NAMESPACE_PROPERTY
-
Constructor Summary
Constructors Constructor Description NamespaceService(PulsarService pulsar)Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddNamespaceBundleOwnershipListener(NamespaceBundleOwnershipListener... listeners)static java.lang.StringcheckHeartbeatNamespace(org.apache.pulsar.common.naming.ServiceUnitId ns)static java.lang.StringcheckHeartbeatNamespaceV2(org.apache.pulsar.common.naming.ServiceUnitId ns)java.util.concurrent.CompletableFuture<java.lang.Boolean>checkTopicExists(org.apache.pulsar.common.naming.TopicName topic)java.util.concurrent.CompletableFuture<java.lang.Boolean>checkTopicOwnership(org.apache.pulsar.common.naming.TopicName topicName)voidclose()protected java.util.concurrent.CompletableFuture<LookupResult>createLookupResult(java.lang.String candidateBroker, boolean authoritativeRedirect, java.lang.String advertisedListenerName)java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>>getAllPartitions(org.apache.pulsar.common.naming.NamespaceName namespaceName)java.util.concurrent.CompletableFuture<java.util.Optional<LookupResult>>getBrokerServiceUrlAsync(org.apache.pulsar.common.naming.TopicName topic, LookupOptions options)NamespaceBundlegetBundle(org.apache.pulsar.common.naming.TopicName topicName)java.util.concurrent.CompletableFuture<NamespaceBundle>getBundleAsync(org.apache.pulsar.common.naming.TopicName topic)intgetBundleCount(org.apache.pulsar.common.naming.NamespaceName namespace)java.util.Optional<NamespaceBundle>getBundleIfPresent(org.apache.pulsar.common.naming.TopicName topicName)java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>>getFullListOfTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName)static org.apache.pulsar.common.naming.NamespaceNamegetHeartbeatNamespace(java.lang.String host, org.apache.pulsar.broker.ServiceConfiguration config)static org.apache.pulsar.common.naming.NamespaceNamegetHeartbeatNamespaceV2(java.lang.String host, org.apache.pulsar.broker.ServiceConfiguration config)java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>>getListOfNonPersistentTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName)java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>>getListOfPersistentTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName)java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>>getListOfTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode mode)NamespaceBundleFactorygetNamespaceBundleFactory()org.apache.pulsar.client.impl.PulsarClientImplgetNamespaceClient(org.apache.pulsar.common.policies.data.ClusterDataImpl cluster)java.util.Map<java.lang.String,org.apache.pulsar.common.policies.data.NamespaceOwnershipStatus>getOwnedNameSpacesStatus()java.util.Set<NamespaceBundle>getOwnedServiceUnits()java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>>getOwnedTopicListForNamespaceBundle(NamespaceBundle bundle)java.util.Optional<NamespaceEphemeralData>getOwner(NamespaceBundle bundle)java.util.concurrent.CompletableFuture<java.util.Optional<NamespaceEphemeralData>>getOwnerAsync(NamespaceBundle bundle)OwnershipCachegetOwnershipCache()java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>>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 java.lang.StringgetSLAMonitorBrokerName(org.apache.pulsar.common.naming.ServiceUnitId ns)static org.apache.pulsar.common.naming.NamespaceNamegetSLAMonitorNamespace(java.lang.String host, org.apache.pulsar.broker.ServiceConfiguration config)intgetTotalServiceUnitsLoaded()java.util.Optional<java.net.URL>getWebServiceUrl(org.apache.pulsar.common.naming.ServiceUnitId suName, LookupOptions options)Return the URL of the broker who's owning a particular service unit.java.util.concurrent.CompletableFuture<java.util.Optional<java.net.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.voidinitialize()booleanisNamespaceBundleDisabled(NamespaceBundle bundle)java.util.concurrent.CompletableFuture<java.lang.Boolean>isNamespaceBundleOwned(NamespaceBundle bundle)booleanisServiceUnitActive(org.apache.pulsar.common.naming.TopicName topicName)java.util.concurrent.CompletableFuture<java.lang.Boolean>isServiceUnitActiveAsync(org.apache.pulsar.common.naming.TopicName topicName)booleanisServiceUnitOwned(org.apache.pulsar.common.naming.ServiceUnitId suName)java.util.concurrent.CompletableFuture<java.lang.Boolean>isServiceUnitOwnedAsync(org.apache.pulsar.common.naming.ServiceUnitId suName)static booleanisSystemServiceNamespace(java.lang.String namespace)protected voidonNamespaceBundleOwned(NamespaceBundle bundle)protected voidonNamespaceBundleUnload(NamespaceBundle bundle)voidregisterBootstrapNamespaces()Register all the bootstrap name spaces including the heartbeat namespace.booleanregisterNamespace(org.apache.pulsar.common.naming.NamespaceName nsname, boolean ensureOwned)Tried to registers a namespace to this instance.booleanregisterSLANamespace()voidremoveOwnedServiceUnit(NamespaceBundle nsBundle)java.util.concurrent.CompletableFuture<java.lang.Void>splitAndOwnBundle(NamespaceBundle bundle, boolean unload, NamespaceBundleSplitAlgorithm splitAlgorithm)1.java.util.concurrent.CompletableFuture<java.lang.Void>unloadNamespaceBundle(NamespaceBundle bundle)java.util.concurrent.CompletableFuture<java.lang.Void>unloadNamespaceBundle(NamespaceBundle bundle, long timeout, java.util.concurrent.TimeUnit timeoutUnit)voidunloadSLANamespace()
-
-
-
Field Detail
-
SLA_NAMESPACE_PROPERTY
public static final java.lang.String SLA_NAMESPACE_PROPERTY
- See Also:
- Constant Field Values
-
HEARTBEAT_NAMESPACE_PATTERN
public static final java.util.regex.Pattern HEARTBEAT_NAMESPACE_PATTERN
-
HEARTBEAT_NAMESPACE_PATTERN_V2
public static final java.util.regex.Pattern HEARTBEAT_NAMESPACE_PATTERN_V2
-
SLA_NAMESPACE_PATTERN
public static final java.util.regex.Pattern SLA_NAMESPACE_PATTERN
-
HEARTBEAT_NAMESPACE_FMT
public static final java.lang.String HEARTBEAT_NAMESPACE_FMT
- See Also:
- Constant Field Values
-
HEARTBEAT_NAMESPACE_FMT_V2
public static final java.lang.String HEARTBEAT_NAMESPACE_FMT_V2
- See Also:
- Constant Field Values
-
SLA_NAMESPACE_FMT
public static final java.lang.String SLA_NAMESPACE_FMT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NamespaceService
public NamespaceService(PulsarService pulsar)
Default constructor.- Throws:
org.apache.pulsar.broker.PulsarServerException
-
-
Method Detail
-
initialize
public void initialize()
-
getBrokerServiceUrlAsync
public java.util.concurrent.CompletableFuture<java.util.Optional<LookupResult>> getBrokerServiceUrlAsync(org.apache.pulsar.common.naming.TopicName topic, LookupOptions options)
-
getBundleAsync
public java.util.concurrent.CompletableFuture<NamespaceBundle> getBundleAsync(org.apache.pulsar.common.naming.TopicName topic)
-
getBundleIfPresent
public java.util.Optional<NamespaceBundle> getBundleIfPresent(org.apache.pulsar.common.naming.TopicName topicName)
-
getBundle
public NamespaceBundle getBundle(org.apache.pulsar.common.naming.TopicName topicName)
-
getBundleCount
public int getBundleCount(org.apache.pulsar.common.naming.NamespaceName namespace) throws java.lang.Exception- Throws:
java.lang.Exception
-
getWebServiceUrlAsync
public java.util.concurrent.CompletableFuture<java.util.Optional<java.net.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 java.util.Optional<java.net.URL> getWebServiceUrl(org.apache.pulsar.common.naming.ServiceUnitId suName, LookupOptions options) throws java.lang.ExceptionReturn the URL of the broker who's owning a particular service unit. If the service unit is not owned, return an empty optional- Throws:
java.lang.Exception
-
registerBootstrapNamespaces
public void registerBootstrapNamespaces() throws org.apache.pulsar.broker.PulsarServerExceptionRegister all the bootstrap name spaces including the heartbeat namespace.- Throws:
org.apache.pulsar.broker.PulsarServerException
-
registerNamespace
public boolean registerNamespace(org.apache.pulsar.common.naming.NamespaceName nsname, boolean ensureOwned) throws org.apache.pulsar.broker.PulsarServerExceptionTried to registers a namespace to this instance.- Parameters:
nsname-ensureOwned-- Returns:
- Throws:
org.apache.pulsar.broker.PulsarServerExceptionjava.lang.Exception
-
createLookupResult
protected java.util.concurrent.CompletableFuture<LookupResult> createLookupResult(java.lang.String candidateBroker, boolean authoritativeRedirect, java.lang.String advertisedListenerName)
-
unloadNamespaceBundle
public java.util.concurrent.CompletableFuture<java.lang.Void> unloadNamespaceBundle(NamespaceBundle bundle)
-
unloadNamespaceBundle
public java.util.concurrent.CompletableFuture<java.lang.Void> unloadNamespaceBundle(NamespaceBundle bundle, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
-
isNamespaceBundleOwned
public java.util.concurrent.CompletableFuture<java.lang.Boolean> isNamespaceBundleOwned(NamespaceBundle bundle)
-
getOwnedNameSpacesStatus
public java.util.Map<java.lang.String,org.apache.pulsar.common.policies.data.NamespaceOwnershipStatus> getOwnedNameSpacesStatus() throws java.lang.Exception- Throws:
java.lang.Exception
-
isNamespaceBundleDisabled
public boolean isNamespaceBundleDisabled(NamespaceBundle bundle) throws java.lang.Exception
- Throws:
java.lang.Exception
-
splitAndOwnBundle
public java.util.concurrent.CompletableFuture<java.lang.Void> splitAndOwnBundle(NamespaceBundle bundle, boolean unload, NamespaceBundleSplitAlgorithm splitAlgorithm)
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-- Returns:
- Throws:
java.lang.Exception
-
getOwnershipCache
public OwnershipCache getOwnershipCache()
-
getTotalServiceUnitsLoaded
public int getTotalServiceUnitsLoaded()
-
getOwnedServiceUnits
public java.util.Set<NamespaceBundle> getOwnedServiceUnits()
-
isServiceUnitOwned
public boolean isServiceUnitOwned(org.apache.pulsar.common.naming.ServiceUnitId suName) throws java.lang.Exception- Throws:
java.lang.Exception
-
isServiceUnitOwnedAsync
public java.util.concurrent.CompletableFuture<java.lang.Boolean> isServiceUnitOwnedAsync(org.apache.pulsar.common.naming.ServiceUnitId suName)
-
isServiceUnitActive
public boolean isServiceUnitActive(org.apache.pulsar.common.naming.TopicName topicName)
-
isServiceUnitActiveAsync
public java.util.concurrent.CompletableFuture<java.lang.Boolean> isServiceUnitActiveAsync(org.apache.pulsar.common.naming.TopicName topicName)
-
checkTopicOwnership
public java.util.concurrent.CompletableFuture<java.lang.Boolean> checkTopicOwnership(org.apache.pulsar.common.naming.TopicName topicName)
-
removeOwnedServiceUnit
public void removeOwnedServiceUnit(NamespaceBundle nsBundle) throws java.lang.Exception
- Throws:
java.lang.Exception
-
onNamespaceBundleOwned
protected void onNamespaceBundleOwned(NamespaceBundle bundle)
-
onNamespaceBundleUnload
protected void onNamespaceBundleUnload(NamespaceBundle bundle)
-
addNamespaceBundleOwnershipListener
public void addNamespaceBundleOwnershipListener(NamespaceBundleOwnershipListener... listeners)
-
getNamespaceBundleFactory
public NamespaceBundleFactory getNamespaceBundleFactory()
-
getServiceUnitId
public org.apache.pulsar.common.naming.ServiceUnitId getServiceUnitId(org.apache.pulsar.common.naming.TopicName topicName) throws java.lang.Exception- Throws:
java.lang.Exception
-
getFullListOfTopics
public java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> getFullListOfTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName)
-
getOwnedTopicListForNamespaceBundle
public java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> getOwnedTopicListForNamespaceBundle(NamespaceBundle bundle)
-
checkTopicExists
public java.util.concurrent.CompletableFuture<java.lang.Boolean> checkTopicExists(org.apache.pulsar.common.naming.TopicName topic)
-
getListOfTopics
public java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> getListOfTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode mode)
-
getAllPartitions
public java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> getAllPartitions(org.apache.pulsar.common.naming.NamespaceName namespaceName)
-
getPartitions
public java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> getPartitions(org.apache.pulsar.common.naming.NamespaceName namespaceName, org.apache.pulsar.common.naming.TopicDomain topicDomain)
-
getListOfPersistentTopics
public java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> getListOfPersistentTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName)
-
getListOfNonPersistentTopics
public java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> getListOfNonPersistentTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName)
-
getNamespaceClient
public org.apache.pulsar.client.impl.PulsarClientImpl getNamespaceClient(org.apache.pulsar.common.policies.data.ClusterDataImpl cluster)
-
getOwner
public java.util.Optional<NamespaceEphemeralData> getOwner(NamespaceBundle bundle) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getOwnerAsync
public java.util.concurrent.CompletableFuture<java.util.Optional<NamespaceEphemeralData>> getOwnerAsync(NamespaceBundle bundle)
-
unloadSLANamespace
public void unloadSLANamespace() throws java.lang.Exception- Throws:
java.lang.Exception
-
getHeartbeatNamespace
public static org.apache.pulsar.common.naming.NamespaceName getHeartbeatNamespace(java.lang.String host, org.apache.pulsar.broker.ServiceConfiguration config)
-
getHeartbeatNamespaceV2
public static org.apache.pulsar.common.naming.NamespaceName getHeartbeatNamespaceV2(java.lang.String host, org.apache.pulsar.broker.ServiceConfiguration config)
-
getSLAMonitorNamespace
public static org.apache.pulsar.common.naming.NamespaceName getSLAMonitorNamespace(java.lang.String host, org.apache.pulsar.broker.ServiceConfiguration config)
-
checkHeartbeatNamespace
public static java.lang.String checkHeartbeatNamespace(org.apache.pulsar.common.naming.ServiceUnitId ns)
-
checkHeartbeatNamespaceV2
public static java.lang.String checkHeartbeatNamespaceV2(org.apache.pulsar.common.naming.ServiceUnitId ns)
-
getSLAMonitorBrokerName
public static java.lang.String getSLAMonitorBrokerName(org.apache.pulsar.common.naming.ServiceUnitId ns)
-
isSystemServiceNamespace
public static boolean isSystemServiceNamespace(java.lang.String namespace)
-
registerSLANamespace
public boolean registerSLANamespace() throws org.apache.pulsar.broker.PulsarServerException- Throws:
org.apache.pulsar.broker.PulsarServerException
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
-