-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Avoid using ArrayList in the concurrent environment.
#16910
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
| public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions, | ||
| ReadEntriesCallback callback, Object ctx, boolean sortEntries) { | ||
| List<Entry> entries = Lists.newArrayListWithExpectedSize(positions.size()); | ||
| List<Entry> entries = Collections.synchronizedList(new ArrayList<>(positions.size())); |
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.
Why local variables need care about concurrency?
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.
We will invoke the entries.add method at callback in the different threads. ( If we need to read entries from the different ledger.)
ArrayList in the concurrent environment.ArrayList in the concurrent environment.
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.
How can this patch fix the NPE issue reported originally?
BTW, you don't have to sync for forEach because compareAndSet will return true only once.
|
I think the issue here can be that the caller calls IIRC bookkeeper handles callbacks one by one so it may not in a concurrent context. |
|
Sorry, I missed the |
Motivation
Relate issue: #16907
pulsar/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
Lines 1375 to 1442 in 3f109d6
We have to avoid using
ArrayListin the concurrent environment.Modifications
synchronizedListto instead ofArrayListVerifying this change
Documentation
doc-not-needed(Please explain why)