-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][test]fix flaky KeySharedSubscriptionBrokerCacheTest.testReplayQueueReadsGettingCached #24955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This change causes a test to fail: perhaps it adds too much overhead for that test. |
|
I think we should simply use Another optimization would be to add a counter to replace the iteration: pulsar/testmocks/src/main/java/org/apache/bookkeeper/client/PulsarMockLedgerHandle.java Lines 232 to 240 in 186b503
|
@lhotari changed to |
It's necessary to implement pulsar/testmocks/src/main/java/org/apache/bookkeeper/client/PulsarMockLedgerHandle.java Lines 232 to 240 in 186b503
|
PulsarMockLedgerHandle.getLength would need to be implemented using a counter where the counter value is incremented when entries are added.
@lhotari sure, I'll add a counter for this |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #24955 +/- ##
============================================
- Coverage 74.24% 74.23% -0.01%
+ Complexity 33911 33604 -307
============================================
Files 1913 1920 +7
Lines 149510 150062 +552
Branches 17373 17404 +31
============================================
+ Hits 110997 111405 +408
- Misses 29685 29772 +87
- Partials 8828 8885 +57
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the getLength() method in mock BookKeeper classes by maintaining a running counter instead of iterating through entries on each call. The changes also add thread-safety by wrapping the entries list in a synchronized collection.
Key changes:
- Introduced
AtomicLong totalLengthCounterto track cumulative entry lengths - Replaced
ArrayListwithCollections.synchronizedListfor thread-safe entry storage - Updated
getLength()implementations to return the counter value directly
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| PulsarMockReadHandle.java | Added totalLengthCounter parameter and updated getLength() to use the counter |
| PulsarMockLedgerHandle.java | Introduced counter field, made entries list thread-safe, and updated entry addition logic to maintain the counter |
| PulsarMockBookKeeper.java | Updated read handle creation to pass counter reference and added counter reset in shutdown |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
testmocks/src/main/java/org/apache/bookkeeper/client/PulsarMockLedgerHandle.java
Outdated
Show resolved
Hide resolved
testmocks/src/main/java/org/apache/bookkeeper/client/PulsarMockLedgerHandle.java
Show resolved
Hide resolved
testmocks/src/main/java/org/apache/bookkeeper/client/PulsarMockLedgerHandle.java
Outdated
Show resolved
Hide resolved
…QueueReadsGettingCached (apache#24955) (cherry picked from commit aeb1bd1)
…QueueReadsGettingCached (apache#24955) (cherry picked from commit aeb1bd1) (cherry picked from commit 6d07787)
…QueueReadsGettingCached (apache#24955) (cherry picked from commit aeb1bd1) (cherry picked from commit 6d07787)
…QueueReadsGettingCached (apache#24955) (cherry picked from commit aeb1bd1) (cherry picked from commit 421d646)
…QueueReadsGettingCached (apache#24955) (cherry picked from commit aeb1bd1) (cherry picked from commit 421d646)
Fixes #24906
Motivation
the test log is: https://gist.github.com/3pacccccc/7050810fa187f17046d826e7971c174a
From the error logs, we can see the exact failure:
The root cause analysis shows:
entrieslist inPulsarMockLedgerHandlewas implemented as anArrayList, which is not thread-safeConcurrentModificationExceptionoccurred, it caused all caches to be removed, making all subsequent read operations fail1NonRecoverableLedgerException: Should not read from BK since cache should be used2Modifications
Replace
ArrayListwithCopyOnWriteArrayListfor theentriesfield inPulsarMockLedgerHandleVerifying this change
Make sure that the change passes the CI checks.
Dependencies (add or upgrade a dependency)
The public API
The schema
The default values of configurations
The threading model
The binary protocol
The REST endpoints
The admin CLI options
The metrics
Anything that affects deployment
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: 3pacccccc#30