From: Simon Brandhof Date: Wed, 22 Feb 2017 10:50:56 +0000 (+0100) Subject: SONAR-6962 restrict ES issues request to a subset of shards when possible X-Git-Tag: 6.4-RC1~919 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ebd06d1a14047dd37877b6152f82865532cf866b;p=sonarqube.git SONAR-6962 restrict ES issues request to a subset of shards when possible --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 11cc31285a1..afc73ee1afa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -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 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) {