Class OwnershipCache
- java.lang.Object
-
- org.apache.pulsar.broker.namespace.OwnershipCache
-
public class OwnershipCache extends java.lang.ObjectThis 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 Summary
Constructors Constructor Description OwnershipCache(PulsarService pulsar, NamespaceBundleFactory bundleFactory, NamespaceService namespaceService)Constructor ofOwnershipCache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Boolean>checkOwnershipAsync(NamespaceBundle bundle)Check whether this broker owns given namespace bundle.java.util.concurrent.CompletableFuture<java.lang.Void>disableOwnership(NamespaceBundle bundle)Disable bundle in local cache and on zk.java.util.Map<NamespaceBundle,org.apache.pulsar.metadata.api.coordination.ResourceLock<NamespaceEphemeralData>>getLocallyAcquiredLocks()OwnedBundlegetOwnedBundle(NamespaceBundle bundle)Return theOwnedBundleinstance from the local cache.java.util.Optional<java.util.concurrent.CompletableFuture<OwnedBundle>>getOwnedBundleAsync(NamespaceBundle bundle)java.util.Map<NamespaceBundle,OwnedBundle>getOwnedBundles()Method to access the map of allServiceUnitobjects owned by the local broker.java.util.concurrent.CompletableFuture<java.util.Optional<NamespaceEphemeralData>>getOwnerAsync(NamespaceBundle suName)Method to get the current owner of theServiceUnit.voidinvalidateLocalOwnerCache()booleanisNamespaceBundleOwned(NamespaceBundle bundle)Checked whether a particular bundle is currently owned by this broker.booleanrefreshSelfOwnerInfo()java.util.concurrent.CompletableFuture<java.lang.Void>removeOwnership(NamespaceBundle bundle)Method to remove the ownership of local broker on theNamespaceBundle, if owned.java.util.concurrent.CompletableFuture<java.lang.Void>removeOwnership(NamespaceBundles bundles)Method to remove ownership of all owned bundles.java.util.concurrent.CompletableFuture<NamespaceEphemeralData>tryAcquiringOwnership(NamespaceBundle bundle)Method to get the current owner of theServiceUnitor set the local broker as the owner if absent.java.util.concurrent.CompletableFuture<java.lang.Void>updateBundleState(NamespaceBundle bundle, boolean isActive)Update bundle state in a local cache.
-
-
-
Constructor Detail
-
OwnershipCache
public OwnershipCache(PulsarService pulsar, NamespaceBundleFactory bundleFactory, NamespaceService namespaceService)
Constructor ofOwnershipCache. the local broker URL that will be set as owner for theServiceUnit
-
-
Method Detail
-
checkOwnershipAsync
public java.util.concurrent.CompletableFuture<java.lang.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
public java.util.concurrent.CompletableFuture<java.util.Optional<NamespaceEphemeralData>> getOwnerAsync(NamespaceBundle suName)
Method to get the current owner of theServiceUnit.- Parameters:
suName- name of theServiceUnit- Returns:
- The ephemeral node data showing the current ownership info in
ZooKeeper - Throws:
java.lang.Exception- throws exception if no ownership info is found
-
tryAcquiringOwnership
public java.util.concurrent.CompletableFuture<NamespaceEphemeralData> tryAcquiringOwnership(NamespaceBundle bundle) throws java.lang.Exception
Method to get the current owner of theServiceUnitor set the local broker as the owner if absent.- Parameters:
bundle- theNamespaceBundle- Returns:
- The ephemeral node data showing the current ownership info in
ZooKeeper - Throws:
java.lang.Exception
-
removeOwnership
public java.util.concurrent.CompletableFuture<java.lang.Void> removeOwnership(NamespaceBundle bundle)
Method to remove the ownership of local broker on theNamespaceBundle, if owned.
-
removeOwnership
public java.util.concurrent.CompletableFuture<java.lang.Void> removeOwnership(NamespaceBundles bundles)
Method to remove ownership of all owned bundles.- Parameters:
bundles-NamespaceBundlesto remove from ownership cache
-
getOwnedBundles
public java.util.Map<NamespaceBundle,OwnedBundle> getOwnedBundles()
Method to access the map of allServiceUnitobjects owned by the local broker.- Returns:
- a map of owned
ServiceUnitobjects
-
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 theOwnedBundleinstance from the local cache. Does not block.- Parameters:
bundle-- Returns:
-
getOwnedBundleAsync
public java.util.Optional<java.util.concurrent.CompletableFuture<OwnedBundle>> getOwnedBundleAsync(NamespaceBundle bundle)
-
disableOwnership
public java.util.concurrent.CompletableFuture<java.lang.Void> disableOwnership(NamespaceBundle bundle)
Disable bundle in local cache and on zk.- Parameters:
bundle-- Throws:
java.lang.Exception
-
updateBundleState
public java.util.concurrent.CompletableFuture<java.lang.Void> updateBundleState(NamespaceBundle bundle, boolean isActive)
Update bundle state in a local cache.- Parameters:
bundle-- Throws:
java.lang.Exception
-
invalidateLocalOwnerCache
public void invalidateLocalOwnerCache()
-
getLocallyAcquiredLocks
public java.util.Map<NamespaceBundle,org.apache.pulsar.metadata.api.coordination.ResourceLock<NamespaceEphemeralData>> getLocallyAcquiredLocks()
-
refreshSelfOwnerInfo
public boolean refreshSelfOwnerInfo()
-
-