-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Not use ConcurrentHashMap in CoordinatorRuleManager.rules #9302
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
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.
I think this should be an AtomicReference of an
ImmutableMapotherwise we can not guarantee that no one updates the map after it is set here.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.
Good point. The value type (
List<Rule>) should be immutable as well. I'm ok with usingUnmodifiableMapandUnmodifiableList.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.
+1 - I missed that.
Perhaps the best approach here is to keep the definition of the variable to
AtomicReference<Map<String, List<Rule>>>And add 2 unit tests to ensure
1 - we can not add to/ remove from the map
2 - we can not mutate the rules for an entry in a map.
This way if someone changes this behavior in the future we can catch it easily, and changing the type of Map/ List is easy as well.
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.
Oh yeah, I didn't mean the value type of
rulesshould beUnmodifiableList<Rule>.@suneet-s do you regard your comment as a blocker for this PR? Those tests would be definitely nice to have, but since any tests haven't rewritten for this class, I'm fine with adding all necessary tests including the ones you mentioned in a follow-up PR at once. @zhenxiao you can do in this PR if you want though.
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.
@jihoonson I think we need some way to verify that this change works and will not break in the future.
I understand it's not any worse than before, but I don't think we'll ever come back to add tests for this until we hit a bug - at which point it will be really hard to debug. It should be relatively quick to add those 2 tests so I think it's worth it. If there's a fast follow, that should be ok.
I'll leave it to you for final decision on whether this should be a blocker or not (I'm not sure what the apache rules are), but I think debugging this if someone changes the code to mutate the map would be very tough - I'd strongly recommend we add tests here to prevent that pain in the future.
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.
@zhenxiao would you consider @suneet-s's comment above? I think it would be nice to have. If you want to add them in this PR, I think you may need to create a new class,
CoordinatorRuleManagerTest, and expose therulesvia a method annotated with@VisibleForTestingto verify that the map inside theAtomicRefenceis immutable. Another option could be creating an issue for adding those tests and doing in a follow-up PR.@zhenxiao @suneet-s What do you think?
Uh oh!
There was an error while loading. Please reload this page.
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.
@jihoonson I'm not so familiar with this area of the code, so I'm happy to defer to your judgement. I like the tests you've described and think it's ok if tests come as a fast follow
@zhenxiao can you describe what manual testing you've done to verify this change? I'm sorry if this is coming across as nagging, I've just experienced a lot of pain trying to triage concurrency issues in the past.
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.
@suneet-s what kind of manual testings you think need to be done? The change in this PR looks pretty straightforward and I don't think this PR would lead to any sort of concurrency issues at least for now.
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.
thanks for your comments @suneet-s @jihoonson
updated to unmodifiableMap
I will file an issue to add tests after this PR is merged
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.
I raised #9318.