Search in sources :

Example 41 with DiscoveryNodes

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

the class BlobTransferTarget method restoreTransferStatus.

private BlobTransferStatus restoreTransferStatus(PutChunkReplicaRequest request) {
    LOGGER.trace("Restoring transferContext for PutChunkReplicaRequest with transferId {}", request.transferId);
    DiscoveryNodes nodes = clusterService.state().getNodes();
    DiscoveryNode recipientNodeId = nodes.get(request.sourceNodeId);
    String senderNodeId = nodes.getLocalNodeId();
    var listener = new PlainActionFuture<BlobTransferInfoResponse>();
    transportService.sendRequest(recipientNodeId, BlobHeadRequestHandler.Actions.GET_TRANSFER_INFO, new BlobInfoRequest(senderNodeId, request.transferId), TransportRequestOptions.EMPTY, new ActionListenerResponseHandler<>(listener, BlobTransferInfoResponse::new));
    BlobTransferInfoResponse transferInfoResponse = listener.actionGet();
    BlobShard blobShard = blobIndicesService.blobShardSafe(request.shardId());
    DigestBlob digestBlob = DigestBlob.resumeTransfer(blobShard.blobContainer(), transferInfoResponse.digest, request.transferId, request.currentPos);
    assert digestBlob != null : "DigestBlob couldn't be restored";
    BlobTransferStatus status;
    status = new BlobTransferStatus(request.shardId(), request.transferId, digestBlob);
    activeTransfers.put(request.transferId, status);
    LOGGER.trace("Restored transferStatus for digest {} transferId: {}", transferInfoResponse.digest, request.transferId);
    var getBlobHeadListener = new PlainActionFuture<>();
    transportService.sendRequest(recipientNodeId, BlobHeadRequestHandler.Actions.GET_BLOB_HEAD, new GetBlobHeadRequest(senderNodeId, request.transferId(), request.currentPos), TransportRequestOptions.EMPTY, new ActionListenerResponseHandler<>(getBlobHeadListener, in -> TransportResponse.Empty.INSTANCE));
    getBlobHeadListener.actionGet();
    return status;
}
Also used : GetBlobHeadRequest(io.crate.blob.transfer.GetBlobHeadRequest) ConcurrentCollections(org.elasticsearch.common.util.concurrent.ConcurrentCollections) BlobShard(io.crate.blob.v2.BlobShard) ClusterService(org.elasticsearch.cluster.service.ClusterService) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(org.elasticsearch.common.inject.Inject) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportResponse(org.elasticsearch.transport.TransportResponse) TransportService(org.elasticsearch.transport.TransportService) DigestMismatchException(io.crate.blob.exceptions.DigestMismatchException) BlobHeadRequestHandler(io.crate.blob.transfer.BlobHeadRequestHandler) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) IOUtils(org.apache.lucene.util.IOUtils) UUID(java.util.UUID) BlobAlreadyExistsException(io.crate.blob.exceptions.BlobAlreadyExistsException) BlobInfoRequest(io.crate.blob.transfer.BlobInfoRequest) BlobIndicesService(io.crate.blob.v2.BlobIndicesService) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TimeValue(io.crate.common.unit.TimeValue) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) BlobTransferInfoResponse(io.crate.blob.transfer.BlobTransferInfoResponse) LogManager(org.apache.logging.log4j.LogManager) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) GetBlobHeadRequest(io.crate.blob.transfer.GetBlobHeadRequest) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) BlobTransferInfoResponse(io.crate.blob.transfer.BlobTransferInfoResponse) BlobInfoRequest(io.crate.blob.transfer.BlobInfoRequest) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) BlobShard(io.crate.blob.v2.BlobShard) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 42 with DiscoveryNodes

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

the class AddVotingConfigExclusionsRequest method resolveVotingConfigExclusions.

Set<VotingConfigExclusion> resolveVotingConfigExclusions(ClusterState currentState) {
    final DiscoveryNodes allNodes = currentState.nodes();
    final Set<VotingConfigExclusion> resolvedNodes = Arrays.stream(allNodes.resolveNodes(nodeDescriptions)).map(allNodes::get).filter(DiscoveryNode::isMasterEligibleNode).map(VotingConfigExclusion::new).collect(Collectors.toSet());
    if (resolvedNodes.isEmpty()) {
        throw new IllegalArgumentException("add voting config exclusions request for " + Arrays.asList(nodeDescriptions) + " matched no master-eligible nodes");
    }
    resolvedNodes.removeIf(n -> currentState.getVotingConfigExclusions().contains(n));
    return resolvedNodes;
}
Also used : VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 43 with DiscoveryNodes

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

the class FollowersCheckerTests method testFailsNodeThatDisconnects.

