From 5db2f0139ca12c5d7dc7cf3a1f7712074936880d Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Sat, 2 Nov 2024 09:25:07 -0400 Subject: [PATCH] Avoid saving `nextBuildNumber` while loading `Job` (#9778) --- core/src/main/java/hudson/model/Job.java | 21 ++++++------------- .../jenkins/model/lazy/LazyBuildMixIn.java | 4 ++-- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java index e4d54d44b375..c4c8679674a1 100644 --- a/core/src/main/java/hudson/model/Job.java +++ b/core/src/main/java/hudson/model/Job.java @@ -221,29 +221,20 @@ public void onLoad(ItemGroup parent, String name) TextFile f = getNextBuildNumberFile(); if (f.exists()) { - // starting 1.28, we store nextBuildNumber in a separate file. - // but old Hudson didn't do it, so if the file doesn't exist, - // assume that nextBuildNumber was read from config.xml try { synchronized (this) { this.nextBuildNumber = Integer.parseInt(f.readTrim()); } } catch (NumberFormatException e) { LOGGER.log(Level.WARNING, "Corruption in {0}: {1}", new Object[] {f, e}); - //noinspection StatementWithEmptyBody - if (this instanceof LazyBuildMixIn.LazyLoadingJob) { - // allow LazyBuildMixIn.onLoad to fix it - } else { - RunT lB = getLastBuild(); - synchronized (this) { - this.nextBuildNumber = lB != null ? lB.getNumber() + 1 : 1; - } - saveNextBuildNumber(); + RunT lB = getLastBuild(); + synchronized (this) { + this.nextBuildNumber = lB != null ? lB.getNumber() + 1 : 1; } + saveNextBuildNumber(); } - } else { - // From the old Hudson, or doCreateItem. Create this file now. - saveNextBuildNumber(); + } else if (nextBuildNumber == 0) { + nextBuildNumber = 1; } if (properties == null) // didn't exist < 1.72 diff --git a/core/src/main/java/jenkins/model/lazy/LazyBuildMixIn.java b/core/src/main/java/jenkins/model/lazy/LazyBuildMixIn.java index c73c5cbf80f1..d6329ed13ed5 100644 --- a/core/src/main/java/jenkins/model/lazy/LazyBuildMixIn.java +++ b/core/src/main/java/jenkins/model/lazy/LazyBuildMixIn.java @@ -109,8 +109,8 @@ public void onLoad(ItemGroup parent, String name) throws IOExcep int max = _builds.maxNumberOnDisk(); int next = asJob().getNextBuildNumber(); if (next <= max) { - LOGGER.log(Level.WARNING, "JENKINS-27530: improper nextBuildNumber {0} detected in {1} with highest build number {2}; adjusting", new Object[] {next, asJob(), max}); - asJob().updateNextBuildNumber(max + 1); + LOGGER.log(Level.FINE, "nextBuildNumber {0} detected in {1} with highest build number {2}; adjusting", new Object[] {next, asJob(), max}); + asJob().fastUpdateNextBuildNumber(max + 1); } RunMap currentBuilds = this.builds; if (parent != null) {