-
Couldn't load subscription status.
- Fork 9.1k
YARN-11838: YARN ConcurrentModificationException When Refreshing Node Attributes #7828
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -741,7 +741,14 @@ public void refreshNodeAttributesToScheduler(NodeId nodeId) { | |||||
| if (host == null || host.attributes == null) { | ||||||
| return; | ||||||
| } | ||||||
| newNodeToAttributesMap.put(hostName, host.attributes.keySet()); | ||||||
| // Use read lock and create defensive copy since | ||||||
| // other threads might access host.attributes | ||||||
| readLock.lock(); | ||||||
| try { | ||||||
| newNodeToAttributesMap.put(hostName, new HashSet<>(host.attributes.keySet())); | ||||||
|
||||||
| newNodeToAttributesMap.put(hostName, new HashSet<>(host.attributes.keySet())); | |
| newNodeToAttributesMap.put(hostName, Collections.unmodifiableSet(new HashSet<>(host.attributes.keySet()))); |
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.
Judging from the stack, the problem occurred when the log was printed, and the wrong line was modified.
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.
The issue is that.
newNodeToAttributesMaptries to iteratehost.attributehost.attributegets modified by some other thread - leading to concurrent modification exception.There are two ways to solve this
host.attributedoes not get modified during LOG statementhost.attribute(under read lock because the modification can happen at that time as well).The rationale behind using option 2 to avoid logging inconsistency- Assume that we readLock before LOG statement. Once the LOG statement is executed, some other thread modifies the
host.attributethis will lead to we logging something and processing something else.Creating a defensive copy make sure that we don't change value. i.e what is LOGed gets processed as well.