-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[fix][test] Fix ConcurrentModificationException in testConcurrentWriteBrokerData #18418
[fix][test] Fix ConcurrentModificationException in testConcurrentWriteBrokerData #18418
Conversation
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.
Normally, all three variables run in a lock block. I think the root cause is here:
pulsar/pulsar-broker/src/test/java/org/apache/pulsar/client/api/BrokerServiceLookupTest.java
Lines 222 to 223 in da64346
data.cleanDeltas(); | |
data.getBundles().clear(); |
Hi @AnonHxy Answer for #18418 (comment)
It's interesting. The 'bundles' has clear before submitting to the thread pool, it maybe that other threads didn't see the clear action immediately?
In this for each block below: cleaning the collection, and creating new tasks to update the collection. I think this is the root cause of concurrent access.
pulsar/pulsar-broker/src/test/java/org/apache/pulsar/client/api/BrokerServiceLookupTest.java
Lines 220 to 237 in da64346
for (int i = 0; i < 1000; i++) { | |
LocalBrokerData data = loadManager.getLoadManager().updateLocalBrokerData(); | |
data.cleanDeltas(); | |
data.getBundles().clear(); | |
list.add(executor.submit(() -> { | |
try { | |
assertNotNull(loadManager.generateLoadReport()); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
})); | |
list.add(executor.submit(() -> { | |
try { | |
loadManager.writeLoadReportOnZookeeper(); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
})); |
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/LocalBrokerData.java
Outdated
Show resolved
Hide resolved
It's interesting. The 'bundles' has clear before submitting to the thread pool, it maybe that other threads didn't see the clear action immediately? |
It make sense to me. It seems that we could just remove the following from the test case, and keep others unchanged
WDYT @poorbarcode |
pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/OverloadShedderTest.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/OverloadShedderTest.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/ThresholdShedderTest.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/impl/ThresholdShedderTest.java
Outdated
Show resolved
Hide resolved
@poorbarcode do you have any other comments?:) |
Hi @AnonHxy
I don't know why
I think the concurrent operation was caused by the test case, so there is no need to change the collection to be thread-safe. |
bad27a2
to
e1ffdeb
Compare
Updated. PTAL @poorbarcode |
Codecov Report
@@ Coverage Diff @@
## master #18418 +/- ##
============================================
+ Coverage 45.61% 47.33% +1.71%
+ Complexity 10728 10462 -266
============================================
Files 752 697 -55
Lines 72521 68015 -4506
Branches 7791 7285 -506
============================================
- Hits 33083 32193 -890
+ Misses 35769 32226 -3543
+ Partials 3669 3596 -73
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Sorry, I've been so busy these days. LGTM, Thanks |
Fixes #18417
Motivation
Fixes #18417
Modifications
Change
bundles
,lastBundleGains
andlastBundleLosses
fromHashSet
toConcurrentHashSet
, and remove the setter methodsVerifying this change
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: AnonHxy#16