Skip to content

Commit d31269a

Browse files
author
maoqingyi
committed
use map instead of list to cache blockage reasons
1 parent 59ce26e commit d31269a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/src/main/java/hudson/model/Queue.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ public void maintain() {
16161616
updateSnapshot();
16171617

16181618
// put label has no candidates here to accelerate the buildableItem circle
1619-
List<Label> noCandidateLabels = new ArrayList<>();
1619+
Map<Label, List<CauseOfBlockage>> noCandidateLabelsMap = new HashMap<>();
16201620
// allocate buildable jobs to executors
16211621
for (BuildableItem p : new ArrayList<>(
16221622
buildables)) { // copy as we'll mutate the list in the loop
@@ -1633,7 +1633,8 @@ public void maintain() {
16331633
}
16341634

16351635
Label itemLabel = p.getAssignedLabel();
1636-
if (noCandidateLabels.contains(itemLabel)) {
1636+
if (noCandidateLabelsMap.containsKey(itemLabel)) {
1637+
p.transientCausesOfBlockage = noCandidateLabelsMap.get(itemLabel);
16371638
continue;
16381639
}
16391640
String taskDisplayName = LOGGER.isLoggable(Level.FINEST) ? p.task.getFullDisplayName() : null;
@@ -1679,9 +1680,9 @@ public void maintain() {
16791680
new Object[]{p, candidates, parked.values()});
16801681
List<CauseOfBlockage> reasons = reasonMap.values().stream().filter(Objects::nonNull).collect(Collectors.toList());
16811682
p.transientCausesOfBlockage = reasons.isEmpty() ? null : reasons;
1682-
// If no candidates, mark the label and end this loop early.
1683+
// If no candidates, mark the label and reasons
16831684
if (candidates.isEmpty()) {
1684-
noCandidateLabels.add(itemLabel);
1685+
noCandidateLabelsMap.put(itemLabel, p.transientCausesOfBlockage);
16851686
LOGGER.log(Level.FINEST, "{0} changes to the state of no candidate executor", itemLabel);
16861687
}
16871688
continue;

0 commit comments

Comments
 (0)