Skip to content

Commit

Permalink
Logging improvements to Run related classes (#8777)
Browse files Browse the repository at this point in the history
Logging improvements to Run related classes
  • Loading branch information
Vlatombe authored Dec 14, 2023
1 parent 2239347 commit 302e6ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -2480,10 +2480,12 @@ public EnvVars getEnvironment() throws IOException, InterruptedException {
}
Jenkins j = Jenkins.getInstanceOrNull();
if (j == null) {
LOGGER.fine(() -> "Jenkins not running");
return null;
}
Job<?, ?> job = j.getItemByFullName(jobName, Job.class);
if (job == null) {
LOGGER.fine(() -> "no such job " + jobName + " when running as " + Jenkins.getAuthentication2().getName());
return null;
}
return job.getBuildByNumber(number);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/hudson/model/RunMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ protected R retrieve(File d) throws IOException {
LOGGER.log(Level.WARNING, "could not load " + d, e);
}
}
LOGGER.fine(() -> "no config.xml in " + d);
return null;
}

Expand Down
15 changes: 12 additions & 3 deletions core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,21 @@ public R getByNumber(int n) {
Index snapshot = index;
if (snapshot.byNumber.containsKey(n)) {
BuildReference<R> ref = snapshot.byNumber.get(n);
if (ref == null) return null; // known failure
if (ref == null) {
LOGGER.fine(() -> "known failure of #" + n + " in " + dir);
return null;
}
R v = unwrap(ref);
if (v != null) return v; // already in memory
if (v != null) {
return v; // already in memory
}
// otherwise fall through to load
}
synchronized (this) {
if (index.byNumber.containsKey(n)) { // JENKINS-22767: recheck inside lock
BuildReference<R> ref = index.byNumber.get(n);
if (ref == null) {
LOGGER.fine(() -> "known failure of #" + n + " in " + dir);
return null;
}
R v = unwrap(ref);
Expand Down Expand Up @@ -655,7 +661,10 @@ private R load(File dataDir, Index editInPlace) {
assert Thread.holdsLock(this);
try {
R r = retrieve(dataDir);
if (r == null) return null;
if (r == null) {
LOGGER.fine(() -> "nothing in " + dataDir);
return null;
}

Index copy = editInPlace != null ? editInPlace : new Index(index);

Expand Down

0 comments on commit 302e6ac

Please sign in to comment.