Skip to content

Commit

Permalink
[FIXED JENKINS-9913] At least print a diagnostic to the build log if …
Browse files Browse the repository at this point in the history
…we are waiting on a checkpoint.
  • Loading branch information
jglick committed Aug 6, 2013
1 parent 3ca7fbf commit eec3075
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
14 changes: 13 additions & 1 deletion core/src/main/java/hudson/model/CheckPoint.java
Expand Up @@ -28,6 +28,7 @@
import hudson.tasks.Builder;
import hudson.tasks.junit.JUnitResultArchiver;
import hudson.scm.SCM;
import javax.annotation.Nonnull;

/**
* Provides a mechanism for synchronizing build executions in the face of concurrent builds.
Expand Down Expand Up @@ -141,7 +142,18 @@ public void report() {
* If the build (represented by the calling executor thread) is aborted while it's waiting.
*/
public void block() throws InterruptedException {
Run.waitForCheckpoint(this);
Run.waitForCheckpoint(this, null, null);
}

/**
* Like {@link #block()} but allows for richer logging.
* @param listener an optional listener to which
* @param waiter a description of what component is requesting the wait, such as {@link Descriptor#getDisplayName}
* @throws InterruptedException if the build is aborted while waiting
* @since 1.528
*/
public void block(@Nonnull BuildListener listener, @Nonnull String waiter) throws InterruptedException {
Run.waitForCheckpoint(this, listener, waiter);
}

/**
Expand Down
16 changes: 11 additions & 5 deletions core/src/main/java/hudson/model/Run.java
Expand Up @@ -1403,7 +1403,7 @@ private void removeRunFromParent() {
/**
* @see CheckPoint#block()
*/
/*package*/ static void waitForCheckpoint(CheckPoint id) throws InterruptedException {
/*package*/ static void waitForCheckpoint(CheckPoint id, @CheckForNull BuildListener listener, @CheckForNull String waiter) throws InterruptedException {
while(true) {
Run b = RunnerStack.INSTANCE.peek().getBuild().getPreviousBuildInProgress();
if(b==null) return; // no pending earlier build
Expand All @@ -1413,7 +1413,7 @@ private void removeRunFromParent() {
Thread.sleep(0);
continue;
}
if(runner.checkpoints.waitForCheckPoint(id))
if(runner.checkpoints.waitForCheckPoint(id, listener, waiter))
return; // confirmed that the previous build reached the check point

// the previous build finished without ever reaching the check point. try again.
Expand Down Expand Up @@ -1449,13 +1449,19 @@ protected synchronized void report(CheckPoint identifier) {
notifyAll();
}

protected synchronized boolean waitForCheckPoint(CheckPoint identifier) throws InterruptedException {
protected synchronized boolean waitForCheckPoint(CheckPoint identifier, @CheckForNull BuildListener listener, @CheckForNull String waiter) throws InterruptedException {
final Thread t = Thread.currentThread();
final String oldName = t.getName();
t.setName(oldName+" : waiting for "+identifier+" on "+getFullDisplayName());
t.setName(oldName + " : waiting for " + identifier + " on " + getFullDisplayName() + " from " + waiter);
try {
while(!allDone && !checkpoints.contains(identifier))
boolean first = true;
while (!allDone && !checkpoints.contains(identifier)) {
if (first && listener != null && waiter != null) {
listener.getLogger().println(Messages.Run__is_waiting_for_a_checkpoint_on_(waiter, getFullDisplayName()));
}
wait();
first = false;
}
return checkpoints.contains(identifier);
} finally {
t.setName(oldName);
Expand Down
13 changes: 11 additions & 2 deletions core/src/main/java/hudson/tasks/BuildStepMonitor.java
Expand Up @@ -4,6 +4,7 @@
import hudson.model.BuildListener;
import hudson.model.CheckPoint;
import hudson.Launcher;
import hudson.model.Describable;

import java.io.IOException;

Expand All @@ -22,7 +23,11 @@ public boolean perform(BuildStep bs, AbstractBuild build, Launcher launcher, Bui
STEP {
public boolean perform(BuildStep bs, AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
CheckPoint cp = new CheckPoint(bs.getClass().getName(),bs.getClass());
cp.block();
if (bs instanceof Describable) {
cp.block(listener, ((Describable) bs).getDescriptor().getDisplayName());
} else {
cp.block();
}
try {
return bs.perform(build,launcher,listener);
} finally {
Expand All @@ -32,7 +37,11 @@ public boolean perform(BuildStep bs, AbstractBuild build, Launcher launcher, Bui
},
BUILD {
public boolean perform(BuildStep bs, AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
CheckPoint.COMPLETED.block();
if (bs instanceof Describable) {
CheckPoint.COMPLETED.block(listener, ((Describable) bs).getDescriptor().getDisplayName());
} else {
CheckPoint.COMPLETED.block();
}
return bs.perform(build,launcher,listener);
}
};
Expand Down
Expand Up @@ -156,7 +156,7 @@ public boolean perform(AbstractBuild build, Launcher launcher,

action.setData(data);

CHECKPOINT.block();
CHECKPOINT.block(listener, getDescriptor().getDisplayName());

} catch (AbortException e) {
if (build.getResult() == Result.FAILURE)
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/hudson/model/Messages.properties
Expand Up @@ -205,6 +205,7 @@ ResultTrend.StillFailing=Still failing
ResultTrend.StillUnstable=Still unstable
ResultTrend.Success=Success
ResultTrend.Unstable=Unstable
Run._is_waiting_for_a_checkpoint_on_={0} is waiting for a checkpoint on {1}
Run.BuildAborted=Build was aborted
Run.MarkedExplicitly=This record is explicitly marked to be kept.
Run.Permissions.Title=Run
Expand Down

2 comments on commit eec3075

@suryagaddipati
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use git with lots of branches and the whole idea of waiting for previous builds to calculate diffs doesnt make much sense.
Is there a way to disable this checkpoint business?

@jglick
Copy link
Member Author

@jglick jglick commented on eec3075 Aug 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suryagaddipati see my response in JENKINS-9913.

Please sign in to comment.