Skip to content

Commit

Permalink
[JENKINS-40435] - Use BulkChange when processing config changes in Jo…
Browse files Browse the repository at this point in the history
…b#doConfigSubmit. (#2664)

When an empty Freestyle job config gets submitted in the default configuration of Jenkins 2.35, the data is being saved to the disk *8 times*. All of them happen in this code: https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/Job.java#L1227-L1246

* setDisplayName
* Project#getBuildWrappersList().rebuild (onModified handler)
* Project#getBuilderList().rebuild (onModified handler)
* Project#getPublisherList().rebuild (onModified handler)
* AbstractProject#makeDisabled
* AbstractProject#setScm
* AbstractProject#triggers.replaceBy
* final save()

There is not so much sense to save partial configurations to the disk due to the risk of data inconsistency there. This change just wraps the config submission section of the job into the BulkChange clause.
(cherry picked from commit a0262d2)
  • Loading branch information
oleg-nenashev authored and olivergondza committed Jan 11, 2017
1 parent ce8edf0 commit ea97d51
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions core/src/main/java/hudson/model/Job.java
Expand Up @@ -1224,26 +1224,27 @@ public synchronized void doConfigSubmit(StaplerRequest req,
JSONObject json = req.getSubmittedForm();

try {
setDisplayName(json.optString("displayNameOrNull"));
try (BulkChange bc = new BulkChange(this)) {
setDisplayName(json.optString("displayNameOrNull"));

logRotator = null;
logRotator = null;

DescribableList<JobProperty<?>, JobPropertyDescriptor> t = new DescribableList<JobProperty<?>, JobPropertyDescriptor>(NOOP,getAllProperties());
JSONObject jsonProperties = json.optJSONObject("properties");
if (jsonProperties != null) {
t.rebuild(req,jsonProperties,JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass()));
} else {
t.clear();
}
properties.clear();
for (JobProperty p : t) {
p.setOwner(this);
properties.add(p);
}

submit(req, rsp);
DescribableList<JobProperty<?>, JobPropertyDescriptor> t = new DescribableList<JobProperty<?>, JobPropertyDescriptor>(NOOP,getAllProperties());
JSONObject jsonProperties = json.optJSONObject("properties");
if (jsonProperties != null) {
t.rebuild(req,jsonProperties,JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass()));
} else {
t.clear();
}
properties.clear();
for (JobProperty p : t) {
p.setOwner(this);
properties.add(p);
}

save();
submit(req, rsp);
bc.commit();
}
ItemListener.fireOnUpdated(this);

String newName = req.getParameter("name");
Expand Down

0 comments on commit ea97d51

Please sign in to comment.