public void testFailsNodeThatDisconnects() {
    final DiscoveryNode localNode = new DiscoveryNode("local-node", buildNewFakeTransportAddress(), Version.CURRENT);
    final DiscoveryNode otherNode = new DiscoveryNode("other-node", buildNewFakeTransportAddress(), Version.CURRENT);
    final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), localNode.getName()).build();
    final DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    final MockTransport mockTransport = new MockTransport() {

        @Override
        protected void onSendRequest(long requestId, String action, TransportRequest request, DiscoveryNode node) {
            assertFalse(node.equals(localNode));
            if (action.equals(HANDSHAKE_ACTION_NAME)) {
                handleResponse(requestId, new TransportService.HandshakeResponse(node, ClusterName.DEFAULT, Version.CURRENT));
                return;
            }
            deterministicTaskQueue.scheduleNow(new Runnable() {

                @Override
                public void run() {
                    handleResponse(requestId, Empty.INSTANCE);
                }

                @Override
                public String toString() {
                    return "sending response to [" + action + "][" + requestId + "] from " + node;
                }
            });
        }
    };
    final TransportService transportService = mockTransport.createTransportService(settings, deterministicTaskQueue.getThreadPool(), boundTransportAddress -> localNode, null);
    transportService.start();
    transportService.acceptIncomingRequests();
    final AtomicBoolean nodeFailed = new AtomicBoolean();
    final FollowersChecker followersChecker = new FollowersChecker(settings, transportService, fcr -> {
        assert false : fcr;
    }, (node, reason) -> {
        assertTrue(nodeFailed.compareAndSet(false, true));
        assertThat(reason, equalTo("disconnected"));
    });
    DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().add(localNode).add(otherNode).localNodeId(localNode.getId()).build();
    followersChecker.setCurrentNodes(discoveryNodes);
    AbstractSimpleTransportTestCase.connectToNode(transportService, otherNode);
    transportService.disconnectFromNode(otherNode);
    deterministicTaskQueue.runAllRunnableTasks();
    assertTrue(nodeFailed.get());
    assertThat(followersChecker.getFaultyNodes(), contains(otherNode));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportRequest(org.elasticsearch.transport.TransportRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransportService(org.elasticsearch.transport.TransportService) MockTransport(org.elasticsearch.test.transport.MockTransport) Settings(org.elasticsearch.common.settings.Settings) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 44 with DiscoveryNodes

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

the class FollowersCheckerTests method testChecksExpectedNodes.

public void testChecksExpectedNodes() {
    final DiscoveryNode localNode = new DiscoveryNode("local-node", buildNewFakeTransportAddress(), Version.CURRENT);
    final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), localNode.getName()).build();
    final DiscoveryNodes[] discoveryNodesHolder = new DiscoveryNodes[] { DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId()).build() };
    final DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    final Set<DiscoveryNode> checkedNodes = new HashSet<>();
    final AtomicInteger checkCount = new AtomicInteger();
    final MockTransport mockTransport = new MockTransport() {

        @Override
        protected void onSendRequest(long requestId, String action, TransportRequest request, DiscoveryNode node) {
            assertThat(action, equalTo(FOLLOWER_CHECK_ACTION_NAME));
            assertThat(request, instanceOf(FollowerCheckRequest.class));
            assertTrue(discoveryNodesHolder[0].nodeExists(node));
            assertThat(node, not(equalTo(localNode)));
            checkedNodes.add(node);
            checkCount.incrementAndGet();
            handleResponse(requestId, Empty.INSTANCE);
        }
    };
    final TransportService transportService = mockTransport.createTransportService(settings, deterministicTaskQueue.getThreadPool(), boundTransportAddress -> localNode, null);
    transportService.start();
    transportService.acceptIncomingRequests();
    final FollowersChecker followersChecker = new FollowersChecker(settings, transportService, fcr -> {
        assert false : fcr;
    }, (node, reason) -> {
        assert false : node;
    });
    followersChecker.setCurrentNodes(discoveryNodesHolder[0]);
    deterministicTaskQueue.runAllTasks();
    assertThat(checkedNodes, empty());
    assertThat(followersChecker.getFaultyNodes(), empty());
    final DiscoveryNode otherNode1 = new DiscoveryNode("other-node-1", buildNewFakeTransportAddress(), Version.CURRENT);
    followersChecker.setCurrentNodes(discoveryNodesHolder[0] = DiscoveryNodes.builder(discoveryNodesHolder[0]).add(otherNode1).build());
    while (checkCount.get() < 10) {
        if (deterministicTaskQueue.hasRunnableTasks()) {
            deterministicTaskQueue.runRandomTask();
        } else {
            deterministicTaskQueue.advanceTime();
        }
    }
    assertThat(checkedNodes, contains(otherNode1));
    assertThat(followersChecker.getFaultyNodes(), empty());
    checkedNodes.clear();
    checkCount.set(0);
    final DiscoveryNode otherNode2 = new DiscoveryNode("other-node-2", buildNewFakeTransportAddress(), Version.CURRENT);
    followersChecker.setCurrentNodes(discoveryNodesHolder[0] = DiscoveryNodes.builder(discoveryNodesHolder[0]).add(otherNode2).build());
    while (checkCount.get() < 10) {
        if (deterministicTaskQueue.hasRunnableTasks()) {
            deterministicTaskQueue.runRandomTask();
        } else {
            deterministicTaskQueue.advanceTime();
        }
    }
    assertThat(checkedNodes, containsInAnyOrder(otherNode1, otherNode2));
    assertThat(followersChecker.getFaultyNodes(), empty());
    checkedNodes.clear();
    checkCount.set(0);
    followersChecker.setCurrentNodes(discoveryNodesHolder[0] = DiscoveryNodes.builder(discoveryNodesHolder[0]).remove(otherNode1).build());
    while (checkCount.get() < 10) {
        if (deterministicTaskQueue.hasRunnableTasks()) {
            deterministicTaskQueue.runRandomTask();
        } else {
            deterministicTaskQueue.advanceTime();
        }
    }
    assertThat(checkedNodes, contains(otherNode2));
    assertThat(followersChecker.getFaultyNodes(), empty());
    checkedNodes.clear();
    followersChecker.clearCurrentNodes();
    deterministicTaskQueue.runAllTasks();
    assertThat(checkedNodes, empty());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportRequest(org.elasticsearch.transport.TransportRequest) FollowerCheckRequest(org.elasticsearch.cluster.coordination.FollowersChecker.FollowerCheckRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransportService(org.elasticsearch.transport.TransportService) MockTransport(org.elasticsearch.test.transport.MockTransport) Settings(org.elasticsearch.common.settings.Settings) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) HashSet(java.util.HashSet)

