Search in sources :

Example 1 with ConnectTransportException

use of org.opensearch.transport.ConnectTransportException in project OpenSearch by opensearch-project.

the class LeaderCheckerTests method testFollowerFailsImmediatelyOnDisconnection.

public void testFollowerFailsImmediatelyOnDisconnection() {
    final DiscoveryNode localNode = new DiscoveryNode("local-node", buildNewFakeTransportAddress(), Version.CURRENT);
    final DiscoveryNode leader = new DiscoveryNode("leader", buildNewFakeTransportAddress(), Version.CURRENT);
    final Response[] responseHolder = new Response[] { Response.SUCCESS };
    final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), localNode.getId()).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) {
            if (action.equals(HANDSHAKE_ACTION_NAME)) {
                handleResponse(requestId, new TransportService.HandshakeResponse(node, ClusterName.DEFAULT, Version.CURRENT));
                return;
            }
            assertThat(action, equalTo(LEADER_CHECK_ACTION_NAME));
            assertEquals(node, leader);
            final Response response = responseHolder[0];
            deterministicTaskQueue.scheduleNow(new Runnable() {

                @Override
                public void run() {
                    switch(response) {
                        case SUCCESS:
                            handleResponse(requestId, Empty.INSTANCE);
                            break;
                        case REMOTE_ERROR:
                            handleRemoteError(requestId, new ConnectTransportException(leader, "simulated error"));
                            break;
                        case DIRECT_ERROR:
                            handleError(requestId, new ConnectTransportException(leader, "simulated error"));
                    }
                }

                @Override
                public String toString() {
                    return response + " response to request " + requestId;
                }
            });
        }
    };
    final TransportService transportService = mockTransport.createTransportService(settings, deterministicTaskQueue.getThreadPool(), NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> localNode, null, emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    final AtomicBoolean leaderFailed = new AtomicBoolean();
    final LeaderChecker leaderChecker = new LeaderChecker(settings, transportService, e -> {
        assertThat(e.getMessage(), anyOf(endsWith("disconnected"), endsWith("disconnected during check")));
        assertTrue(leaderFailed.compareAndSet(false, true));
    }, () -> new StatusInfo(StatusInfo.Status.HEALTHY, "healthy-info"));
    leaderChecker.updateLeader(leader);
    {
        while (deterministicTaskQueue.getCurrentTimeMillis() < 10 * LEADER_CHECK_INTERVAL_SETTING.get(Settings.EMPTY).millis()) {
            deterministicTaskQueue.runAllRunnableTasks();
            deterministicTaskQueue.advanceTime();
        }
        deterministicTaskQueue.runAllRunnableTasks();
        assertFalse(leaderFailed.get());
        responseHolder[0] = Response.REMOTE_ERROR;
        deterministicTaskQueue.advanceTime();
        deterministicTaskQueue.runAllRunnableTasks();
        assertTrue(leaderFailed.get());
    }
    leaderChecker.updateLeader(null);
    deterministicTaskQueue.runAllTasks();
    leaderFailed.set(false);
    responseHolder[0] = Response.SUCCESS;
    leaderChecker.updateLeader(leader);
    {
        while (deterministicTaskQueue.getCurrentTimeMillis() < 10 * LEADER_CHECK_INTERVAL_SETTING.get(Settings.EMPTY).millis()) {
            deterministicTaskQueue.runAllRunnableTasks();
            deterministicTaskQueue.advanceTime();
        }
        deterministicTaskQueue.runAllRunnableTasks();
        assertFalse(leaderFailed.get());
        responseHolder[0] = Response.DIRECT_ERROR;
        deterministicTaskQueue.advanceTime();
        deterministicTaskQueue.runAllRunnableTasks();
        assertTrue(leaderFailed.get());
    }
    deterministicTaskQueue.runAllTasks();
    leaderFailed.set(false);
    responseHolder[0] = Response.SUCCESS;
    leaderChecker.updateLeader(leader);
    {
        // need to connect first for disconnect to have any effect
        transportService.connectToNode(leader);
        transportService.disconnectFromNode(leader);
        deterministicTaskQueue.runAllRunnableTasks();
        assertTrue(leaderFailed.get());
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportRequest(org.opensearch.transport.TransportRequest) TransportResponse(org.opensearch.transport.TransportResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransportService(org.opensearch.transport.TransportService) ConnectTransportException(org.opensearch.transport.ConnectTransportException) StatusInfo(org.opensearch.monitor.StatusInfo) MockTransport(org.opensearch.test.transport.MockTransport) Settings(org.opensearch.common.settings.Settings)

Example 2 with ConnectTransportException

use of org.opensearch.transport.ConnectTransportException in project OpenSearch by opensearch-project.

the class PreVoteCollectorTests method createObjects.

@Before
public void createObjects() {
    Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), "node").build();
    deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    final MockTransport mockTransport = new MockTransport() {

        @Override
        protected void onSendRequest(final long requestId, final String action, final TransportRequest request, final DiscoveryNode node) {
            super.onSendRequest(requestId, action, request, node);
            assertThat(action, is(REQUEST_PRE_VOTE_ACTION_NAME));
            assertThat(request, instanceOf(PreVoteRequest.class));
            assertThat(node, not(equalTo(localNode)));
            PreVoteRequest preVoteRequest = (PreVoteRequest) request;
            assertThat(preVoteRequest.getSourceNode(), equalTo(localNode));
            deterministicTaskQueue.scheduleNow(new Runnable() {

                @Override
                public void run() {
                    final PreVoteResponse response = responsesByNode.get(node);
                    if (response == null) {
                        handleRemoteError(requestId, new ConnectTransportException(node, "no response"));
                    } else {
                        handleResponse(requestId, response);
                    }
                }

                @Override
                public String toString() {
                    return "response to " + request + " from " + node;
                }
            });
        }

        @Override
        public void handleRemoteError(long requestId, Throwable t) {
            logger.warn("Remote error", t);
        }
    };
    lastAcceptedTerm = randomNonNegativeLong();
    currentTerm = randomLongBetween(lastAcceptedTerm, Long.MAX_VALUE);
    lastAcceptedVersion = randomNonNegativeLong();
    localNode = new DiscoveryNode("local-node", buildNewFakeTransportAddress(), Version.CURRENT);
    responsesByNode.put(localNode, new PreVoteResponse(currentTerm, lastAcceptedTerm, lastAcceptedVersion));
    healthStatus = new StatusInfo(HEALTHY, "healthy-info");
    transportService = mockTransport.createTransportService(settings, deterministicTaskQueue.getThreadPool(), TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> localNode, null, emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    preVoteCollector = new PreVoteCollector(transportService, () -> {
        assert electionOccurred == false;
        electionOccurred = true;
    }, l -> {
    }, ElectionStrategy.DEFAULT_INSTANCE, () -> healthStatus);
    preVoteCollector.update(getLocalPreVoteResponse(), null);
}
Also used : Matchers.not(org.hamcrest.Matchers.not) Version(org.opensearch.Version) HashMap(java.util.HashMap) Releasable(org.opensearch.common.lease.Releasable) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockTransport(org.opensearch.test.transport.MockTransport) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Before(org.junit.Before) UNHEALTHY(org.opensearch.monitor.StatusInfo.Status.UNHEALTHY) StreamInput(org.opensearch.common.io.stream.StreamInput) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) TransportRequest(org.opensearch.transport.TransportRequest) Collections.emptySet(java.util.Collections.emptySet) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) RemoteTransportException(org.opensearch.transport.RemoteTransportException) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) Set(java.util.Set) HEALTHY(org.opensearch.monitor.StatusInfo.Status.HEALTHY) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) TransportService(org.opensearch.transport.TransportService) Objects(java.util.Objects) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) SAME(org.opensearch.threadpool.ThreadPool.Names.SAME) NODE_NAME_SETTING(org.opensearch.node.Node.NODE_NAME_SETTING) Matchers.equalTo(org.hamcrest.Matchers.equalTo) REQUEST_PRE_VOTE_ACTION_NAME(org.opensearch.cluster.coordination.PreVoteCollector.REQUEST_PRE_VOTE_ACTION_NAME) StatusInfo(org.opensearch.monitor.StatusInfo) ConnectTransportException(org.opensearch.transport.ConnectTransportException) Matchers.is(org.hamcrest.Matchers.is) TransportException(org.opensearch.transport.TransportException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportRequest(org.opensearch.transport.TransportRequest) ConnectTransportException(org.opensearch.transport.ConnectTransportException) StatusInfo(org.opensearch.monitor.StatusInfo) MockTransport(org.opensearch.test.transport.MockTransport) Settings(org.opensearch.common.settings.Settings) Before(org.junit.Before)

Example 3 with ConnectTransportException

use of org.opensearch.transport.ConnectTransportException in project OpenSearch by opensearch-project.

the class HandshakingTransportAddressConnectorTests method testLogsFullConnectionFailureAfterSuccessfulHandshake.

@TestLogging(reason = "ensure logging happens", value = "org.opensearch.discovery.HandshakingTransportAddressConnector:INFO")
public void testLogsFullConnectionFailureAfterSuccessfulHandshake() throws Exception {
    remoteNode = new DiscoveryNode("remote-node", buildNewFakeTransportAddress(), Version.CURRENT);
    remoteClusterName = "local-cluster";
    discoveryAddress = buildNewFakeTransportAddress();
    fullConnectionFailure = new ConnectTransportException(remoteNode, "simulated", new OpenSearchException("root cause"));
    FailureListener failureListener = new FailureListener();
    Logger targetLogger = LogManager.getLogger(HandshakingTransportAddressConnector.class);
    try (MockLogAppender mockAppender = MockLogAppender.createForLoggers(targetLogger)) {
        mockAppender.addExpectation(new MockLogAppender.SeenEventExpectation("message", HandshakingTransportAddressConnector.class.getCanonicalName(), Level.WARN, "*completed handshake with [*] but followup connection failed*"));
        handshakingTransportAddressConnector.connectToRemoteMasterNode(discoveryAddress, failureListener);
        failureListener.assertFailure();
        mockAppender.assertAllExpectationsMatched();
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockLogAppender(org.opensearch.test.MockLogAppender) ConnectTransportException(org.opensearch.transport.ConnectTransportException) OpenSearchException(org.opensearch.OpenSearchException) Logger(org.apache.logging.log4j.Logger) TestLogging(org.opensearch.test.junit.annotations.TestLogging)

Example 4 with ConnectTransportException

use of org.opensearch.transport.ConnectTransportException in project OpenSearch by opensearch-project.

the class ExceptionSerializationTests method testConnectTransportException.

public void testConnectTransportException() throws IOException {
    TransportAddress transportAddress = buildNewFakeTransportAddress();
    DiscoveryNode node = new DiscoveryNode("thenode", transportAddress, emptyMap(), emptySet(), Version.CURRENT);
    ConnectTransportException ex = serialize(new ConnectTransportException(node, "msg", "action", null));
    assertEquals("[][" + transportAddress.toString() + "][action] msg", ex.getMessage());
    assertEquals(node, ex.node());
    assertEquals("action", ex.action());
    assertNull(ex.getCause());
    ex = serialize(new ConnectTransportException(node, "msg", "action", new NullPointerException()));
    assertEquals("[][" + transportAddress + "][action] msg", ex.getMessage());
    assertEquals(node, ex.node());
    assertEquals("action", ex.action());
    assertTrue(ex.getCause() instanceof NullPointerException);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ConnectTransportException(org.opensearch.transport.ConnectTransportException) TransportAddress(org.opensearch.common.transport.TransportAddress)

Example 5 with ConnectTransportException

use of org.opensearch.transport.ConnectTransportException in project OpenSearch by opensearch-project.

the class TransportInstanceSingleOperationActionTests method testRetryOfAnAlreadyTimedOutRequest.

public void testRetryOfAnAlreadyTimedOutRequest() throws Exception {
    Request request = new Request().index("test").timeout(new TimeValue(0, TimeUnit.MILLISECONDS));
    request.shardId = new ShardId("test", "_na_", 0);
    PlainActionFuture<Response> listener = new PlainActionFuture<>();
    setState(clusterService, ClusterStateCreationUtils.state("test", randomBoolean(), ShardRoutingState.STARTED));
    action.new AsyncSingleAction(request, listener).start();
    assertThat(transport.capturedRequests().length, equalTo(1));
    long requestId = transport.capturedRequests()[0].requestId;
    transport.clear();
    DiscoveryNode node = clusterService.state().getNodes().getLocalNode();
    transport.handleLocalError(requestId, new ConnectTransportException(node, "test exception"));
    // wait until the timeout was triggered and we actually tried to send for the second time
    assertBusy(() -> assertThat(transport.capturedRequests().length, equalTo(1)));
    // let it fail the second time too
    requestId = transport.capturedRequests()[0].requestId;
    transport.handleLocalError(requestId, new ConnectTransportException(node, "test exception"));
    try {
        // result should return immediately
        assertTrue(listener.isDone());
        listener.get();
        fail("this should fail with a transport exception");
    } catch (ExecutionException t) {
        if (ExceptionsHelper.unwrap(t, ConnectTransportException.class) == null) {
            logger.info("expected ConnectTransportException  but got ", t);
            fail("expected and ConnectTransportException");
        }
    }
}
Also used : ShardId(org.opensearch.index.shard.ShardId) ActionResponse(org.opensearch.action.ActionResponse) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) ConnectTransportException(org.opensearch.transport.ConnectTransportException) IndicesRequest(org.opensearch.action.IndicesRequest) ExecutionException(java.util.concurrent.ExecutionException) TimeValue(org.opensearch.common.unit.TimeValue)

Aggregations

ConnectTransportException (org.opensearch.transport.ConnectTransportException)18 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)14 TransportAddress (org.opensearch.common.transport.TransportAddress)5 TransportRequest (org.opensearch.transport.TransportRequest)5 TransportService (org.opensearch.transport.TransportService)5 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 OpenSearchException (org.opensearch.OpenSearchException)4 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)4 ClusterState (org.opensearch.cluster.ClusterState)4 TimeValue (org.opensearch.common.unit.TimeValue)4 ShardId (org.opensearch.index.shard.ShardId)4 NodeClosedException (org.opensearch.node.NodeClosedException)4 HashSet (java.util.HashSet)3 CircuitBreakingException (org.opensearch.common.breaker.CircuitBreakingException)3 OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)3 MockTransportService (org.opensearch.test.transport.MockTransportService)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2