You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by te...@apache.org on 2022/10/27 06:43:39 UTC
[pulsar] branch master updated: [improve][broker] Remove locallyAcquiredLock when removeOwnership (#18197)
This is an automated email from the ASF dual-hosted git repository.
technoboy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new b061c6ac583 [improve][broker] Remove locallyAcquiredLock when removeOwnership (#18197)
b061c6ac583 is described below
commit b061c6ac5833c21e483368febebd0d30679a35e1
Author: Lei Zhiyuan <le...@gmail.com>
AuthorDate: Thu Oct 27 14:43:32 2022 +0800
[improve][broker] Remove locallyAcquiredLock when removeOwnership (#18197)
---
.../java/org/apache/pulsar/broker/namespace/OwnershipCache.java | 9 ++++++++-
.../org/apache/pulsar/broker/namespace/OwnershipCacheTest.java | 1 +
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java
index 1ca9a049455..a9dd44d4589 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java
@@ -21,6 +21,7 @@ package org.apache.pulsar.broker.namespace;
import com.github.benmanes.caffeine.cache.AsyncCacheLoader;
import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
import com.github.benmanes.caffeine.cache.Caffeine;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.ArrayList;
import java.util.List;
@@ -207,7 +208,7 @@ public class OwnershipCache {
*
*/
public CompletableFuture<Void> removeOwnership(NamespaceBundle bundle) {
- ResourceLock<NamespaceEphemeralData> lock = locallyAcquiredLocks.get(bundle);
+ ResourceLock<NamespaceEphemeralData> lock = locallyAcquiredLocks.remove(bundle);
if (lock == null) {
// We don't own the specified bundle anymore
return CompletableFuture.completedFuture(null);
@@ -328,6 +329,12 @@ public class OwnershipCache {
this.ownedBundlesCache.synchronous().invalidate(namespaceBundle);
}
+ @VisibleForTesting
+ public Map<NamespaceBundle, ResourceLock<NamespaceEphemeralData>> getLocallyAcquiredLocks() {
+ return locallyAcquiredLocks;
+ }
+
+
public synchronized boolean refreshSelfOwnerInfo() {
this.selfOwnerInfo = new NamespaceEphemeralData(pulsar.getBrokerServiceUrl(),
pulsar.getBrokerServiceUrlTls(), pulsar.getSafeWebServiceAddress(),
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/namespace/OwnershipCacheTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/namespace/OwnershipCacheTest.java
index b5092784103..8b2cb96e267 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/namespace/OwnershipCacheTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/namespace/OwnershipCacheTest.java
@@ -367,6 +367,7 @@ public class OwnershipCacheTest {
Awaitility.await().untilAsserted(() -> {
assertTrue(cache.getOwnedBundles().isEmpty());
assertFalse(store.exists(ServiceUnitUtils.path(bundle)).join());
+ assertNull(cache.getLocallyAcquiredLocks().get(bundle));
});
}