From: Simon Brandhof Date: Tue, 23 Jul 2013 13:50:09 +0000 (+0200) Subject: Add debug logs to export of dry run H2 db X-Git-Tag: 3.7~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a8741b115d7539fd29fed8f5754167611a739c5c;p=sonarqube.git Add debug logs to export of dry run H2 db --- diff --git a/sonar-application/src/main/assembly/conf/logback.xml b/sonar-application/src/main/assembly/conf/logback.xml index cea4a381d49..5859163242d 100644 --- a/sonar-application/src/main/assembly/conf/logback.xml +++ b/sonar-application/src/main/assembly/conf/logback.xml @@ -76,10 +76,21 @@ + + + + diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java b/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java index 2a1fb7d9d1b..1ed424396b0 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java @@ -31,14 +31,7 @@ import org.sonar.api.ServerComponent; import org.sonar.api.utils.SonarException; import javax.sql.DataSource; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Timestamp; -import java.sql.Types; +import java.sql.*; import java.util.List; public class DbTemplate implements ServerComponent { @@ -46,6 +39,7 @@ public class DbTemplate implements ServerComponent { public DbTemplate copyTable(DataSource source, DataSource dest, String table, String... whereClauses) { LOG.debug("Copy table {}", table); + long startup = System.currentTimeMillis(); String selectQuery = selectQuery(table, whereClauses); truncate(dest, table); @@ -56,6 +50,7 @@ public class DbTemplate implements ServerComponent { Connection destConnection = null; ResultSet destResultSet = null; PreparedStatement destStatement = null; + int count = 0; try { sourceConnection = source.getConnection(); sourceStatement = sourceConnection.createStatement(); @@ -71,7 +66,7 @@ public class DbTemplate implements ServerComponent { String insertSql = new StringBuilder().append("INSERT INTO ").append(table).append("(").append(Joiner.on(",").join(columnNames)) .append(") VALUES(").append(StringUtils.repeat("?", ",", columnNames.length)).append(")").toString(); destStatement = destConnection.prepareStatement(insertSql); - int count = 0; + do { copyColumns(sourceResultSet, destStatement, columnNames, columnTypes); count++; @@ -86,6 +81,9 @@ public class DbTemplate implements ServerComponent { destStatement.executeBatch(); destConnection.commit(); } + if (LOG.isDebugEnabled()) { + LOG.debug(" " + count + " rows of " + table + " copied in " + (System.currentTimeMillis() - startup) + " ms"); + } } catch (SQLException e) { LOG.error("Fail to copy table " + table, e); throw new IllegalStateException("Fail to copy table " + table, e); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java index 27a8445f42b..e752e618fc8 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java @@ -21,6 +21,8 @@ package org.sonar.core.persistence; import com.google.common.io.Files; import org.apache.commons.dbcp.BasicDataSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.api.ServerComponent; import org.sonar.api.issue.Issue; import org.sonar.api.platform.ServerFileSystem; @@ -33,6 +35,7 @@ import java.io.IOException; import java.sql.SQLException; public class DryRunDatabaseFactory implements ServerComponent { + private static final Logger LOG = LoggerFactory.getLogger(DryRunDatabaseFactory.class); private static final String DIALECT = "h2"; private static final String DRIVER = "org.h2.Driver"; private static final String URL = "jdbc:h2:"; @@ -47,6 +50,7 @@ public class DryRunDatabaseFactory implements ServerComponent { } public byte[] createDatabaseForDryRun(@Nullable Long projectId) { + long startup = System.currentTimeMillis(); String name = serverFileSystem.getTempDir().getAbsolutePath() + "db-" + System.nanoTime(); try { @@ -56,6 +60,17 @@ public class DryRunDatabaseFactory implements ServerComponent { copy(source, destination, projectId); close(destination); + if (LOG.isDebugEnabled()) { + File dbFile = new File(name + ".h2.db"); + long size = dbFile.length(); + long duration = System.currentTimeMillis() - startup; + if (projectId == null) { + LOG.debug("Dry Run Database created in " + duration + " ms, size is " + size + " bytes"); + } else { + LOG.debug("Dry Run Database for project " + projectId + " created in " + duration + " ms, size is " + size + " bytes"); + } + } + return dbFileContent(name); } catch (SQLException e) { throw new SonarException("Unable to create database for DryRun", e);