]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9480 fix removal of rules from index when too many failures
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 13 Jul 2017 13:15:44 +0000 (15:15 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Thu, 13 Jul 2017 15:55:05 +0000 (17:55 +0200)
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexer.java
server/sonar-server/src/test/java/org/sonar/server/es/RecoveryIndexerTest.java

index 8a9f9d6f2908312f3af2268c151db2ec1de36610..edb2402016350ad73c6b8d40d36de29f4b7bec6e 100644 (file)
@@ -48,7 +48,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Arrays.asList;
 import static java.util.Collections.singletonList;
 import static java.util.Objects.requireNonNull;
-import static org.sonar.core.util.stream.MoreCollectors.toArrayList;
+import static org.sonar.core.util.stream.MoreCollectors.toHashSet;
 import static org.sonar.server.rule.index.RuleIndexDefinition.INDEX_TYPE_RULE;
 import static org.sonar.server.rule.index.RuleIndexDefinition.INDEX_TYPE_RULE_EXTENSION;
 
@@ -138,14 +138,14 @@ public class RuleIndexer implements StartupIndexer, ResilientIndexer {
     BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, new ResiliencyIndexingListener(dbClient, dbSession, items));
     bulkIndexer.start();
 
-    List<RuleKey> ruleKeys = items
+    Set<RuleKey> ruleKeys = items
       .stream()
       .filter(i -> {
         requireNonNull(i.getDocId(), () -> "BUG - " + i + " has not been persisted before indexing");
         return i.getDocType() == EsQueueDto.Type.RULE;
       })
       .map(i -> RuleKey.parse(i.getDocId()))
-      .collect(toArrayList(items.size()));
+      .collect(toHashSet(items.size()));
 
     dbClient.ruleDao().scrollIndexingRulesByKeys(dbSession, ruleKeys,
       // only index requests, no deletion requests.
@@ -158,8 +158,10 @@ public class RuleIndexer implements StartupIndexer, ResilientIndexer {
 
     // the remaining items reference rows that don't exist in db. They must
     // be deleted from index.
-    ruleKeys.forEach(r -> bulkIndexer.addDeletion(RuleIndexDefinition.INDEX_TYPE_RULE, r.toString(), r.toString()));
-    ruleKeys.forEach(r -> bulkIndexer.addDeletion(RuleIndexDefinition.INDEX_TYPE_RULE_EXTENSION, RuleExtensionDoc.idOf(r, RuleExtensionScope.system()), r.toString()));
+    ruleKeys.forEach(r -> {
+      bulkIndexer.addDeletion(RuleIndexDefinition.INDEX_TYPE_RULE, r.toString(), r.toString());
+      bulkIndexer.addDeletion(RuleIndexDefinition.INDEX_TYPE_RULE_EXTENSION, RuleExtensionDoc.idOf(r, RuleExtensionScope.system()), r.toString());
+    });
 
     return bulkIndexer.stop();
   }
@@ -168,14 +170,14 @@ public class RuleIndexer implements StartupIndexer, ResilientIndexer {
     BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, new ResiliencyIndexingListener(dbClient, dbSession, items));
     bulkIndexer.start();
 
-    List<RuleExtensionId> docIds = items
+    Set<RuleExtensionId> docIds = items
       .stream()
       .filter(i -> {
         requireNonNull(i.getDocId(), () -> "BUG - " + i + " has not been persisted before indexing");
         return i.getDocType() == EsQueueDto.Type.RULE_EXTENSION;
       })
       .map(RuleIndexer::explodeRuleExtensionDocId)
-      .collect(toArrayList(items.size()));
+      .collect(toHashSet(items.size()));
 
     dbClient.ruleDao().scrollIndexingRuleExtensionsByIds(dbSession, docIds,
       // only index requests, no deletion requests.
index eaede45f8aa9b60bf88f984f3abd9e69a9f36552..7cead64cb48f0bf49cfaaa261187c8df9a782ef7 100644 (file)
@@ -45,7 +45,7 @@ import org.sonar.server.es.StartupIndexer;
 
 import static java.util.Collections.singletonList;
 import static java.util.Objects.requireNonNull;
-import static org.sonar.core.util.stream.MoreCollectors.toArrayList;
+import static org.sonar.core.util.stream.MoreCollectors.toHashSet;
 import static org.sonar.server.user.index.UserIndexDefinition.INDEX_TYPE_USER;
 
 public class UserIndexer implements StartupIndexer, ResilientIndexer {
@@ -113,14 +113,14 @@ public class UserIndexer implements StartupIndexer, ResilientIndexer {
     if (items.isEmpty()) {
       return new IndexingResult();
     }
-    List<String> logins = items
+    Set<String> logins = items
       .stream()
       .filter(i -> {
         requireNonNull(i.getDocId(), () -> "BUG - " + i + " has not been persisted before indexing");
         return i.getDocType() == EsQueueDto.Type.USER;
       })
       .map(EsQueueDto::getDocId)
-      .collect(toArrayList(items.size()));
+      .collect(toHashSet(items.size()));
 
     ListMultimap<String, String> organizationUuidsByLogin = ArrayListMultimap.create();
     dbClient.organizationMemberDao().selectForUserIndexing(dbSession, logins, organizationUuidsByLogin::put);
index b3f42589d137b124a2b216cadb64db1bdc9250ea..423a185cacb2e1873e939703f59f712a532daac6 100644 (file)
@@ -307,7 +307,7 @@ public class RecoveryIndexerTest {
       .containsExactlyInAnyOrder(item1.getUuid(), item2.getUuid(), item3.getUuid());
 
     assertThatLogsContain(TRACE, "Elasticsearch recovery - processing 3 USER");
-    assertThatLogsContain(INFO, "Elasticsearch recovery - 3 documents processed [0 failures]");
+    assertThatLogsContain(INFO, "Elasticsearch recovery - 1 documents processed [0 failures]");
   }
 
   private class ProxyUserIndexer extends UserIndexer {