From: Simon Brandhof Date: Fri, 20 Jun 2014 14:31:13 +0000 (+0200) Subject: SONAR-5394 open SQL write connection only on first statement X-Git-Tag: 4.4-RC1~232 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7557461a362d3caad00a18d90b2052768e85aec6;p=sonarqube.git SONAR-5394 open SQL write connection only on first statement --- diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java index 49230376878..bff09fd3f9d 100644 --- a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java +++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java @@ -88,10 +88,6 @@ public class MassUpdater { Connection writeConnection = null; PreparedStatement writeStatement = null; try { - writeConnection = db.getDataSource().getConnection(); - writeConnection.setAutoCommit(false); - writeStatement = writeConnection.prepareStatement(converter.updateSql()); - readConnection = db.getDataSource().getConnection(); readConnection.setAutoCommit(false); @@ -104,6 +100,17 @@ public class MassUpdater { if (row == null) { continue; } + + if (writeConnection==null) { + // do not open the write connection too early + // else if the select on read connection is long, then mysql + // write connection fails with communication failure error because + // no activity during a long period + writeConnection = db.getDataSource().getConnection(); + writeConnection.setAutoCommit(false); + writeStatement = writeConnection.prepareStatement(converter.updateSql()); + } + if (converter.convert(row, writeStatement)) { writeStatement.addBatch(); writeStatement.clearParameters();