[fix][meta] Metadata cache refresh might not take effect#25246
Merged
lhotari merged 3 commits intoapache:masterfrom Feb 16, 2026
Merged
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
pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #25246 +/- ##
=============================================
+ Coverage 37.96% 72.59% +34.63%
- Complexity 13510 34396 +20886
=============================================
Files 1902 1959 +57
Lines 151242 155401 +4159
Branches 17240 17724 +484
=============================================
+ Hits 57413 112821 +55408
+ Misses 86193 33576 -52617
- Partials 7636 9004 +1368
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
lhotari
pushed a commit
that referenced
this pull request
Feb 16, 2026
(cherry picked from commit 24eba10)
lhotari
pushed a commit
that referenced
this pull request
Feb 16, 2026
(cherry picked from commit 24eba10)
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: