Skip to content

Commit

Permalink
[FIXED JENKINS-3265]
Browse files Browse the repository at this point in the history
Made the in-flight build survive the reload from the disk.
  • Loading branch information
kohsuke committed Mar 14, 2013
1 parent a32f2dd commit 25084f5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -62,6 +62,9 @@
<li class=bug>
an in-progress build was dropped from JSON API when lazy-loading was introduced.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15583">issue 15583</a>)
<li class=bug>
In-progress builds now survive the "reload from disk" administrator action.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-3265">issue 3265</a>)
<li class=bug>
Fixed a bad interaction between Windows symlinks and build record lazy loading.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15587">issue 15587</a>)
Expand Down
15 changes: 13 additions & 2 deletions core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -282,9 +282,20 @@ public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOExcep
super.onLoad(parent, name);

RunMap<R> builds = createBuildRunMap();
if (this.builds!=null) {

RunMap<R> currentBuilds = this.builds;

if (currentBuilds==null) {
// are we overwriting what currently exist?
// this is primarily when Jenkins is getting reloaded
Item current = parent.getItem(name);

This comment has been minimized.

Copy link
@jglick

jglick Mar 19, 2013

Member

This is very bad.

This comment has been minimized.

Copy link
@jglick

jglick Mar 31, 2013

Member

This comment has been minimized.

Copy link
@jglick

jglick Apr 5, 2013

Member

Also broke cloudbees-folder (ZD-8933).

This comment has been minimized.

Copy link
@kohsuke

kohsuke Apr 7, 2013

Author Member

Fixed in 4f9d058

This comment has been minimized.

Copy link
@jglick

jglick Apr 8, 2013

Member

That did not fix anything; see comment in that commit.

if (current!=null && current.getClass()==getClass()) {
currentBuilds = ((AbstractProject)current).builds;
}
}
if (currentBuilds !=null) {
// if we are reloading, keep all those that are still building intact
for (R r : this.builds.getLoadedBuilds().values()) {
for (R r : currentBuilds.getLoadedBuilds().values()) {
if (r.isBuilding())
builds.put(r);
}
Expand Down
19 changes: 18 additions & 1 deletion core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -2505,6 +2505,8 @@ public boolean accept(File child) {
}
});

final Set<String> loadedNames = Collections.synchronizedSet(new HashSet<String>());

TaskGraphBuilder g = new TaskGraphBuilder();
Handle loadHudson = g.requires(EXTENSIONS_AUGMENTED).attains(JOB_LOADED).add("Loading global config", new Executable() {
public void run(Reactor session) throws Exception {
Expand All @@ -2527,7 +2529,6 @@ public void run(Reactor session) throws Exception {
if (slaves == null) slaves = new NodeList();

clouds.setOwner(Jenkins.this);
items.clear();

// JENKINS-8043: re-add the slaves which were not saved into the config file
// and are now missing, but still connected.
Expand All @@ -2550,10 +2551,26 @@ public void run(Reactor session) throws Exception {
public void run(Reactor session) throws Exception {
TopLevelItem item = (TopLevelItem) Items.load(Jenkins.this, subdir);
items.put(item.getName(), item);
loadedNames.add(item.getName());

This comment has been minimized.

Copy link
@jglick

jglick Mar 14, 2013

Member

This is not going to work for jobs inside folders I guess?

}
});
}

g.requires(JOB_LOADED).add("Cleaning up old builds",new Executable() {
public void run(Reactor reactor) throws Exception {
// anything we didn't load from disk, throw them away.
// doing this after loading from disk allows newly loaded items
// to inspect what already existed in memory (in case of reloading)

// retainAll doesn't work well because of CopyOnWriteMap implementation, so remove one by one
// hopefully there shouldn't be too many of them.
for (String name : items.keySet()) {
if (!loadedNames.contains(name))
items.remove(name);
}
}
});

g.requires(JOB_LOADED).add("Finalizing set up",new Executable() {
public void run(Reactor session) throws Exception {
rebuildDependencyGraph();
Expand Down

0 comments on commit 25084f5

Please sign in to comment.