I got an SQLException when upgrading from 7.1 to 7.2.
2018.06.20 16:37:23 INFO web[][DbMigrations] #2128 'Purge duplicate rules_parameters and their orphans'...
2018.06.20 16:37:23 ERROR web[][DbMigrations] #2128 'Purge duplicate rules_parameters and their orphans': failure | time=48ms
2018.06.20 16:37:23 ERROR web[][DbMigrations] Executed DB migrations: failure | time=50ms
2018.06.20 16:37:23 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=163ms
2018.06.20 16:37:23 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration ended with an exception
org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #2128 'Purge duplicate rules_parameters and their orphans' failed
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:79)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:67)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEachOrdered(ReferencePipeline.java:590)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:52)
at org.sonar.server.platform.db.migration.engine.MigrationEngineImpl.execute(MigrationEngineImpl.java:50)
at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doUpgradeDb(DatabaseMigrationImpl.java:105)
at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doDatabaseMigration(DatabaseMigrationImpl.java:80)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: You can't specify target table 'p1' for update in FROM clause
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.sonar.server.platform.db.migration.step.UpsertImpl.execute(UpsertImpl.java:66)
at org.sonar.server.platform.db.migration.version.v72.PurgeDuplicateRulesParameters.execute(PurgeDuplicateRulesParameters.java:64)
at org.sonar.server.platform.db.migration.step.DataChange.execute(DataChange.java:44)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)
... 11 common frames omitted
We don’t fully understand the problem yet: the migration is well tested and we should have caught it. We need a bit more details to understand what is going wrong and how to fix. Can you please send:
We don’t reproduce the error with MySQL 5.6 and 5.7.22 with the default settings. Changes in the query optimizer in 5.7.6 may have an impact on the DB migration that fails. Could you share the result of show variables like 'optimizer_switch' ? Except the extensions/plugins/ directory, are there some specific changes on the SonarQube installation, like a different JDBC driver ?
Maybe I have a closer look to the actual problem.
I configured the log level to trace and I saw the query which might be the problem:
2018.06.25 14:45:50 TRACE web[][sql] time=16ms | sql=DELETE p1 FROM rules_parameters as p1 WHERE id NOT IN (SELECT id FROM (SELECT MIN(id) as id FROM rules_parameters GROUP BY rule_id, name) temp)
2018.06.25 14:45:50 ERROR web[][DbMigrations] #2128 'Purge duplicate rules_parameters and their orphans': failure | time=27ms
Trying to run that query in MySQL workbench, showed me an 1093 error.
Error Code: 1093. You can't specify target table 'p1' for update in FROM clause
Just to give you an update, on MySQL 5.7.22, having the same value of optimizer_switch as you (the default, apparently), the query works for me. I continue to try to reproduce, or to find another way to write the query.
Lazy workaround: manually insert the migration that doesn’t work.
insert into schema_migrations values (2128);
And then restart SonarQube, visit /setup page to complete the database upgrade, by performing the rest of the migrations.
This migration deletes records that are duplicate by rule_id + name on the rules_parameters table. If there are no duplicates, then the workaround will work flawlessly. If there are some duplicates, then a next migration step will fail. In that case, the duplicates must be deleted manually before continuing with the database upgrade.
Hi I’m on mysql 5.7.11 (centos 7) I’m trying to upgrade Sonar from 6.7.4 LTS to 7.2 and i have exactly the same issue
2018.07.24 18:44:02 ERROR web[][DbMigrations] #2128 'Purge duplicate rules_parameters and their orphans': failure | time=48ms
2018.07.24 18:44:02 ERROR web[][DbMigrations] Executed DB migrations: failure | time=26659526ms
2018.07.24 18:44:02 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=26659596ms
2018.07.24 18:44:02 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration ended with an exception
org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #2128 'Purge duplicate rules_parameters and their orphans' failed
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:79)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:67)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEachOrdered(ReferencePipeline.java:590)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:52)
at org.sonar.server.platform.db.migration.engine.MigrationEngineImpl.execute(MigrationEngineImpl.java:50)
at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doUpgradeDb(DatabaseMigrationImpl.java:105)
at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doDatabaseMigration(DatabaseMigrationImpl.java:80)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: You can't specify target table 'p1' for update in FROM clause
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.sonar.server.platform.db.migration.step.UpsertImpl.execute(UpsertImpl.java:66)
at org.sonar.server.platform.db.migration.version.v72.PurgeDuplicateRulesParameters.execute(PurgeDuplicateRulesParameters.java:64)
at org.sonar.server.platform.db.migration.step.DataChange.execute(DataChange.java:44)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)
... 11 common frames omitted