Skip to content

Commit 6d81292

Browse files
BewareMyPowerlhotari
authored andcommitted
[fix][meta] Metadata cache refresh might not take effect (#25246)
(cherry picked from commit 24eba10)
1 parent 9343837 commit 6d81292

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

pulsar-metadata/src/main/java/org/apache/pulsar/metadata/cache/impl/MetadataCacheImpl.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,6 @@ private CompletableFuture<Optional<CacheGetResult<T>>> readValueFromStore(String
153153
return FutureUtils.value(Optional.<CacheGetResult<T>>empty());
154154
}
155155
final var res = optRes.get();
156-
final var cachedFuture = objCache.getIfPresent(path);
157-
if (cachedFuture != null && cachedFuture != future) {
158-
if (log.isDebugEnabled()) {
159-
log.debug("A new read on key {} is in progress or completed, ignore this one", path);
160-
}
161-
return cachedFuture;
162-
}
163156
try {
164157
T obj = serde.deserialize(path, res.getValue(), res.getStat());
165158
if (log.isDebugEnabled()) {

pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.io.IOException;
3434
import java.lang.reflect.Field;
3535
import java.nio.charset.StandardCharsets;
36+
import java.time.Duration;
3637
import java.util.ArrayList;
3738
import java.util.EnumSet;
3839
import java.util.List;
@@ -69,6 +70,7 @@
6970
import org.apache.pulsar.metadata.api.Stat;
7071
import org.apache.pulsar.metadata.api.extended.CreateOption;
7172
import org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl;
73+
import org.apache.pulsar.metadata.impl.LocalMemoryMetadataStore;
7274
import org.awaitility.Awaitility;
7375
import org.mockito.stubbing.Answer;
7476
import org.testng.annotations.Test;
@@ -739,4 +741,18 @@ public void testNoBackoffMetadataCacheConfig() {
739741
assertTrue(backoff.isMandatoryStopMade());
740742
assertEquals(backoff.getFirstBackoffTimeInMillis(), 0);
741743
}
744+
745+
@Test
746+
public void testRefreshRace() throws Exception {
747+
@Cleanup final var store = new LocalMemoryMetadataStore("memory:local", MetadataStoreConfig.builder().build());
748+
final var cache = store.getMetadataCache(String.class);
749+
for (int i = 0; i < 500; i++) {
750+
final var key = "/key" + i;
751+
assertTrue(cache.get(key).get().isEmpty());
752+
753+
store.put(key, "\"value\"".getBytes(StandardCharsets.UTF_8), Optional.empty()).get();
754+
Awaitility.await().pollInterval(Duration.ofMillis(1)).atMost(Duration.ofSeconds(3)).untilAsserted(() ->
755+
assertTrue(cache.get(key).get().isPresent(), "Failed at key " + key));
756+
}
757+
}
742758
}

0 commit comments

Comments
 (0)