Search in sources :

Example 66 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.

the class RoutingTest method testRoutingForRandomMasterOrDataNodePrefersLocal.

@Test
public void testRoutingForRandomMasterOrDataNodePrefersLocal() throws Exception {
    Set<DiscoveryNodeRole> data = Set.of(DiscoveryNodeRole.DATA_ROLE);
    Map<String, String> attr = Map.of();
    DiscoveryNode local = new DiscoveryNode("local_data", buildNewFakeTransportAddress(), attr, data, null);
    DiscoveryNodes nodes = new DiscoveryNodes.Builder().add(local).localNodeId(local.getId()).add(new DiscoveryNode("data_1", buildNewFakeTransportAddress(), attr, data, null)).add(new DiscoveryNode("data_2", buildNewFakeTransportAddress(), attr, data, null)).add(new DiscoveryNode("data_3", buildNewFakeTransportAddress(), attr, data, null)).add(new DiscoveryNode("data_4", buildNewFakeTransportAddress(), attr, data, null)).build();
    RoutingProvider routingProvider = new RoutingProvider(Randomness.get().nextInt(), Collections.emptyList());
    Routing routing = routingProvider.forRandomMasterOrDataNode(new RelationName("doc", "table"), nodes);
    assertThat(routing.locations().keySet(), contains("local_data"));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Test(org.junit.Test)

Example 67 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.

the class RoutingTest method testRoutingForRandomMasterOrDataNode.

@Test
public void testRoutingForRandomMasterOrDataNode() throws IOException {
    Map<String, String> attr = Map.of();
    Set<DiscoveryNodeRole> master_and_data = Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE);
    DiscoveryNode local = new DiscoveryNode("client_node_1", buildNewFakeTransportAddress(), attr, Set.of(), null);
    DiscoveryNodes nodes = new DiscoveryNodes.Builder().add(new DiscoveryNode("data_master_node_1", buildNewFakeTransportAddress(), attr, master_and_data, null)).add(new DiscoveryNode("data_master_node_2", buildNewFakeTransportAddress(), attr, master_and_data, null)).add(local).add(new DiscoveryNode("client_node_2", buildNewFakeTransportAddress(), attr, Set.of(), null)).add(new DiscoveryNode("client_node_3", buildNewFakeTransportAddress(), attr, Set.of(), null)).localNodeId(local.getId()).build();
    RoutingProvider routingProvider = new RoutingProvider(Randomness.get().nextInt(), Collections.emptyList());
    Routing routing = routingProvider.forRandomMasterOrDataNode(new RelationName("doc", "table"), nodes);
    assertThat(routing.locations().keySet(), anyOf(contains("data_master_node_1"), contains("data_master_node_2")));
    Routing routing2 = routingProvider.forRandomMasterOrDataNode(new RelationName("doc", "table"), nodes);
    assertThat("routingProvider is seeded and must return deterministic routing", routing.locations(), equalTo(routing2.locations()));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Test(org.junit.Test)

Example 68 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.

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.elasticsearch.action.support.nodes.BaseNodeResponse) FailedNodeException(org.elasticsearch.action.FailedNodeException) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 69 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.

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.elasticsearch.action.support.nodes.BaseNodeResponse) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 70 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.

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.elasticsearch.action.support.nodes.BaseNodeResponse) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Aggregations

DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)129 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)74 ClusterState (org.elasticsearch.cluster.ClusterState)45 Settings (org.elasticsearch.common.settings.Settings)37 ArrayList (java.util.ArrayList)32 IOException (java.io.IOException)27 HashSet (java.util.HashSet)25 List (java.util.List)24 Map (java.util.Map)23 TransportService (org.elasticsearch.transport.TransportService)23 Version (org.elasticsearch.Version)22 HashMap (java.util.HashMap)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)20 Set (java.util.Set)19 TransportException (org.elasticsearch.transport.TransportException)19 Collections (java.util.Collections)18 ThreadPool (org.elasticsearch.threadpool.ThreadPool)18 CountDownLatch (java.util.concurrent.CountDownLatch)16 Collectors (java.util.stream.Collectors)16