Example 45 with DiscoveryNodes

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

the class FollowersCheckerTests method testPreferMasterNodes.

public void testPreferMasterNodes() {
    List<DiscoveryNode> nodes = randomNodes(10);
    DiscoveryNodes.Builder discoNodesBuilder = DiscoveryNodes.builder();
    nodes.forEach(dn -> discoNodesBuilder.add(dn));
    DiscoveryNodes discoveryNodes = discoNodesBuilder.localNodeId(nodes.get(0).getId()).build();
    CapturingTransport capturingTransport = new CapturingTransport();
    final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), nodes.get(0).getName()).build();
    final DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    TransportService transportService = capturingTransport.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), x -> nodes.get(0), null);
    final FollowersChecker followersChecker = new FollowersChecker(Settings.EMPTY, transportService, fcr -> {
        assert false : fcr;
    }, (node, reason) -> {
        assert false : node;
    });
    followersChecker.setCurrentNodes(discoveryNodes);
    List<DiscoveryNode> followerTargets = Stream.of(capturingTransport.getCapturedRequestsAndClear()).map(cr -> cr.node).collect(Collectors.toList());
    List<DiscoveryNode> sortedFollowerTargets = new ArrayList<>(followerTargets);
    Collections.sort(sortedFollowerTargets, Comparator.comparing(n -> n.isMasterEligibleNode() == false));
    assertEquals(sortedFollowerTargets, followerTargets);
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) HANDSHAKE_ACTION_NAME(org.elasticsearch.transport.TransportService.HANDSHAKE_ACTION_NAME) TransportRequest(org.elasticsearch.transport.TransportRequest) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) Matchers.not(org.hamcrest.Matchers.not) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) AbstractSimpleTransportTestCase(org.elasticsearch.transport.AbstractSimpleTransportTestCase) FollowerCheckRequest(org.elasticsearch.cluster.coordination.FollowersChecker.FollowerCheckRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mode(org.elasticsearch.cluster.coordination.Coordinator.Mode) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ClusterName(org.elasticsearch.cluster.ClusterName) FOLLOWER_CHECK_RETRY_COUNT_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_RETRY_COUNT_SETTING) EqualsHashCodeTestUtils(org.elasticsearch.test.EqualsHashCodeTestUtils) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) Version(org.elasticsearch.Version) Stream(java.util.stream.Stream) FOLLOWER_CHECK_ACTION_NAME(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_ACTION_NAME) NODE_NAME_SETTING(org.elasticsearch.node.Node.NODE_NAME_SETTING) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) TransportException(org.elasticsearch.transport.TransportException) Empty(org.elasticsearch.transport.TransportResponse.Empty) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Names(org.elasticsearch.threadpool.ThreadPool.Names) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) CopyFunction(org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) FOLLOWER_CHECK_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_TIMEOUT_SETTING) TransportResponse(org.elasticsearch.transport.TransportResponse) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Matchers.empty(org.hamcrest.Matchers.empty) MockTransport(org.elasticsearch.test.transport.MockTransport) FOLLOWER_CHECK_INTERVAL_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_INTERVAL_SETTING) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Comparator(java.util.Comparator) Collections(java.util.Collections) Builder(org.elasticsearch.common.settings.Settings.Builder) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportService(org.elasticsearch.transport.TransportService) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ArrayList(java.util.ArrayList) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Settings(org.elasticsearch.common.settings.Settings)

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