Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SearchReplicaSelectionIT failures #71507

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.cluster.routing.OperationRouting;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.ResponseCollectorService.ComputedNodeStats;
import org.elasticsearch.test.ESIntegTestCase;

import java.util.HashSet;
Expand All @@ -28,6 +27,7 @@
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;

@ESIntegTestCase.ClusterScope(numClientNodes = 1, numDataNodes = 3)
public class SearchReplicaSelectionIT extends ESIntegTestCase {
Expand All @@ -38,7 +38,6 @@ public Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
.put(OperationRouting.USE_ADAPTIVE_REPLICA_SELECTION_SETTING.getKey(), true).build();
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/70621")
public void testNodeSelection() {
// We grab a client directly to avoid using a randomizing client that might set a search preference.
Client client = internalCluster().coordOnlyNodeClient();
Expand Down Expand Up @@ -69,7 +68,7 @@ public void testNodeSelection() {

assertEquals(3, nodeIds.size());

// Now after more searches, we should select the node with the best ARS rank.
// Now after more searches, we should select a node with the lowest ARS rank.
for (int i = 0; i < 5; i++) {
client.prepareSearch().setQuery(matchAllQuery()).get();
}
Expand All @@ -86,17 +85,13 @@ public void testNodeSelection() {
assertNotNull(nodeStats);
assertEquals(3, nodeStats.getAdaptiveSelectionStats().getComputedStats().size());

String bestNodeId = null;
double bestRank = Double.POSITIVE_INFINITY;
for (Map.Entry<String, ComputedNodeStats> entry : nodeStats.getAdaptiveSelectionStats().getComputedStats().entrySet()) {
double rank = entry.getValue().rank(1L);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we fixed #71022, we passed in 1 for the number of outstanding requests so that this rank calculation matched the one used to select shards. Now that the bug is fixed, we need to remove the workaround.

if (rank < bestRank) {
bestNodeId = entry.getKey();
bestRank = rank;
}
}

searchResponse = client.prepareSearch().setQuery(matchAllQuery()).get();
assertEquals(bestNodeId, searchResponse.getHits().getAt(0).getShard().getNodeId());
String selectedNodeId = searchResponse.getHits().getAt(0).getShard().getNodeId();
double selectedRank = nodeStats.getAdaptiveSelectionStats().getRanks().get(selectedNodeId);

for (Map.Entry<String, Double> entry : nodeStats.getAdaptiveSelectionStats().getRanks().entrySet()) {
double rank = entry.getValue();
assertThat(rank, greaterThanOrEqualTo(selectedRank));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected SearchService newSearchService(ClusterService clusterService, IndicesS
responseCollectorService, circuitBreakerService);
}
return new MockSearchService(clusterService, indicesService, threadPool, scriptService,
bigArrays, fetchPhase, circuitBreakerService);
bigArrays, fetchPhase, responseCollectorService, circuitBreakerService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.node.MockNode;
import org.elasticsearch.node.ResponseCollectorService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.fetch.FetchPhase;
Expand Down Expand Up @@ -68,10 +69,11 @@ static void removeActiveContext(ReaderContext context) {
ACTIVE_SEARCH_CONTEXTS.remove(context);
}

public MockSearchService(ClusterService clusterService,
IndicesService indicesService, ThreadPool threadPool, ScriptService scriptService,
BigArrays bigArrays, FetchPhase fetchPhase, CircuitBreakerService circuitBreakerService) {
super(clusterService, indicesService, threadPool, scriptService, bigArrays, fetchPhase, null, circuitBreakerService);
public MockSearchService(ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool,
ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase,
ResponseCollectorService responseCollectorService, CircuitBreakerService circuitBreakerService) {
super(clusterService, indicesService, threadPool, scriptService, bigArrays, fetchPhase, responseCollectorService,
circuitBreakerService);
}

@Override
Expand Down