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

Indexing of active rules in E/S fail when they are linked on removed rules

    XMLWordPrintable

    Details

      Description

      Indexing of active rules in E/S fail when they are linked on no more existing rules (but it could also be the same if they are linked on no more existing quality profiles).
      This is not a normal use case as removed rules are never deleted from the database.

      Here's the stacktrace generated in such case :

      2015.05.05 10:24:54 INFO  web[o.s.s.s.BaseIndex]  Index rules:rules has last update of Wed Dec 31 19:00:00 EST 1969
      2015.05.05 10:24:54 INFO  web[o.s.s.s.BaseIndex]  Index rules:activeRules has last update of Wed Dec 31 19:00:00 EST 1969
      2015.05.05 10:24:54 ERROR web[o.s.s.s.IndexQueue]  Could not commit to ElasticSearch
      java.lang.IllegalStateException: Could not execute normalization for stack
      	at org.sonar.server.search.IndexQueue.executeNormalization(IndexQueue.java:141) ~[sonar-server-4.5.2.jar:na]
      	at org.sonar.server.search.IndexQueue.enqueue(IndexQueue.java:84) ~[sonar-server-4.5.2.jar:na]
      	at org.sonar.core.persistence.DbSession.commit(DbSession.java:59) [sonar-core-4.5.2.jar:na]
      	at org.sonar.core.persistence.BatchSession.commit(BatchSession.java:170) [sonar-core-4.5.2.jar:na]
      	at org.sonar.server.db.BaseDao.synchronizeAfter(BaseDao.java:285) [sonar-server-4.5.2.jar:na]
      	at org.sonar.server.search.IndexSynchronizer.synchronize(IndexSynchronizer.java:60) [sonar-server-4.5.2.jar:na]
      	at org.sonar.server.search.IndexSynchronizer.execute(IndexSynchronizer.java:52) [sonar-server-4.5.2.jar:na]
      	at org.sonar.server.platform.ServerComponents$1.doPrivileged(ServerComponents.java:589) [sonar-server-4.5.2.jar:na]
      	at org.sonar.server.user.DoPrivileged.execute(DoPrivileged.java:43) [sonar-server-4.5.2.jar:na]
      	at org.sonar.server.platform.ServerComponents.executeStartupTasks(ServerComponents.java:586) [sonar-server-4.5.2.jar:na]
      	at org.sonar.server.platform.Platform.executeStartupTasks(Platform.java:126) [sonar-server-4.5.2.jar:na]
      	at org.sonar.server.platform.Platform.startLevel34Containers(Platform.java:122) [sonar-server-4.5.2.jar:na]
      	at org.sonar.server.platform.Platform.doStart(Platform.java:81) [sonar-server-4.5.2.jar:na]
      	at org.sonar.server.platform.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:43) [sonar-server-4.5.2.jar:na]
      	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973) [tomcat-embed-core-7.0.54.jar:7.0.54]
      	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467) [tomcat-embed-core-7.0.54.jar:7.0.54]
      	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-7.0.54.jar:7.0.54]
      	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [tomcat-embed-core-7.0.54.jar:7.0.54]
      	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [tomcat-embed-core-7.0.54.jar:7.0.54]
      	at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_51]
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_51]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_51]
      	at java.lang.Thread.run(Thread.java:744) [na:1.7.0_51]
      Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Repository must be set
      	at java.util.concurrent.FutureTask.report(FutureTask.java:122) [na:1.7.0_51]
      	at java.util.concurrent.FutureTask.get(FutureTask.java:188) [na:1.7.0_51]
      	at org.sonar.server.search.IndexQueue.executeNormalization(IndexQueue.java:129) ~[sonar-server-4.5.2.jar:na]
      	... 22 common frames omitted
      Caused by: java.lang.IllegalArgumentException: Repository must be set
      	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:88) ~[guava-10.0.1.jar:na]
      	at org.sonar.api.rule.RuleKey.of(RuleKey.java:46) ~[sonar-plugin-api-4.5.2.jar:na]
      	at org.sonar.core.qualityprofile.db.ActiveRuleDto.getKey(ActiveRuleDto.java:64) ~[sonar-core-4.5.2.jar:na]
      	at org.sonar.server.qualityprofile.index.ActiveRuleNormalizer.normalize(ActiveRuleNormalizer.java:109) ~[sonar-server-4.5.2.jar:na]
      	at org.sonar.server.qualityprofile.index.ActiveRuleNormalizer.normalize(ActiveRuleNormalizer.java:47) ~[sonar-server-4.5.2.jar:na]
      	at org.sonar.server.search.action.UpsertDto.doCall(UpsertDto.java:53) ~[sonar-server-4.5.2.jar:na]
      	at org.sonar.server.search.action.IndexActionRequest.call(IndexActionRequest.java:66) ~[sonar-server-4.5.2.jar:na]
      	at org.sonar.server.search.action.IndexActionRequest.call(IndexActionRequest.java:31) ~[sonar-server-4.5.2.jar:na]
      	... 4 common frames omitted
      

      This is because the query to get active rules is using some LEFT JOIN :

      SELECT * FROM active_rules a
          LEFT JOIN rules_profiles qp ON qp.id=a.profile_id
          LEFT JOIN rules_profiles profile_parent ON profile_parent.kee=qp.parent_kee
          LEFT JOIN active_rules active_rule_parent ON active_rule_parent.profile_id=profile_parent.id AND a.rule_id=active_rule_parent.rule_id
      

      The solution could be to replace LEFT JOIN by INNER JOIN, then active rules on no more existing rules or quality profiles will be ignored.

        Attachments

          Activity

            People

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

              Dates

              Due:
              Created:
              Updated:
              Resolved: