use of org.elasticsearch.action.support.PlainActionFuture in project crate by crate.
the class BlobRecoveryHandler method sendStartRecoveryRequest.
private void sendStartRecoveryRequest() {
var listener = new PlainActionFuture<TransportResponse>();
transportService.sendRequest(request.targetNode(), BlobRecoveryTarget.Actions.START_RECOVERY, new BlobStartRecoveryRequest(request.recoveryId(), request.shardId()), TransportRequestOptions.EMPTY, new ActionListenerResponseHandler<>(listener, in -> TransportResponse.Empty.INSTANCE));
listener.actionGet();
}
use of org.elasticsearch.action.support.PlainActionFuture in project crate by crate.
the class BlobRecoveryHandler method sendFinalizeRecoveryRequest.
private void sendFinalizeRecoveryRequest() {
var listener = new PlainActionFuture<TransportResponse>();
transportService.sendRequest(request.targetNode(), BlobRecoveryTarget.Actions.FINALIZE_RECOVERY, new BlobFinalizeRecoveryRequest(request.recoveryId()), TransportRequestOptions.EMPTY, new ActionListenerResponseHandler<>(listener, in -> TransportResponse.Empty.INSTANCE));
listener.actionGet();
}
use of org.elasticsearch.action.support.PlainActionFuture in project crate by crate.
the class TransportVerifyShardBeforeCloseActionTests method testUnavailableShardsMarkedAsStale.
@Test
public void testUnavailableShardsMarkedAsStale() throws Exception {
String index = "test";
ShardId shardId = new ShardId(index, "_na_", 0);
int nbReplicas = randomIntBetween(1, 10);
ShardRoutingState[] replicaStates = new ShardRoutingState[nbReplicas];
Arrays.fill(replicaStates, ShardRoutingState.STARTED);
final ClusterState clusterState = state(index, true, ShardRoutingState.STARTED, replicaStates);
setState(clusterService, clusterState);
IndexShardRoutingTable shardRoutingTable = clusterState.routingTable().index(index).shard(shardId.id());
IndexMetadata indexMetaData = clusterState.getMetadata().index(index);
ShardRouting primaryRouting = shardRoutingTable.primaryShard();
long primaryTerm = indexMetaData.primaryTerm(0);
Set<String> inSyncAllocationIds = indexMetaData.inSyncAllocationIds(0);
Set<String> trackedShards = shardRoutingTable.getAllAllocationIds();
List<ShardRouting> unavailableShards = randomSubsetOf(randomIntBetween(1, nbReplicas), shardRoutingTable.replicaShards());
IndexShardRoutingTable.Builder shardRoutingTableBuilder = new IndexShardRoutingTable.Builder(shardRoutingTable);
unavailableShards.forEach(shardRoutingTableBuilder::removeShard);
shardRoutingTable = shardRoutingTableBuilder.build();
ReplicationGroup replicationGroup = new ReplicationGroup(shardRoutingTable, inSyncAllocationIds, trackedShards);
assertThat(replicationGroup.getUnavailableInSyncShards().size(), greaterThan(0));
PlainActionFuture<PrimaryResult> listener = new PlainActionFuture<>();
TransportVerifyShardBeforeCloseAction.ShardRequest request = new TransportVerifyShardBeforeCloseAction.ShardRequest(shardId, false, clusterBlock);
ReplicationOperation.Replicas<TransportVerifyShardBeforeCloseAction.ShardRequest> proxy = action.newReplicasProxy();
ReplicationOperation<TransportVerifyShardBeforeCloseAction.ShardRequest, TransportVerifyShardBeforeCloseAction.ShardRequest, PrimaryResult> operation = new ReplicationOperation<>(request, createPrimary(primaryRouting, replicationGroup), listener, proxy, logger, "test", primaryTerm);
operation.execute();
CapturingTransport.CapturedRequest[] capturedRequests = transport.getCapturedRequestsAndClear();
assertThat(capturedRequests.length, equalTo(nbReplicas));
for (CapturingTransport.CapturedRequest capturedRequest : capturedRequests) {
String actionName = capturedRequest.action;
if (actionName.startsWith(ShardStateAction.SHARD_FAILED_ACTION_NAME)) {
assertThat(capturedRequest.request, instanceOf(ShardStateAction.FailedShardEntry.class));
String allocationId = ((ShardStateAction.FailedShardEntry) capturedRequest.request).getAllocationId();
assertTrue(unavailableShards.stream().anyMatch(shardRouting -> shardRouting.allocationId().getId().equals(allocationId)));
transport.handleResponse(capturedRequest.requestId, TransportResponse.Empty.INSTANCE);
} else if (actionName.startsWith(TransportVerifyShardBeforeCloseAction.NAME)) {
assertThat(capturedRequest.request, instanceOf(ConcreteShardRequest.class));
String allocationId = ((ConcreteShardRequest) capturedRequest.request).getTargetAllocationID();
assertFalse(unavailableShards.stream().anyMatch(shardRouting -> shardRouting.allocationId().getId().equals(allocationId)));
assertTrue(inSyncAllocationIds.stream().anyMatch(inSyncAllocationId -> inSyncAllocationId.equals(allocationId)));
transport.handleResponse(capturedRequest.requestId, new TransportReplicationAction.ReplicaResponse(0L, 0L));
} else {
fail("Test does not support action " + capturedRequest.action);
}
}
ReplicationResponse.ShardInfo shardInfo = listener.get().getShardInfo();
assertThat(shardInfo.getFailed(), equalTo(0));
assertThat(shardInfo.getFailures(), arrayWithSize(0));
assertThat(shardInfo.getSuccessful(), equalTo(1 + nbReplicas - unavailableShards.size()));
}
use of org.elasticsearch.action.support.PlainActionFuture in project crate by crate.
the class NodeConnectionsServiceTests method testConnectAndDisconnect.
public void testConnectAndDisconnect() throws Exception {
final NodeConnectionsService service = new NodeConnectionsService(Settings.EMPTY, threadPool, transportService);
final AtomicBoolean stopReconnecting = new AtomicBoolean();
final Thread reconnectionThread = new Thread(() -> {
while (stopReconnecting.get() == false) {
final PlainActionFuture<Void> future = new PlainActionFuture<>();
service.ensureConnections(() -> future.onResponse(null));
future.actionGet();
}
}, "reconnection thread");
reconnectionThread.start();
try {
final List<DiscoveryNode> allNodes = generateNodes();
for (int iteration = 0; iteration < 3; iteration++) {
final boolean isDisrupting = randomBoolean();
if (isDisrupting == false) {
// if the previous iteration was a disrupting one then there could still be some pending disconnections which would
// prevent us from asserting that all nodes are connected in this iteration without this call.
ensureConnections(service);
}
final AtomicBoolean stopDisrupting = new AtomicBoolean();
final Thread disruptionThread = new Thread(() -> {
while (isDisrupting && stopDisrupting.get() == false) {
transportService.disconnectFromNode(randomFrom(allNodes));
}
}, "disruption thread " + iteration);
disruptionThread.start();
final DiscoveryNodes nodes = discoveryNodesFromList(randomSubsetOf(allNodes));
final PlainActionFuture<Void> future = new PlainActionFuture<>();
service.connectToNodes(nodes, () -> future.onResponse(null));
future.actionGet();
if (isDisrupting == false) {
assertConnected(transportService, nodes);
}
service.disconnectFromNodesExcept(nodes);
assertTrue(stopDisrupting.compareAndSet(false, true));
disruptionThread.join();
if (randomBoolean()) {
// sometimes do not wait for the disconnections to complete before starting the next connections
if (usually()) {
ensureConnections(service);
assertConnectedExactlyToNodes(nodes);
} else {
assertBusy(() -> assertConnectedExactlyToNodes(nodes));
}
}
}
} finally {
assertTrue(stopReconnecting.compareAndSet(false, true));
reconnectionThread.join();
}
ensureConnections(service);
}
use of org.elasticsearch.action.support.PlainActionFuture in project crate by crate.
the class NodeConnectionsServiceTests method testOnlyBlocksOnConnectionsToNewNodes.
public void testOnlyBlocksOnConnectionsToNewNodes() throws Exception {
final NodeConnectionsService service = new NodeConnectionsService(Settings.EMPTY, threadPool, transportService);
// connect to one node
final DiscoveryNode node0 = new DiscoveryNode("node0", buildNewFakeTransportAddress(), Version.CURRENT);
final DiscoveryNodes nodes0 = DiscoveryNodes.builder().add(node0).build();
final PlainActionFuture<Void> future0 = new PlainActionFuture<>();
service.connectToNodes(nodes0, () -> future0.onResponse(null));
future0.actionGet();
assertConnectedExactlyToNodes(nodes0);
// connection attempts to node0 block indefinitely
final CyclicBarrier connectionBarrier = new CyclicBarrier(2);
try {
nodeConnectionBlocks.put(node0, connectionBarrier::await);
transportService.disconnectFromNode(node0);
// can still connect to another node without blocking
final DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Version.CURRENT);
final DiscoveryNodes nodes1 = DiscoveryNodes.builder().add(node1).build();
final DiscoveryNodes nodes01 = DiscoveryNodes.builder(nodes0).add(node1).build();
final PlainActionFuture<Void> future1 = new PlainActionFuture<>();
service.connectToNodes(nodes01, () -> future1.onResponse(null));
future1.actionGet();
assertConnectedExactlyToNodes(nodes1);
// can also disconnect from node0 without blocking
final PlainActionFuture<Void> future2 = new PlainActionFuture<>();
service.connectToNodes(nodes1, () -> future2.onResponse(null));
future2.actionGet();
service.disconnectFromNodesExcept(nodes1);
assertConnectedExactlyToNodes(nodes1);
// however, now node0 is considered to be a new node so we will block on a subsequent attempt to connect to it
final PlainActionFuture<Void> future3 = new PlainActionFuture<>();
service.connectToNodes(nodes01, () -> future3.onResponse(null));
expectThrows(ElasticsearchTimeoutException.class, () -> future3.actionGet(timeValueMillis(scaledRandomIntBetween(1, 1000))));
// once the connection is unblocked we successfully connect to it.
connectionBarrier.await(10, TimeUnit.SECONDS);
nodeConnectionBlocks.clear();
future3.actionGet();
assertConnectedExactlyToNodes(nodes01);
// if we disconnect from a node while blocked trying to connect to it then we do eventually disconnect from it
nodeConnectionBlocks.put(node0, connectionBarrier::await);
transportService.disconnectFromNode(node0);
final PlainActionFuture<Void> future4 = new PlainActionFuture<>();
service.connectToNodes(nodes01, () -> future4.onResponse(null));
future4.actionGet();
assertConnectedExactlyToNodes(nodes1);
service.disconnectFromNodesExcept(nodes1);
connectionBarrier.await();
if (randomBoolean()) {
// assertBusy because the connection completes before disconnecting, so we might briefly observe a connection to node0
assertBusy(() -> assertConnectedExactlyToNodes(nodes1));
}
// use ensureConnections() to wait until the service is idle
ensureConnections(service);
assertConnectedExactlyToNodes(nodes1);
// if we disconnect from a node while blocked trying to connect to it then the listener is notified
final PlainActionFuture<Void> future6 = new PlainActionFuture<>();
service.connectToNodes(nodes01, () -> future6.onResponse(null));
expectThrows(ElasticsearchTimeoutException.class, () -> future6.actionGet(timeValueMillis(scaledRandomIntBetween(1, 1000))));
service.disconnectFromNodesExcept(nodes1);
// completed even though the connection attempt is still blocked
future6.actionGet();
assertConnectedExactlyToNodes(nodes1);
connectionBarrier.await(10, TimeUnit.SECONDS);
nodeConnectionBlocks.clear();
ensureConnections(service);
assertConnectedExactlyToNodes(nodes1);
} finally {
nodeConnectionBlocks.clear();
connectionBarrier.reset();
}
}
Aggregations