use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.
the class DedicatedClusterSnapshotRestoreIT method testAbortWaitsOnDataNode.
public void testAbortWaitsOnDataNode() throws Exception {
internalCluster().startMasterOnlyNode();
final String dataNodeName = internalCluster().startDataOnlyNode();
final String indexName = "test-index";
createIndex(indexName);
index(indexName, "_doc", "some_id", "foo", "bar");
final String otherDataNode = internalCluster().startDataOnlyNode();
final String repoName = "test-repo";
createRepository(repoName, "mock");
blockAllDataNodes(repoName);
final String snapshotName = "test-snap";
final ActionFuture<CreateSnapshotResponse> snapshotResponse = startFullSnapshot(repoName, snapshotName);
waitForBlock(dataNodeName, repoName, TimeValue.timeValueSeconds(30L));
final AtomicBoolean blocked = new AtomicBoolean(true);
final TransportService transportService = internalCluster().getInstance(TransportService.class, otherDataNode);
transportService.addMessageListener(new TransportMessageListener() {
@Override
public void onRequestSent(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions finalOptions) {
if (blocked.get() && action.equals(SnapshotsService.UPDATE_SNAPSHOT_STATUS_ACTION_NAME)) {
throw new AssertionError("Node had no assigned shard snapshots so it shouldn't send out shard state updates");
}
}
});
logger.info("--> abort snapshot");
final ActionFuture<AcknowledgedResponse> deleteResponse = startDeleteSnapshot(repoName, snapshotName);
awaitClusterState(otherDataNode, state -> state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY).entries().stream().anyMatch(entry -> entry.state() == SnapshotsInProgress.State.ABORTED));
assertFalse("delete should not be able to finish until data node is unblocked", deleteResponse.isDone());
blocked.set(false);
unblockAllDataNodes(repoName);
assertAcked(deleteResponse.get());
assertThat(snapshotResponse.get().getSnapshotInfo().state(), is(SnapshotState.FAILED));
}
use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.
the class RemoteRecoveryTargetHandler method receiveFileInfo.
@Override
public void receiveFileInfo(List<String> phase1FileNames, List<Long> phase1FileSizes, List<String> phase1ExistingFileNames, List<Long> phase1ExistingFileSizes, int totalTranslogOps, ActionListener<Void> listener) {
final String action = PeerRecoveryTargetService.Actions.FILES_INFO;
final long requestSeqNo = requestSeqNoGenerator.getAndIncrement();
RecoveryFilesInfoRequest request = new RecoveryFilesInfoRequest(recoveryId, requestSeqNo, shardId, phase1FileNames, phase1FileSizes, phase1ExistingFileNames, phase1ExistingFileSizes, totalTranslogOps);
final TransportRequestOptions options = TransportRequestOptions.builder().withTimeout(recoverySettings.internalActionTimeout()).build();
final Writeable.Reader<TransportResponse.Empty> reader = in -> TransportResponse.Empty.INSTANCE;
final ActionListener<TransportResponse.Empty> responseListener = ActionListener.map(listener, r -> null);
executeRetryableAction(action, request, options, responseListener, reader);
}
use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.
the class RemoteRecoveryTargetHandler method cleanFiles.
@Override
public void cleanFiles(int totalTranslogOps, long globalCheckpoint, Store.MetadataSnapshot sourceMetadata, ActionListener<Void> listener) {
final String action = PeerRecoveryTargetService.Actions.CLEAN_FILES;
final long requestSeqNo = requestSeqNoGenerator.getAndIncrement();
final RecoveryCleanFilesRequest request = new RecoveryCleanFilesRequest(recoveryId, requestSeqNo, shardId, sourceMetadata, totalTranslogOps, globalCheckpoint);
final TransportRequestOptions options = TransportRequestOptions.builder().withTimeout(recoverySettings.internalActionTimeout()).build();
final Writeable.Reader<TransportResponse.Empty> reader = in -> TransportResponse.Empty.INSTANCE;
final ActionListener<TransportResponse.Empty> responseListener = ActionListener.map(listener, r -> null);
executeRetryableAction(action, request, options, responseListener, reader);
}
use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.
the class TransportSearchActionTests method testBuildConnectionLookup.
public void testBuildConnectionLookup() {
Function<String, DiscoveryNode> localNodes = (nodeId) -> new DiscoveryNode("local-" + nodeId, new TransportAddress(TransportAddress.META_ADDRESS, 1024), Version.CURRENT);
BiFunction<String, String, DiscoveryNode> remoteNodes = (clusterAlias, nodeId) -> new DiscoveryNode("remote-" + nodeId, new TransportAddress(TransportAddress.META_ADDRESS, 2048), Version.CURRENT);
BiFunction<String, DiscoveryNode, Transport.Connection> nodeToConnection = (clusterAlias, node) -> new Transport.Connection() {
@Override
public DiscoveryNode getNode() {
return node;
}
@Override
public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws TransportException {
}
@Override
public void addCloseListener(ActionListener<Void> listener) {
}
@Override
public boolean isClosed() {
return false;
}
@Override
public void close() {
}
};
{
BiFunction<String, String, Transport.Connection> connectionLookup = TransportSearchAction.buildConnectionLookup(null, localNodes, remoteNodes, nodeToConnection);
Transport.Connection localConnection = connectionLookup.apply(null, randomAlphaOfLengthBetween(5, 10));
assertThat(localConnection.getNode().getId(), startsWith("local-"));
Transport.Connection remoteConnection = connectionLookup.apply(randomAlphaOfLengthBetween(5, 10), randomAlphaOfLengthBetween(5, 10));
assertThat(remoteConnection.getNode().getId(), startsWith("remote-"));
}
{
String requestClusterAlias = randomAlphaOfLengthBetween(5, 10);
BiFunction<String, String, Transport.Connection> connectionLookup = TransportSearchAction.buildConnectionLookup(requestClusterAlias, localNodes, remoteNodes, nodeToConnection);
Transport.Connection localConnection = connectionLookup.apply(requestClusterAlias, randomAlphaOfLengthBetween(5, 10));
assertThat(localConnection.getNode().getId(), startsWith("local-"));
}
}
use of org.opensearch.transport.TransportRequestOptions in project OpenSearch by opensearch-project.
the class DisruptableMockTransport method openConnection.
@Override
public void openConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Connection> listener) {
final Optional<DisruptableMockTransport> optionalMatchingTransport = getDisruptableMockTransport(node.getAddress());
if (optionalMatchingTransport.isPresent()) {
final DisruptableMockTransport matchingTransport = optionalMatchingTransport.get();
final ConnectionStatus connectionStatus = getConnectionStatus(matchingTransport.getLocalNode());
if (connectionStatus != ConnectionStatus.CONNECTED) {
listener.onFailure(new ConnectTransportException(node, "node [" + node + "] is [" + connectionStatus + "] not [CONNECTED]"));
} else {
listener.onResponse(new CloseableConnection() {
@Override
public DiscoveryNode getNode() {
return node;
}
@Override
public void sendRequest(long requestId, String action, TransportRequest request, TransportRequestOptions options) throws TransportException {
onSendRequest(requestId, action, request, matchingTransport);
}
});
}
} else {
listener.onFailure(new ConnectTransportException(node, "node " + node + " does not exist"));
}
}
Aggregations