Search in sources :

Example 96 with DiscoveryNodes

use of org.opensearch.cluster.node.DiscoveryNodes in project OpenSearch by opensearch-project.

the class AsyncShardFetchTests method testIgnoreResponseFromDifferentRound.

public void testIgnoreResponseFromDifferentRound() throws Exception {
    DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
    test.addSimulation(node1.getId(), response1);
    // first fetch, no data, still on going
    AsyncShardFetch.FetchResult<Response> fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(false));
    assertThat(test.reroute.get(), equalTo(0));
    // handle a response with incorrect round id, wait on reroute incrementing
    test.processAsyncFetch(Collections.singletonList(response1), Collections.emptyList(), 0);
    assertThat(fetchData.hasData(), equalTo(false));
    assertThat(test.reroute.get(), equalTo(1));
    // fire a response (with correct round id), wait on reroute incrementing
    test.fireSimulationAndWait(node1.getId());
    // verify we get back the data node
    assertThat(test.reroute.get(), equalTo(2));
    fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(true));
    assertThat(fetchData.getData().size(), equalTo(1));
    assertThat(fetchData.getData().get(node1), sameInstance(response1));
}
Also used : BaseNodeResponse(org.opensearch.action.support.nodes.BaseNodeResponse) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 97 with DiscoveryNodes

use of org.opensearch.cluster.node.DiscoveryNodes in project OpenSearch by opensearch-project.

the class AsyncShardFetchTests method testTwoNodesOnSetupAndFailure.

public void testTwoNodesOnSetupAndFailure() throws Exception {
    DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).add(node2).build();
    test.addSimulation(node1.getId(), response1);
    test.addSimulation(node2.getId(), failure2);
    // no fetched data, 2 requests still on going
    AsyncShardFetch.FetchResult<Response> fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(false));
    assertThat(test.reroute.get(), equalTo(0));
    // fire the first response, it should trigger a reroute
    test.fireSimulationAndWait(node1.getId());
    assertThat(test.reroute.get(), equalTo(1));
    fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(false));
    // fire the second simulation, this should allow us to get the data
    test.fireSimulationAndWait(node2.getId());
    assertThat(test.reroute.get(), equalTo(2));
    // since one of those failed, we should only have one entry
    fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(true));
    assertThat(fetchData.getData().size(), equalTo(1));
    assertThat(fetchData.getData().get(node1), sameInstance(response1));
}
Also used : BaseNodeResponse(org.opensearch.action.support.nodes.BaseNodeResponse) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 98 with DiscoveryNodes

use of org.opensearch.cluster.node.DiscoveryNodes in project OpenSearch by opensearch-project.

the class AsyncShardFetchTests method testClose.

public void testClose() throws Exception {
    DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
    test.addSimulation(node1.getId(), response1);
    // first fetch, no data, still on going
    AsyncShardFetch.FetchResult<Response> fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(false));
    assertThat(test.reroute.get(), equalTo(0));
    // fire a response, wait on reroute incrementing
    test.fireSimulationAndWait(node1.getId());
    // verify we get back the data node
    assertThat(test.reroute.get(), equalTo(1));
    test.close();
    try {
        test.fetchData(nodes, emptySet());
        fail("fetch data should fail when closed");
    } catch (IllegalStateException e) {
    // all is well
    }
}
Also used : BaseNodeResponse(org.opensearch.action.support.nodes.BaseNodeResponse) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 99 with DiscoveryNodes

use of org.opensearch.cluster.node.DiscoveryNodes in project OpenSearch by opensearch-project.

the class AsyncShardFetchTests method testIgnoreFailureFromDifferentRound.

public void testIgnoreFailureFromDifferentRound() throws Exception {
    DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
    // add a failed response for node1
    test.addSimulation(node1.getId(), failure1);
    // first fetch, no data, still on going
    AsyncShardFetch.FetchResult<Response> fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(false));
    assertThat(test.reroute.get(), equalTo(0));
    // handle a failure with incorrect round id, wait on reroute incrementing
    test.processAsyncFetch(Collections.emptyList(), Collections.singletonList(new FailedNodeException(node1.getId(), "dummy failure", failure1)), 0);
    assertThat(fetchData.hasData(), equalTo(false));
    assertThat(test.reroute.get(), equalTo(1));
    // fire a response, wait on reroute incrementing
    test.fireSimulationAndWait(node1.getId());
    // failure, fetched data exists, but has no data
    assertThat(test.reroute.get(), equalTo(2));
    fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(true));
    assertThat(fetchData.getData().size(), equalTo(0));
}
Also used : BaseNodeResponse(org.opensearch.action.support.nodes.BaseNodeResponse) FailedNodeException(org.opensearch.action.FailedNodeException) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 100 with DiscoveryNodes

use of org.opensearch.cluster.node.DiscoveryNodes in project OpenSearch by opensearch-project.

the class AsyncShardFetchTests method testConcurrentRequestAndClearCache.

public void testConcurrentRequestAndClearCache() throws Exception {
    DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).build();
    test.addSimulation(node1.getId(), response1);
    // no fetched data, request still on going
    AsyncShardFetch.FetchResult<Response> fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(false));
    assertThat(test.reroute.get(), equalTo(0));
    // clear cache while request is still on going, before it is processed
    test.clearCacheForNode(node1.getId());
    test.fireSimulationAndWait(node1.getId());
    assertThat(test.reroute.get(), equalTo(1));
    // prepare next request
    test.addSimulation(node1.getId(), response1_2);
    // verify still no fetched data, request still on going
    fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(false));
    test.fireSimulationAndWait(node1.getId());
    assertThat(test.reroute.get(), equalTo(2));
    // verify we get new data back
    fetchData = test.fetchData(nodes, emptySet());
    assertThat(fetchData.hasData(), equalTo(true));
    assertThat(fetchData.getData().size(), equalTo(1));
    assertThat(fetchData.getData().get(node1), sameInstance(response1_2));
}
Also used : BaseNodeResponse(org.opensearch.action.support.nodes.BaseNodeResponse) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Aggregations

DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)128 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)82 ClusterState (org.opensearch.cluster.ClusterState)49 Settings (org.opensearch.common.settings.Settings)32 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)27 HashSet (java.util.HashSet)22 ArrayList (java.util.ArrayList)21 ClusterName (org.opensearch.cluster.ClusterName)21 Metadata (org.opensearch.cluster.metadata.Metadata)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 TransportService (org.opensearch.transport.TransportService)19 Collections (java.util.Collections)18 List (java.util.List)18 IOException (java.io.IOException)17 Map (java.util.Map)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 ShardRouting (org.opensearch.cluster.routing.ShardRouting)17 ShardId (org.opensearch.index.shard.ShardId)17 Version (org.opensearch.Version)16