Upgrade from 6.7.3 to 7.9 (LTS) -> Fail to execute CREATE UNIQUE INDEX live_measures_component

Hi,

I’m trying to update from SonarQube 6.7.3 to 7.9. I’m on Windows and I use an Oracle database.
Sadly, the database migration fails.

2019.07.10 11:34:38 INFO  web[][DbMigrations] #1941 'Populate table live_measures': success | time=792729ms
2019.07.10 11:34:38 INFO  web[][DbMigrations] #1942 'Add live_measures.metric_id index'...
2019.07.10 11:34:48 ERROR web[][DbMigrations] #1942 'Add live_measures.metric_id index': failure | time=9769ms
2019.07.10 11:34:48 ERROR web[][DbMigrations] Executed DB migrations: failure | time=807844ms
2019.07.10 11:34:48 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=807938ms
2019.07.10 11:34:48 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 #1942 'Add live_measures.metric_id index' 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.base/java.lang.Iterable.forEach(Iterable.java:75)
	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:68)
	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.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Fail to execute CREATE UNIQUE INDEX live_measures_component ON live_measures (component_uuid, metric_id)
	at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:97)
	at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:77)
	at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:117)
	at org.sonar.server.platform.db.migration.version.v70.AddLiveMeasuresMetricIndex.execute(AddLiveMeasuresMetricIndex.java:44)
	at org.sonar.server.platform.db.migration.step.DdlChange.execute(DdlChange.java:45)
	at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)
	... 9 common frames omitted
Caused by: java.sql.SQLException: ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found

	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
	at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059)
	at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
	at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
	at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587)
	at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:210)
	at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:30)
	at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:931)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1150)
	at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1792)
	at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1745)
	at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:334)
	at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:175)
	at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:175)
	at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:82)

To check how many duplicate rows exist I ran

select component_uuid, metric_id, count(*) from live_measures group by (component_uuid, metric_id) having count(*) > 1

I found 107 duplicates. To my understanding, the live_measures table is created during the database migration, so something seems wrong in the upgrade scripts.
Please advice.

Thanks,
Markus

Is there a recommended solution for this or way forward?

I have come across the same error. Attempting to migrate from SonarQube Version 6.7 (build 33306) to Community Edition Version 7.7 (build 23042) and have come across the same error

2019.07.10 06:11:27 ERROR web[DbMigrations] #1907 ‘Populate table live_measures’: failure | time=100347ms
2019.07.10 06:11:27 ERROR web[DbMigrations] Executed DB migrations: failure | time=100349ms
2019.07.10 06:11:27 ERROR web[o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=100519ms
2019.07.10 06:11:27 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 #1907 ‘Populate table live_measures’ 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.lang.Iterable.forEach(Iterable.java:75)
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:68)
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.lang.IllegalStateException: Error during processing of row: [uuid=AWTE3M0S7PL3f_vbbpLK,project_uuid=AWTE3M0S7PL3f_vbbpLK,metric_id=1,value=510732,text_value=null,variation_value_1=-22,measure_data=null]
at org.sonar.server.platform.db.migration.step.SelectImpl.newExceptionWithRowDetails(SelectImpl.java:89)
at org.sonar.server.platform.db.migration.step.SelectImpl.scroll(SelectImpl.java:81)
at org.sonar.server.platform.db.migration.step.MassUpdate.execute(MassUpdate.java:92)
at org.sonar.server.platform.db.migration.version.v70.PopulateLiveMeasures.execute(PopulateLiveMeasures.java:57)
at org.sonar.server.platform.db.migration.step.DataChange.execute(DataChange.java:45)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)
… 9 common frames omitted
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (CICD_SONARQ.LIVE_MEASURES_COMPONENT) violated

Running the SQL. We have an Oracle database so I have changed “s.islast = TRUE” to “s.islast = 1”

SELECT p.uuid, p.name, p.kee, p.created_at, p.long_name, p.language, pm.metric_id, COUNT(1)
FROM project_measures pm
INNER JOIN projects p on p.uuid = pm.component_uuid
INNER JOIN snapshots s on s.uuid = pm.analysis_uuid
WHERE s.islast = 1 and pm.person_id is null
GROUP BY p.uuid, p.name, p.kee, p.created_at, p.long_name, p.language, pm.metric_id HAVING
COUNT(1) > 1;

Returned over 200,000 records

Hi all,

Sorry for the delay in responding. This seems to be caused by projects which have gone unanalyzed since 5.6.*. We’re not planning to put out a fix for this, but this ticket tells you how to work around the issue: SONAR-12282.

 
HTH,
Ann

2 Likes

Hello Ann,

thank you for this information. I can confirm that it works. We had a really old Delphi project which we could not scan for years (no working Delphi plugin), but we kept the project because of, well, it was nice to sometimes have a look at the issues that were found. :slight_smile:
After I deleted the project, the database update completed successfully.
Now I just need a solution for this to complete a first analysis with the new SonarQube version.

Thanks for your help.
Markus

2 Likes

Thank you.

All our records returned by the below query belonged to two old projects. Once I deleted those projects, the upgrade was able to progress.

SELECT p.uuid, p.name, p.kee, p.created_at, p.long_name, p.language, pm.metric_id, COUNT(1)
FROM project_measures pm
INNER JOIN projects p on p.uuid = pm.component_uuid
INNER JOIN snapshots s on s.uuid = pm.analysis_uuid
WHERE s.islast = 1 and pm.person_id is null
GROUP BY p.uuid, p.name, p.kee, p.created_at, p.long_name, p.language, pm.metric_id HAVING
COUNT(1) > 1;

2 Likes

Hi Ann,

I am facing the exact same issue mentioned above.
But when I ran the query given in the workaround (after restoring to 6.7.7) it gives me 0 rows.

Can you help me troubleshoot?

Thanks
Siddhant Gogri

@siddhant.gogri your question was answered in the new topic you created. Let’s consider this thread re-closed.