This is an automated email from the ASF dual-hosted git repository.
bogong pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.9 by this push:
new 2bbeace8f99 fix-12894 (#12896)
2bbeace8f99 is described below
commit 2bbeace8f99abe8e16c4d2db4f61ea3994a1f359
Author: JiangHaiting <[email protected]>
AuthorDate: Wed Dec 1 05:09:08 2021 +0800
fix-12894 (#12896)
Co-authored-by: Jiang Haiting <[email protected]>
(cherry picked from commit 2b939b7a8b0bf9ed2fd31353067033d049ea5350)
---
.../org/apache/pulsar/metadata/cache/impl/MetadataCacheImpl.java | 7 +++++--
.../test/java/org/apache/pulsar/metadata/MetadataCacheTest.java | 3 ++-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git
a/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/cache/impl/MetadataCacheImpl.java
b/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/cache/impl/MetadataCacheImpl.java
index 0ab56bb1bc1..fccbe2ca38a 100644
---
a/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/cache/impl/MetadataCacheImpl.java
+++
b/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/cache/impl/MetadataCacheImpl.java
@@ -261,8 +261,11 @@ public class MetadataCacheImpl<T> implements
MetadataCache<T>, Consumer<Notifica
@Override
public void refresh(String path) {
- objCache.synchronous().invalidate(path);
- objCache.synchronous().refresh(path);
+ // Refresh object of path if only it is cached before.
+ if (objCache.getIfPresent(path) != null) {
+ objCache.synchronous().invalidate(path);
+ objCache.synchronous().refresh(path);
+ }
}
@VisibleForTesting
diff --git
a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java
b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java
index e7680296563..a4ba88852b0 100644
---
a/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java
+++
b/pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java
@@ -325,13 +325,14 @@ public class MetadataCacheTest extends
BaseMetadataStoreTest {
}
@Test(dataProvider = "impl")
- public void insertionOutsideCacheWithGenericType(String provider,
Supplier<String> urlSupplier) throws Exception {
+ public void updateOutsideCacheWithGenericType(String provider,
Supplier<String> urlSupplier) throws Exception {
@Cleanup
MetadataStore store = MetadataStoreFactory.create(urlSupplier.get(),
MetadataStoreConfig.builder().build());
MetadataCache<Map<String, String>> objCache =
store.getMetadataCache(new TypeReference<Map<String, String>>() {
});
String key1 = newKey();
+ objCache.get(key1);
Map<String, String> v = new TreeMap<>();
v.put("a", "1");