Improve assignmentMetadataStore thread safety #3020
Open
GrantPSpencer wants to merge 2 commits intoapache:masterfrom
Open
Improve assignmentMetadataStore thread safety #3020GrantPSpencer wants to merge 2 commits intoapache:masterfrom
GrantPSpencer wants to merge 2 commits intoapache:masterfrom
Conversation
junkaixue
reviewed
Apr 30, 2025
Comment on lines
82
to
84
| return _globalBaseline.entrySet().stream().collect( | ||
| Collectors.toMap(Map.Entry::getKey, | ||
| entry -> new ResourceAssignment(entry.getValue().getRecord()))); |
Contributor
There was a problem hiding this comment.
Try not implementing lambda function in core piece. It hurts the performance.
3960621 to
a4ae8ae
Compare
junkaixue
reviewed
May 23, 2025
Comment on lines
+112
to
+115
| Map<String, ResourceAssignment> result = new HashMap<>(_bestPossibleAssignment); | ||
| for (Map.Entry<String, ResourceAssignment> entry : _bestPossibleAssignment.entrySet()) { | ||
| result.put(entry.getKey(), new ResourceAssignment(entry.getValue().getRecord())); | ||
| } |
Contributor
There was a problem hiding this comment.
_bestPossibleAssignment.size()?
Contributor
There was a problem hiding this comment.
And this logic I have seen for multiple lines. Please make them in a function to be called in the place similar.
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.
Issues
ConcurrentModification errors can occur during waged rebalance due to async thread modifying the best possible while the main thread is iterating over it
Description
This PR refactors how we access and store the best possible and baseline assignments.
Get - returns a deep copy, assignment can now be safely modified without affecting the cache
Set - creates a deep copy prior to storing - the passed in assignment can be safely modified without affecting the cache
The above changes are aimed at preventing unintended modification of the underlying ResourceAssignments
When a new assignment is persisted, we no longer clear the previous map and add the new map's value, but just point
_globalBaseline or _bestPossibleAssignment at the new map. This change is intended to isolate threads so they cannot modify the underlying structure that another thread is pointing at.
Stack trace of concurrentModification exception that can occur:
Tests
The following tests are written for this issue:
No new tests were added
The following is the result of the "mvn test" command on the appropriate module:
Changes that Break Backward Compatibility (Optional)
N/A
Commits
Code Quality
(helix-style-intellij.xml if IntelliJ IDE is used)