[core][scheduler] Fix iterator invalidation in node label filtering - #65516
[core][scheduler] Fix iterator invalidation in node label filtering#65516RocMarshal wants to merge 1 commit into
Conversation
Signed-off-by: Yuepeng Pan <panyuepeng@apache.org>
There was a problem hiding this comment.
Code Review
This pull request fixes an iterator invalidation bug in NodeLabelSchedulingPolicy::FilterNodesByLabelMatchExpressions when erasing elements from match_nodes during iteration, and adds a corresponding unit test. The reviewer suggested a more idiomatic way to erase elements from the map by utilizing the return value of erase instead of manually copying and incrementing the iterator.
| } else { | ||
| auto iter_to_erase = iter; | ||
| ++iter; | ||
| match_nodes.erase(iter_to_erase); | ||
| } |
There was a problem hiding this comment.
Instead of manually copying the iterator, incrementing it, and then erasing the copy, you can use the return value of match_nodes.erase(iter). In absl::flat_hash_map (and standard C++11 containers), erase returns the iterator pointing to the element immediately following the erased element. This is more idiomatic and less error-prone.
} else {
iter = match_nodes.erase(iter);
}There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 8c9a394. Configure here.
| } else { | ||
| auto iter_to_erase = iter; | ||
| ++iter; | ||
| match_nodes.erase(iter_to_erase); |
There was a problem hiding this comment.
Unclear PR description
Low Severity
This violates the Clear PR Descriptions and Titles rule. The description still includes template boilerplate and restates the title without explaining what the iterator invalidation problem is or how this change fixes it. A short sentence for each would help reviewers.
Triggered by project rule: Bugbot Rules
Reviewed by Cursor Bugbot for commit 8c9a394. Configure here.


Description
[core][scheduler] Fix iterator invalidation in node label filtering
Related issues
#65517
Additional information
N.A