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;
}
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;
}
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));
}
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());
}
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);
}
Aggregations