Class OwnershipCache

java.lang.Object
org.apache.pulsar.broker.namespace.OwnershipCache

public class OwnershipCache extends Object
This class provides a cache service for all the service unit ownership among the brokers. It provide a cache service as well as MetadataStore read/write functions for a) lookup of a service unit ownership to a broker; b) take ownership of a service unit by the local broker
  • Constructor Details

  • Method Details

    • checkOwnershipAsync

      public CompletableFuture<Boolean> checkOwnershipAsync(NamespaceBundle bundle)
      Check whether this broker owns given namespace bundle.
      Parameters:
      bundle - namespace bundle
      Returns:
      future that will complete with check result
    • getOwnerAsync

      Method to get the current owner of the ServiceUnit.
      Parameters:
      suName - name of the ServiceUnit
      Returns:
      The ephemeral node data showing the current ownership info in ZooKeeper
      Throws:
      Exception - throws exception if no ownership info is found
    • tryAcquiringOwnership

      public CompletableFuture<NamespaceEphemeralData> tryAcquiringOwnership(NamespaceBundle bundle) throws Exception
      Method to get the current owner of the NamespaceBundle or set the local broker as the owner if absent.
      Parameters:
      bundle - the NamespaceBundle
      Returns:
      The ephemeral node data showing the current ownership info in ZooKeeper
      Throws:
      Exception
    • removeOwnership

      public CompletableFuture<Void> removeOwnership(NamespaceBundle bundle)
      Method to remove the ownership of local broker on the NamespaceBundle, if owned.
    • removeOwnership

      public CompletableFuture<Void> removeOwnership(NamespaceBundles bundles)
      Method to remove ownership of all owned bundles.
      Parameters:
      bundles - NamespaceBundles to remove from ownership cache
    • getOwnedBundles

      public Map<NamespaceBundle,OwnedBundle> getOwnedBundles()
      Method to access the map of all ServiceUnit objects owned by the local broker.
      Returns:
      a map of owned ServiceUnit objects
    • getOwnedBundlesAsync

      public Map<NamespaceBundle,CompletableFuture<OwnedBundle>> getOwnedBundlesAsync()
    • isNamespaceBundleOwned

      public boolean isNamespaceBundleOwned(NamespaceBundle bundle)
      Checked whether a particular bundle is currently owned by this broker.
      Parameters:
      bundle -
      Returns:
    • getOwnedBundle

      public OwnedBundle getOwnedBundle(NamespaceBundle bundle)
      Return the OwnedBundle instance from the local cache. Does not block.
      Parameters:
      bundle -
      Returns:
    • getOwnedBundleAsync

      public Optional<CompletableFuture<OwnedBundle>> getOwnedBundleAsync(NamespaceBundle bundle)
    • disableOwnership

      public CompletableFuture<Void> disableOwnership(NamespaceBundle bundle)
      Disable bundle in local cache and on zk.
      Parameters:
      bundle -
      Throws:
      Exception
    • updateBundleState

      public CompletableFuture<Void> updateBundleState(NamespaceBundle bundle, boolean isActive)
      Update bundle state in a local cache.
      Parameters:
      bundle -
      Throws:
      Exception
    • invalidateLocalOwnerCache

      public void invalidateLocalOwnerCache()
    • invalidateLocalOwnerCache

      public void invalidateLocalOwnerCache(NamespaceBundle namespaceBundle)
    • getLocallyAcquiredLocks

      public Map<NamespaceBundle,org.apache.pulsar.metadata.api.coordination.ResourceLock<NamespaceEphemeralData>> getLocallyAcquiredLocks()
    • refreshSelfOwnerInfo

      public boolean refreshSelfOwnerInfo()