Class NamespaceService

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class NamespaceService
    extends java.lang.Object
    implements java.lang.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:
    PulsarService
    • 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.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:
        java.lang.Exception
      • registerBootstrapNamespaces

        public void registerBootstrapNamespaces()
                                         throws org.apache.pulsar.broker.PulsarServerException
        Register 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.PulsarServerException
        Tried to registers a namespace to this instance.
        Parameters:
        nsname -
        ensureOwned -
        Returns:
        Throws:
        org.apache.pulsar.broker.PulsarServerException
        java.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)
      • unloadNamespaceBundle

        public java.util.concurrent.CompletableFuture<java.lang.Void> unloadNamespaceBundle​(NamespaceBundle bundle,
                                                                                            long timeout,
                                                                                            java.util.concurrent.TimeUnit timeoutUnit,
                                                                                            boolean closeWithoutWaitingClientDisconnect)
      • 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
      • 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)
      • 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)
      • 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)
      • isHeartbeatNamespace

        public static boolean isHeartbeatNamespace​(org.apache.pulsar.common.naming.ServiceUnitId ns)
      • registerSLANamespace

        public boolean registerSLANamespace()
                                     throws org.apache.pulsar.broker.PulsarServerException
        Throws:
        org.apache.pulsar.broker.PulsarServerException
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable