Class NamespaceService

java.lang.Object
org.apache.pulsar.broker.namespace.NamespaceService
All Implemented Interfaces:
AutoCloseable

public class NamespaceService extends Object implements 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 Details

    • SLA_NAMESPACE_PROPERTY

      public static final String SLA_NAMESPACE_PROPERTY
      See Also:
    • HEARTBEAT_NAMESPACE_PATTERN

      public static final Pattern HEARTBEAT_NAMESPACE_PATTERN
    • HEARTBEAT_NAMESPACE_PATTERN_V2

      public static final Pattern HEARTBEAT_NAMESPACE_PATTERN_V2
    • SLA_NAMESPACE_PATTERN

      public static final Pattern SLA_NAMESPACE_PATTERN
    • HEARTBEAT_NAMESPACE_FMT

      public static final String HEARTBEAT_NAMESPACE_FMT
      See Also:
    • HEARTBEAT_NAMESPACE_FMT_V2

      public static final String HEARTBEAT_NAMESPACE_FMT_V2
      See Also:
    • SLA_NAMESPACE_FMT

      public static final String SLA_NAMESPACE_FMT
      See Also:
  • Constructor Details

    • NamespaceService

      public NamespaceService(PulsarService pulsar)
      Default constructor.
      Throws:
      org.apache.pulsar.broker.PulsarServerException
  • 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

      public NamespaceBundle getBundle(org.apache.pulsar.common.naming.TopicName topicName)
    • getBundleCount

      public int getBundleCount(org.apache.pulsar.common.naming.NamespaceName namespace) throws Exception
      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

      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
      Exception
    • createLookupResult

      protected CompletableFuture<LookupResult> createLookupResult(String candidateBroker, boolean authoritativeRedirect, String advertisedListenerName)
    • unloadNamespaceBundle

      public CompletableFuture<Void> unloadNamespaceBundle(NamespaceBundle bundle)
    • unloadNamespaceBundle

      public CompletableFuture<Void> unloadNamespaceBundle(NamespaceBundle bundle, long timeout, TimeUnit timeoutUnit)
    • unloadNamespaceBundle

      public CompletableFuture<Void> unloadNamespaceBundle(NamespaceBundle bundle, long timeout, TimeUnit timeoutUnit, boolean closeWithoutWaitingClientDisconnect)
    • isNamespaceBundleOwned

      public CompletableFuture<Boolean> isNamespaceBundleOwned(NamespaceBundle bundle)
    • getOwnedNameSpacesStatusAsync

      public CompletableFuture<Map<String,org.apache.pulsar.common.policies.data.NamespaceOwnershipStatus>> getOwnedNameSpacesStatusAsync()
    • isNamespaceBundleDisabled

      public boolean isNamespaceBundleDisabled(NamespaceBundle bundle) throws Exception
      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 -
      Returns:
      Throws:
      Exception
    • getOwnershipCache

      public OwnershipCache getOwnershipCache()
    • getTotalServiceUnitsLoaded

      public int getTotalServiceUnitsLoaded()
    • getOwnedServiceUnits

      public Set<NamespaceBundle> 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

      public boolean isServiceUnitActive(org.apache.pulsar.common.naming.TopicName topicName)
    • 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

      public CompletableFuture<Void> removeOwnedServiceUnitAsync(NamespaceBundle nsBundle)
    • 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 Exception
      Throws:
      Exception
    • getFullListOfTopics

      public CompletableFuture<List<String>> getFullListOfTopics(org.apache.pulsar.common.naming.NamespaceName namespaceName)
    • getOwnedTopicListForNamespaceBundle

      public CompletableFuture<List<String>> getOwnedTopicListForNamespaceBundle(NamespaceBundle bundle)
    • checkTopicExists

      public CompletableFuture<Boolean> checkTopicExists(org.apache.pulsar.common.naming.TopicName topic)
    • getListOfTopics

      public CompletableFuture<List<String>> getListOfTopics(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)
    • getListOfNonPersistentTopics

      public CompletableFuture<List<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 Optional<NamespaceEphemeralData> getOwner(NamespaceBundle bundle) throws Exception
      Throws:
      Exception
    • getOwnerAsync

    • unloadSLANamespace

      public void unloadSLANamespace() throws Exception
      Throws:
      Exception
    • getHeartbeatNamespace

      public static org.apache.pulsar.common.naming.NamespaceName getHeartbeatNamespace(String host, org.apache.pulsar.broker.ServiceConfiguration config)
    • getHeartbeatNamespaceV2

      public static org.apache.pulsar.common.naming.NamespaceName getHeartbeatNamespaceV2(String host, org.apache.pulsar.broker.ServiceConfiguration config)
    • getSLAMonitorNamespace

      public static org.apache.pulsar.common.naming.NamespaceName getSLAMonitorNamespace(String host, org.apache.pulsar.broker.ServiceConfiguration config)
    • checkHeartbeatNamespace

      public static String checkHeartbeatNamespace(org.apache.pulsar.common.naming.ServiceUnitId ns)
    • checkHeartbeatNamespaceV2

      public static String checkHeartbeatNamespaceV2(org.apache.pulsar.common.naming.ServiceUnitId ns)
    • getSLAMonitorBrokerName

      public static String getSLAMonitorBrokerName(org.apache.pulsar.common.naming.ServiceUnitId ns)
    • isSystemServiceNamespace

      public static boolean isSystemServiceNamespace(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 AutoCloseable