You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xi...@apache.org on 2022/12/14 02:32:43 UTC
[pulsar] branch branch-2.10 updated: [improve][broker] Remove locallyAcquiredLock when removeOwnership (#18197)
This is an automated email from the ASF dual-hosted git repository.
xiangying pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.10 by this push:
new 5e4ce5113c4 [improve][broker] Remove locallyAcquiredLock when removeOwnership (#18197)
5e4ce5113c4 is described below
commit 5e4ce5113c4605f89bd39ce1bc92d5396e94c54f
Author: Lei Zhiyuan <le...@gmail.com>
AuthorDate: Thu Oct 27 14:43:32 2022 +0800
[improve][broker] Remove locallyAcquiredLock when removeOwnership (#18197)
(cherry picked from commit b061c6ac5833c21e483368febebd0d30679a35e1)
---
.../java/org/apache/pulsar/broker/namespace/OwnershipCache.java | 8 +++++++-
.../org/apache/pulsar/broker/namespace/OwnershipCacheTest.java | 1 +
2 files changed, 8 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 663e8569d0e..861dbdfdbce 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
@@ -22,6 +22,7 @@ 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.collect.Lists;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.List;
import java.util.Map;
@@ -212,7 +213,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);
@@ -325,6 +326,11 @@ public class OwnershipCache {
this.ownedBundlesCache.synchronous().invalidateAll();
}
+ @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 dde25fa2eed..088c427eb44 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
@@ -366,6 +366,7 @@ public class OwnershipCacheTest {
Awaitility.await().untilAsserted(() -> {
assertTrue(cache.getOwnedBundles().isEmpty());
assertFalse(store.exists(ServiceUnitUtils.path(bundle)).join());
+ assertNull(cache.getLocallyAcquiredLocks().get(bundle));
});
}