Search in sources :

Example 1 with DiscoveryNodeRole

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

the class NodeConnectionsServiceTests method generateNodes.

private List<DiscoveryNode> generateNodes() {
    List<DiscoveryNode> nodes = new ArrayList<>();
    for (int i = randomIntBetween(20, 50); i > 0; i--) {
        Set<DiscoveryNodeRole> roles = new HashSet<>(randomSubsetOf(DiscoveryNodeRole.BUILT_IN_ROLES));
        nodes.add(new DiscoveryNode("node_" + i, "" + i, buildNewFakeTransportAddress(), Collections.emptyMap(), roles, Version.CURRENT));
    }
    return nodes;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 2 with DiscoveryNodeRole

use of org.elasticsearch.cluster.node.DiscoveryNodeRole 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 3 with DiscoveryNodeRole

use of org.elasticsearch.cluster.node.DiscoveryNodeRole 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 4 with DiscoveryNodeRole

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

the class TransportReplicationAllPermitsAcquisitionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    globalBlock = randomBoolean();
    RestStatus restStatus = randomFrom(RestStatus.values());
    block = new ClusterBlock(randomIntBetween(1, 10), randomAlphaOfLength(5), false, true, false, restStatus, ClusterBlockLevel.ALL);
    clusterService = createClusterService(threadPool);
    final ClusterState.Builder state = ClusterState.builder(clusterService.state());
    Set<DiscoveryNodeRole> roles = new HashSet<>(DiscoveryNodeRole.BUILT_IN_ROLES);
    DiscoveryNode node1 = new DiscoveryNode("_name1", "_node1", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("_name2", "_node2", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
    state.nodes(DiscoveryNodes.builder().add(node1).add(node2).localNodeId(node1.getId()).masterNodeId(node1.getId()));
    shardId = new ShardId("index", UUID.randomUUID().toString(), 0);
    ShardRouting shardRouting = newShardRouting(shardId, node1.getId(), true, ShardRoutingState.INITIALIZING, RecoverySource.EmptyStoreRecoverySource.INSTANCE);
    Settings indexSettings = Settings.builder().put(SETTING_VERSION_CREATED, Version.CURRENT).put(SETTING_INDEX_UUID, shardId.getIndex().getUUID()).put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 1).put(SETTING_CREATION_DATE, System.currentTimeMillis()).build();
    primary = newStartedShard(p -> newShard(shardRouting, indexSettings, new InternalEngineFactory()), true);
    for (int i = 0; i < 10; i++) {
        final String id = Integer.toString(i);
        indexDoc(primary, id, "{\"value\":" + id + "}");
    }
    IndexMetadata indexMetadata = IndexMetadata.builder(shardId.getIndexName()).settings(indexSettings).primaryTerm(shardId.id(), primary.getOperationPrimaryTerm()).putMapping("default", "{ \"properties\": { \"value\":  { \"type\": \"short\"}}}").build();
    state.metadata(Metadata.builder().put(indexMetadata, false).generateClusterUuidIfNeeded());
    replica = newShard(primary.shardId(), false, node2.getId(), indexMetadata, null);
    recoverReplica(replica, primary, true);
    IndexRoutingTable.Builder routing = IndexRoutingTable.builder(indexMetadata.getIndex());
    routing.addIndexShard(new IndexShardRoutingTable.Builder(shardId).addShard(primary.routingEntry()).build());
    state.routingTable(RoutingTable.builder().add(routing.build()).build());
    setState(clusterService, state.build());
    final Settings transportSettings = Settings.builder().put("node.name", node1.getId()).build();
    MockTransport transport = new MockTransport() {

        @Override
        protected void onSendRequest(long requestId, String action, TransportRequest request, DiscoveryNode node) {
            assertThat(action, allOf(startsWith("cluster:admin/test/"), endsWith("[r]")));
            assertThat(node, equalTo(node2));
            // node2 doesn't really exist, but we are performing some trickery in mockIndicesService() to pretend that node1 holds both
            // the primary and the replica, so redirect the request back to node1.
            transportService.sendRequest(transportService.getLocalNode(), action, request, new TransportResponseHandler<TransportReplicationAction.ReplicaResponse>() {

                @Override
                public ReplicaResponse read(StreamInput in) throws IOException {
                    return new ReplicaResponse(in);
                }

                @SuppressWarnings("unchecked")
                private TransportResponseHandler<TransportReplicationAction.ReplicaResponse> getResponseHandler() {
                    return (TransportResponseHandler<TransportReplicationAction.ReplicaResponse>) getResponseHandlers().onResponseReceived(requestId, TransportMessageListener.NOOP_LISTENER);
                }

                @Override
                public void handleResponse(TransportReplicationAction.ReplicaResponse response) {
                    getResponseHandler().handleResponse(response);
                }

                @Override
                public void handleException(TransportException exp) {
                    getResponseHandler().handleException(exp);
                }

                @Override
                public String executor() {
                    return ThreadPool.Names.SAME;
                }
            });
        }
    };
    transportService = transport.createTransportService(transportSettings, threadPool, bta -> node1, null);
    transportService.start();
    transportService.acceptIncomingRequests();
    shardStateAction = new ShardStateAction(clusterService, transportService, null, null);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) TransportRequest(org.elasticsearch.transport.TransportRequest) SETTING_VERSION_CREATED(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ClusterState(org.elasticsearch.cluster.ClusterState) TransportMessageListener(org.elasticsearch.transport.TransportMessageListener) Settings(org.elasticsearch.common.settings.Settings) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) After(org.junit.After) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ThreadPool(org.elasticsearch.threadpool.ThreadPool) InternalEngineFactory(org.elasticsearch.index.engine.InternalEngineFactory) Releasable(org.elasticsearch.common.lease.Releasable) CyclicBarrier(java.util.concurrent.CyclicBarrier) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) Set(java.util.Set) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) UUID(java.util.UUID) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Objects(java.util.Objects) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) RecoverySource(org.elasticsearch.cluster.routing.RecoverySource) List(java.util.List) Version(org.elasticsearch.Version) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) RestStatus(org.elasticsearch.rest.RestStatus) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) SETTING_INDEX_UUID(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_INDEX_UUID) TransportException(org.elasticsearch.transport.TransportException) Matchers.endsWith(org.hamcrest.Matchers.endsWith) Mockito.mock(org.mockito.Mockito.mock) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) SETTING_NUMBER_OF_SHARDS(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS) TransportChannel(org.elasticsearch.transport.TransportChannel) ClusterService(org.elasticsearch.cluster.service.ClusterService) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) ArrayList(java.util.ArrayList) TestShardRouting.newShardRouting(org.elasticsearch.cluster.routing.TestShardRouting.newShardRouting) HashSet(java.util.HashSet) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) SETTING_NUMBER_OF_REPLICAS(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS) ReplicaResponse(org.elasticsearch.action.support.replication.TransportReplicationAction.ReplicaResponse) TransportResponse(org.elasticsearch.transport.TransportResponse) IndicesService(org.elasticsearch.indices.IndicesService) TransportService(org.elasticsearch.transport.TransportService) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) SetOnce(org.apache.lucene.util.SetOnce) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) MockTransport(org.elasticsearch.test.transport.MockTransport) Test(org.junit.Test) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) SETTING_CREATION_DATE(org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_CREATION_DATE) Mockito.when(org.mockito.Mockito.when) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IndexShardTestCase(org.elasticsearch.index.shard.IndexShardTestCase) Matchers.hasItem(org.hamcrest.Matchers.hasItem) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ActionListener(org.elasticsearch.action.ActionListener) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ShardId(org.elasticsearch.index.shard.ShardId) InternalEngineFactory(org.elasticsearch.index.engine.InternalEngineFactory) MockTransport(org.elasticsearch.test.transport.MockTransport) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Settings(org.elasticsearch.common.settings.Settings) HashSet(java.util.HashSet) ClusterState(org.elasticsearch.cluster.ClusterState) TransportRequest(org.elasticsearch.transport.TransportRequest) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException) RestStatus(org.elasticsearch.rest.RestStatus) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ReplicaResponse(org.elasticsearch.action.support.replication.TransportReplicationAction.ReplicaResponse) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting.newShardRouting(org.elasticsearch.cluster.routing.TestShardRouting.newShardRouting) ReplicaResponse(org.elasticsearch.action.support.replication.TransportReplicationAction.ReplicaResponse) Before(org.junit.Before)

Example 5 with DiscoveryNodeRole

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

the class NodeJoinTests method newNode.

protected DiscoveryNode newNode(int i, boolean master) {
    final Set<DiscoveryNodeRole> roles;
    if (master) {
        roles = Set.of(DiscoveryNodeRole.MASTER_ROLE);
    } else {
        roles = Set.of();
    }
    final String prefix = master ? "master_" : "data_";
    return new DiscoveryNode(prefix + i, i + "", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)6 DiscoveryNodeRole (org.elasticsearch.cluster.node.DiscoveryNodeRole)6 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 IOException (java.io.IOException)2 List (java.util.List)2 Set (java.util.Set)2 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)2 ClusterService (org.elasticsearch.cluster.service.ClusterService)2 Settings (org.elasticsearch.common.settings.Settings)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Test (org.junit.Test)2 IOUtils (io.crate.common.io.IOUtils)1 TimeValue (io.crate.common.unit.TimeValue)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1