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

Project is corrupted because of branch or pull request in inconsistent state

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.8
    • Component/s: Branch & PR
    • Labels:
      None
    • Edition:
      Developer
    • Production Notes:
      None

      Description

      Several issues point to same cause:

      1. Analysis fails to be processed by Compute Engine with error:
        org.apache.ibatis.exceptions.PersistenceException: 
            ### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "project_branches_kee_key_type"
              Detail: Key (project_uuid, kee, key_type)=(AWnkeQn68FPh9JKrfdOa, 92, PULL_REQUEST) already exists.
            ### The error may involve org.sonar.db.component.BranchMapper.insert-Inline
            ### The error occurred while setting parameters
            ### SQL: insert into project_branches (       uuid,       project_uuid,       kee,       key_type,       branch_type,       merge_branch_uuid,       pull_request_binary,       manual_baseline_analysis_uuid,       created_at,       updated_at     ) values (       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?     )
            ### Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "project_branches_kee_key_type"
              Detail: Key (project_uuid, kee, key_type)=(AWnkeQn68FPh9JKrfdOa, 92, PULL_REQUEST) already exists.
            	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
            	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
            	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
            	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
            	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
            	at com.sun.proxy.$Proxy54.insert(Unknown Source)
            	at org.sonar.db.component.BranchDao.upsert(BranchDao.java:50)
            	at org.sonar.ce.task.projectanalysis.component.BranchPersisterImpl.persist(BranchPersisterImpl.java:54)
            	at org.sonar.ce.task.projectanalysis.step.PersistComponentsStep.execute(PersistComponentsStep.java:96)
            	at org.sonar.ce.task.step.ComputationStepExecutor.executeStep(ComputationStepExecutor.java:81)
            	at org.sonar.ce.task.step.ComputationStepExecutor.executeSteps(ComputationStepExecutor.java:72)
            	at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:59)
            	at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
            	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:207)
            	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:189)
            	at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:156)
            	at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:131)
            	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:83)
            	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:51)
            	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
            	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
            	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
            	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: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "project_branches_kee_key_type"
              Detail: Key (project_uuid, kee, key_type)=(AWnkeQn68FPh9JKrfdOa, 92, PULL_REQUEST) already exists.
            	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
            	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
            	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
            	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
            	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
            	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
            	at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:132)
            	at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)
            	at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)
            	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
            	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
            	at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java:52)
            	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
            	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
            	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
            	... 25 more
        
      2. The same project can no longer be deleted. Webapp fails with message "component not found"
        The error is thrown by the elseThrow in the following piece of code:
        private static void deleteRootComponent(String rootUuid, PurgeMapper mapper, PurgeCommands commands) {
          List<IdUuidPair> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid);
          long rootId = rootAndModulesOrSubviews.stream()
            .filter(pair -> pair.getUuid().equals(rootUuid))
            .map(IdUuidPair::getId)
            .findFirst()
            .orElseThrow(() -> new IllegalArgumentException("Couldn't find root component with uuid " + rootUuid));
          [...]
        }
      3. a user on the mailing list reports failure at renaming a project key and a branch which can't be deleted from the UI (see https://community.sonarsource.com/t/sonar-failing-to-update-project-key/10547/2)

      The root cause is that the table project_branches has a row that references a component that does not exist in the table projects: the SQL request select count(uuid) from project_branches pb where not exists (select 1 from projects p where p.uuid = pb.uuid) does not return the expected zero.

      What should be fixed:

      • project deletion should not fail if the table project_branches has orphans. These orphan rows should be deleted.
      • it should not be possible to have orphans in project_branches !

        Attachments

          Activity

            People

            Assignee:
            sebastien.lesaint Sebastien Lesaint
            Reporter:
            simon.brandhof Simon Brandhof (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Due:
              Created:
              Updated:
              Resolved: