[fix][meta] Metadata cache refresh might not take effect#25246
Open
BewareMyPower wants to merge 2 commits intoapache:masterfrom
Open
[fix][meta] Metadata cache refresh might not take effect#25246BewareMyPower wants to merge 2 commits intoapache:masterfrom
BewareMyPower wants to merge 2 commits intoapache:masterfrom
Conversation
4 tasks
Member
|
/pulsarbot rerun-failure-checks |
Contributor
Author
|
@lhotari Do you know why Anyway, I pushed a PR to fix this broken test (not flaky): #25247 |
dao-jun
approved these changes
Feb 14, 2026
gaoran10
reviewed
Feb 14, 2026
| assertTrue(cache.get(key).get().isEmpty()); | ||
|
|
||
| store.put(key, "\"value\"".getBytes(StandardCharsets.UTF_8), Optional.empty()).get(); | ||
| Awaitility.await().pollInterval(Duration.ofMillis(1)).atMost(Duration.ofSeconds(3)).untilAsserted(() -> |
Contributor
There was a problem hiding this comment.
Why does the test need to wait here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
#25187 introduces a regression on
MetadataCacheImpl#refresh. When a path is created or modified, therefreshmethod will be called by updatingobjCachewith the future returned byreadValueFromStore(). However, there is a race:ConcurrentMapofobjCache. Then callreadValueFromStore, which callsstore.getstore.get,objCache.getIfPresentcalls theConcurrentMap#getto get the cached future and check if it's the same with the future inserted to the mapConcurrentMapofobjCacheand release the lockThe updated future of step 3 is not guaranteed to be immediately visible in step 2 because
ConcurrentMap#getis lock-free, which means it does not need to wait the lock onpathis released after step 3.pulsar/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/cache/impl/MetadataCacheImpl.java
Lines 156 to 162 in 9db31cc
The correctness of the code above is based on the fact that the
cachedFuturemust be the future ofreadValueFromStore, but not the existing cached future.This logic was added originally because
testCloneInReadModifyUpdateOrCreatefailed. I've thought it's caused by duplicatedrefreshcalls but it's actually not. However, the root cause is that when it failed, thecreatemethod implementation was wrong:It should be
thenComposeAsyncrather thanthenAcceptAsync, otherwiseobjCache.getmight not see the updated value. This bug was accidentally fixed in my later commits.Modifications
cachedFuturerelated code. We might need a careful design to reduce unnecessary deserializations whenrefreshis called multiple times for an update (e.g. the callback ofMetadataCacheImpl#putand the notification method ofAbstractMetadataStore#accept)testRefreshRaceto verify this race disappears.Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: