Skip to content

Commit

Permalink
[FIXED JENKINS-8929] Changed the definition of a building downstream …
Browse files Browse the repository at this point in the history
…project to one that is Building, Waiting, Pending or Buildable

but NOT blocked.  This prevents the deadlock condition where upstream project A is blocked on downstream project B, which is
blocked on upstream project A - now in this scenario B will remain blocked but A will build, eventually freeing up B.
  • Loading branch information
Robert Elliot authored and kohsuke committed Apr 7, 2011
1 parent 31fb8b0 commit bddc4f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -98,6 +98,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -1071,9 +1072,10 @@ public CauseOfBlockage getCauseOfBlockage() {
protected AbstractProject getBuildingDownstream() {
DependencyGraph graph = Hudson.getInstance().getDependencyGraph();
Set<AbstractProject> tups = graph.getTransitiveDownstream(this);
tups.add(this);
Queue queue = Hudson.getInstance().getQueue();

for (AbstractProject tup : tups) {
if(tup!=this && (tup.isBuilding() || tup.isInQueue()))
if(tup.isBuilding() || queue.getUnblockedItems().containsKey(tup))
return tup;
}
return null;
Expand Down
14 changes: 13 additions & 1 deletion core/src/main/java/hudson/model/Queue.java
Expand Up @@ -77,6 +77,7 @@
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -633,6 +634,17 @@ public synchronized List<BuildableItem> getPendingItems() {
return new ArrayList<BuildableItem>(pendings.values());
}

/**
* Gets all items that are in the queue but not blocked
*/
synchronized ItemList<Item> getUnblockedItems() {
ItemList<Item> queuedNotBlocked = new ItemList<Item>();
queuedNotBlocked.addAll(waitingList);
queuedNotBlocked.addAll(pendings);
queuedNotBlocked.addAll(buildables);
return queuedNotBlocked;
}

/**
* Is the given task currently pending execution?
*/
Expand Down Expand Up @@ -1557,7 +1569,7 @@ protected void doRun() {
/**
* {@link ArrayList} of {@link Item} with more convenience methods.
*/
private static class ItemList<T extends Item> extends ArrayList<T> {
static class ItemList<T extends Item> extends ArrayList<T> {
public T get(Task task) {
for (T item: this) {
if (item.task == task) {
Expand Down

0 comments on commit bddc4f2

Please sign in to comment.