Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-11450

Fail to execute migration increasing organization key and name on SQL server 2017

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 7.4
    • Fix Version/s: None
    • Component/s: Database, Organizations
    • Labels:
      None
    • Edition:
      Community
    • Production Notes:
      None

      Description

      Description

      The migration #2321 'Increase organization key and name length' can fail on SQL server 2017 with :

      2018.11.06 10:05:17 INFO  web[][o.s.s.p.w.MasterServletFilter] Initializing servlet filter org.sonar.server.ws.WebServiceFilter@662f7274 [pattern=UrlPattern{inclusions=[/api/system/migrate_db.*, ...], exclusions=[/api/properties*, ...]}]
      2018.11.06 10:05:17 INFO  web[][o.s.s.a.EmbeddedTomcat] HTTP connector enabled on port 9000
      2018.11.06 10:05:19 INFO  web[][o.s.s.p.d.m.DatabaseMigrationImpl] Starting DB Migration and container restart
      2018.11.06 10:05:19 INFO  web[][DbMigrations] Executing DB migrations...
      2018.11.06 10:05:19 INFO  web[][DbMigrations] #2321 'Increase organization key and name length'...
      2018.11.06 10:05:19 ERROR web[][DbMigrations] #2321 'Increase organization key and name length': failure | time=0ms
      2018.11.06 10:05:19 ERROR web[][DbMigrations] Executed DB migrations: failure | time=0ms
      2018.11.06 10:05:19 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=93ms
      2018.11.06 10:05:19 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 #2321 'Increase organization key and name length' 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(Unknown Source)
      	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(Unknown Source)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      	at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.IllegalStateException: Fail to execute ALTER TABLE organizations ALTER COLUMN kee NVARCHAR (255) NOT NULL
      	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.v74.IncreaseOrganizationsKeeAndNameLength.execute(IncreaseOrganizationsKeeAndNameLength.java:41)
      	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: com.microsoft.sqlserver.jdbc.SQLServerException: The index 'organization_key' is dependent on column 'kee'.
      	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:258)
      	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1535)
      	at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:845)
      	at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:752)
      	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7151)
      	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2478)
      	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:219)
      	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:199)
      	at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:729)
      	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)
      	... 14 common frames omitted
      

      To be noted that this issue doesn't happen when starting from an empty database, so when there's only one row in the organizations table (the default organization).

      Explanation

      The migration is updating the key of organizations, but the key is part of the index ORGANIZATION_KEY.

      Workaround

      Before migrating to SonarQube 7.4, drop the index ORGANIZATION_KEY
      After the migration, create the unique index ORGANIZATION_KEY on column key

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                julien.lancelot Julien Lancelot
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: