]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6962 restrict ES issues request to a subset of shards when possible
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 22 Feb 2017 10:50:56 +0000 (11:50 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 22 Feb 2017 16:10:15 +0000 (17:10 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java

index 11cc31285a156c0b75093885f6256355593a599d..afc73ee1afa3e67a840a14d326d358b67c0b109b 100644 (file)
@@ -198,6 +198,7 @@ public class IssueIndex extends BaseIndex {
 
     configureSorting(query, requestBuilder);
     configurePagination(options, requestBuilder);
+    configureRouting(query, options, requestBuilder);
 
     QueryBuilder esQuery = matchAllQuery();
     BoolQueryBuilder esFilter = boolQuery();
@@ -217,6 +218,20 @@ public class IssueIndex extends BaseIndex {
     return new SearchResult<>(requestBuilder.get(), DOC_CONVERTER);
   }
 
+  /**
+   * Optimization - do not send ES request to all shards when scope is restricted
+   * to a set of projects. Because project UUID is used for routing, the request
+   * can be sent to only the shards containing the specified projects.
+   * Note that sticky facets may involve all projects, so this optimization must be
+   * disabled when facets are enabled.
+   */
+  private void configureRouting(IssueQuery query, SearchOptions options, SearchRequestBuilder requestBuilder) {
+    Collection<String> uuids = query.projectUuids();
+    if (!uuids.isEmpty() && options.getFacets().isEmpty()) {
+      requestBuilder.setRouting(uuids.toArray(new String[uuids.size()]));
+    }
+  }
+
   private void configureSorting(IssueQuery query, SearchRequestBuilder esRequest) {
     String sortField = query.sort();
     if (sortField != null) {