Class OwnershipCache
java.lang.Object
org.apache.pulsar.broker.namespace.OwnershipCache
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 Summary
ConstructorsConstructorDescriptionOwnershipCache(PulsarService pulsar, NamespaceBundleFactory bundleFactory, NamespaceService namespaceService) Constructor ofOwnershipCache. -
Method Summary
Modifier and TypeMethodDescriptioncheckOwnershipAsync(NamespaceBundle bundle) Check whether this broker owns given namespace bundle.disableOwnership(NamespaceBundle bundle) Disable bundle in local cache and on zk.Map<NamespaceBundle,org.apache.pulsar.metadata.api.coordination.ResourceLock<NamespaceEphemeralData>> getOwnedBundle(NamespaceBundle bundle) Return theOwnedBundleinstance from the local cache.getOwnedBundleAsync(NamespaceBundle bundle) Method to access the map of allServiceUnitobjects owned by the local broker.getOwnerAsync(NamespaceBundle suName) Method to get the current owner of theServiceUnit.voidvoidinvalidateLocalOwnerCache(NamespaceBundle namespaceBundle) booleanChecked whether a particular bundle is currently owned by this broker.booleanremoveOwnership(NamespaceBundle bundle) Method to remove the ownership of local broker on theNamespaceBundle, if owned.removeOwnership(NamespaceBundles bundles) Method to remove ownership of all owned bundles.tryAcquiringOwnership(NamespaceBundle bundle) Method to get the current owner of theNamespaceBundleor set the local broker as the owner if absent.updateBundleState(NamespaceBundle bundle, boolean isActive) Update bundle state in a local cache.
-
Constructor Details
-
OwnershipCache
public OwnershipCache(PulsarService pulsar, NamespaceBundleFactory bundleFactory, NamespaceService namespaceService) Constructor ofOwnershipCache. the local broker URL that will be set as owner for theServiceUnit
-
-
Method Details
-
checkOwnershipAsync
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 theServiceUnit.- Parameters:
suName- name of theServiceUnit- 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 theNamespaceBundleor 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:
Exception
-
removeOwnership
Method to remove the ownership of local broker on theNamespaceBundle, if owned. -
removeOwnership
Method to remove ownership of all owned bundles.- Parameters:
bundles-NamespaceBundlesto remove from ownership cache
-
getOwnedBundles
Method to access the map of allServiceUnitobjects owned by the local broker.- Returns:
- a map of owned
ServiceUnitobjects
-
getOwnedBundlesAsync
-
isNamespaceBundleOwned
Checked whether a particular bundle is currently owned by this broker.- Parameters:
bundle-- Returns:
-
getOwnedBundle
Return theOwnedBundleinstance from the local cache. Does not block.- Parameters:
bundle-- Returns:
-
getOwnedBundleAsync
-
disableOwnership
Disable bundle in local cache and on zk.- Parameters:
bundle-- Throws:
Exception
-
updateBundleState
Update bundle state in a local cache.- Parameters:
bundle-- Throws:
Exception
-
invalidateLocalOwnerCache
public void invalidateLocalOwnerCache() -
invalidateLocalOwnerCache
-
getLocallyAcquiredLocks
public Map<NamespaceBundle,org.apache.pulsar.metadata.api.coordination.ResourceLock<NamespaceEphemeralData>> getLocallyAcquiredLocks() -
refreshSelfOwnerInfo
public boolean refreshSelfOwnerInfo()
-