Improve assignmentMetadataStore thread safety #3020
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)