Search in sources :

Example 1 with NodeNotConnectedException

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

the class ClearScrollControllerTests method testClearScrollIdsWithFailure.

public void testClearScrollIdsWithFailure() throws IOException, InterruptedException {
    DiscoveryNode node1 = new DiscoveryNode("node_1", buildNewFakeTransportAddress(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("node_2", buildNewFakeTransportAddress(), Version.CURRENT);
    DiscoveryNode node3 = new DiscoveryNode("node_3", buildNewFakeTransportAddress(), Version.CURRENT);
    AtomicArray<SearchPhaseResult> array = new AtomicArray<>(3);
    SearchAsyncActionTests.TestSearchPhaseResult testSearchPhaseResult1 = new SearchAsyncActionTests.TestSearchPhaseResult(new ShardSearchContextId(UUIDs.randomBase64UUID(), 1), node1);
    testSearchPhaseResult1.setSearchShardTarget(new SearchShardTarget("node_1", new ShardId("idx", "uuid1", 2), null, null));
    SearchAsyncActionTests.TestSearchPhaseResult testSearchPhaseResult2 = new SearchAsyncActionTests.TestSearchPhaseResult(new ShardSearchContextId(UUIDs.randomBase64UUID(), 12), node2);
    testSearchPhaseResult2.setSearchShardTarget(new SearchShardTarget("node_2", new ShardId("idy", "uuid2", 42), null, null));
    SearchAsyncActionTests.TestSearchPhaseResult testSearchPhaseResult3 = new SearchAsyncActionTests.TestSearchPhaseResult(new ShardSearchContextId(UUIDs.randomBase64UUID(), 42), node3);
    testSearchPhaseResult3.setSearchShardTarget(new SearchShardTarget("node_3", new ShardId("idy", "uuid2", 43), null, null));
    array.setOnce(0, testSearchPhaseResult1);
    array.setOnce(1, testSearchPhaseResult2);
    array.setOnce(2, testSearchPhaseResult3);
    AtomicInteger numFreed = new AtomicInteger(0);
    AtomicInteger numFailures = new AtomicInteger(0);
    AtomicInteger numConnectionFailures = new AtomicInteger(0);
    String scrollId = TransportSearchHelper.buildScrollId(array, VersionUtils.randomVersion(random()));
    DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).add(node2).add(node3).build();
    CountDownLatch latch = new CountDownLatch(1);
    ActionListener<ClearScrollResponse> listener = new LatchedActionListener<>(new ActionListener<ClearScrollResponse>() {

        @Override
        public void onResponse(ClearScrollResponse clearScrollResponse) {
            assertEquals(numFreed.get(), clearScrollResponse.getNumFreed());
            if (numFailures.get() > 0) {
                assertFalse(clearScrollResponse.isSucceeded());
            } else {
                assertTrue(clearScrollResponse.isSucceeded());
            }
        }

        @Override
        public void onFailure(Exception e) {
            throw new AssertionError(e);
        }
    }, latch);
    List<DiscoveryNode> nodesInvoked = new CopyOnWriteArrayList<>();
    SearchTransportService searchTransportService = new SearchTransportService(null, null) {

        @Override
        public void sendFreeContext(Transport.Connection connection, ShardSearchContextId contextId, ActionListener<SearchFreeContextResponse> listener) {
            nodesInvoked.add(connection.getNode());
            boolean freed = randomBoolean();
            boolean fail = randomBoolean();
            Thread t = new Thread(() -> {
                if (fail) {
                    numFailures.incrementAndGet();
                    listener.onFailure(new IllegalArgumentException("boom"));
                } else {
                    if (freed) {
                        numFreed.incrementAndGet();
                    }
                    listener.onResponse(new SearchFreeContextResponse(freed));
                }
            });
            t.start();
        }

        @Override
        public Transport.Connection getConnection(String clusterAlias, DiscoveryNode node) {
            if (randomBoolean()) {
                numFailures.incrementAndGet();
                numConnectionFailures.incrementAndGet();
                throw new NodeNotConnectedException(node, "boom");
            }
            return new SearchAsyncActionTests.MockConnection(node);
        }
    };
    ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
    clearScrollRequest.scrollIds(Arrays.asList(scrollId));
    ClearScrollController controller = new ClearScrollController(clearScrollRequest, listener, nodes, logger, searchTransportService);
    controller.run();
    latch.await();
    assertEquals(3 - numConnectionFailures.get(), nodesInvoked.size());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) ShardId(org.opensearch.index.shard.ShardId) LatchedActionListener(org.opensearch.action.LatchedActionListener) NodeNotConnectedException(org.opensearch.transport.NodeNotConnectedException) SearchPhaseResult(org.opensearch.search.SearchPhaseResult) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) CountDownLatch(java.util.concurrent.CountDownLatch) NodeNotConnectedException(org.opensearch.transport.NodeNotConnectedException) IOException(java.io.IOException) ShardSearchContextId(org.opensearch.search.internal.ShardSearchContextId) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SearchShardTarget(org.opensearch.search.SearchShardTarget) Transport(org.opensearch.transport.Transport) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with NodeNotConnectedException

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

the class ShardStateActionTests method testMasterChannelException.

public void testMasterChannelException() throws InterruptedException {
    final String index = "test";
    setState(clusterService, ClusterStateCreationUtils.stateWithActivePrimary(index, true, randomInt(5)));
    CountDownLatch latch = new CountDownLatch(1);
    AtomicInteger retries = new AtomicInteger();
    AtomicBoolean success = new AtomicBoolean();
    AtomicReference<Throwable> throwable = new AtomicReference<>();
    LongConsumer retryLoop = requestId -> {
        if (randomBoolean()) {
            transport.handleRemoteError(requestId, randomFrom(new NotMasterException("simulated"), new FailedToCommitClusterStateException("simulated")));
        } else {
            if (randomBoolean()) {
                transport.handleLocalError(requestId, new NodeNotConnectedException(null, "simulated"));
            } else {
                transport.handleError(requestId, new NodeDisconnectedException(null, ShardStateAction.SHARD_FAILED_ACTION_NAME));
            }
        }
    };
    final int numberOfRetries = randomIntBetween(1, 256);
    setUpMasterRetryVerification(numberOfRetries, retries, latch, retryLoop);
    ShardRouting failedShard = getRandomShardRouting(index);
    shardStateAction.localShardFailed(failedShard, "test", getSimulatedFailure(), new ActionListener<Void>() {

        @Override
        public void onResponse(Void aVoid) {
            success.set(true);
            latch.countDown();
        }

        @Override
        public void onFailure(Exception e) {
            success.set(false);
            throwable.set(e);
            latch.countDown();
            assert false;
        }
    });
    final CapturingTransport.CapturedRequest[] capturedRequests = transport.getCapturedRequestsAndClear();
    assertThat(capturedRequests.length, equalTo(1));
    assertFalse(success.get());
    assertThat(retries.get(), equalTo(0));
    retryLoop.accept(capturedRequests[0].requestId);
    latch.await();
    assertNull(throwable.get());
    assertThat(retries.get(), equalTo(numberOfRetries));
    assertTrue(success.get());
}
Also used : FailedShardEntry(org.opensearch.cluster.action.shard.ShardStateAction.FailedShardEntry) VersionUtils.randomCompatibleVersion(org.opensearch.test.VersionUtils.randomCompatibleVersion) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) ClusterStateCreationUtils(org.opensearch.action.support.replication.ClusterStateCreationUtils) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Matchers.nullValue(org.hamcrest.Matchers.nullValue) NotMasterException(org.opensearch.cluster.NotMasterException) ActionListener(org.opensearch.action.ActionListener) NodeNotConnectedException(org.opensearch.transport.NodeNotConnectedException) AfterClass(org.junit.AfterClass) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Predicate(java.util.function.Predicate) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) TransportResponse(org.opensearch.transport.TransportResponse) UUID(java.util.UUID) TransportService(org.opensearch.transport.TransportService) FailedToCommitClusterStateException(org.opensearch.cluster.coordination.FailedToCommitClusterStateException) CountDownLatch(java.util.concurrent.CountDownLatch) NodeDisconnectedException(org.opensearch.transport.NodeDisconnectedException) Matchers.is(org.hamcrest.Matchers.is) TransportException(org.opensearch.transport.TransportException) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) BytesReference(org.opensearch.common.bytes.BytesReference) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ThreadPool(org.opensearch.threadpool.ThreadPool) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Writeable(org.opensearch.common.io.stream.Writeable) AtomicReference(java.util.concurrent.atomic.AtomicReference) IndexRoutingTable(org.opensearch.cluster.routing.IndexRoutingTable) ClusterState(org.opensearch.cluster.ClusterState) RerouteService(org.opensearch.cluster.routing.RerouteService) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) SetOnce(org.apache.lucene.util.SetOnce) TransportRequest(org.opensearch.transport.TransportRequest) IOException(java.io.IOException) ShardsIterator(org.opensearch.cluster.routing.ShardsIterator) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) LongConsumer(java.util.function.LongConsumer) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) Phaser(java.util.concurrent.Phaser) StartedShardEntry(org.opensearch.cluster.action.shard.ShardStateAction.StartedShardEntry) ClusterService(org.opensearch.cluster.service.ClusterService) RoutingTable(org.opensearch.cluster.routing.RoutingTable) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) FailedToCommitClusterStateException(org.opensearch.cluster.coordination.FailedToCommitClusterStateException) NodeDisconnectedException(org.opensearch.transport.NodeDisconnectedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) NotMasterException(org.opensearch.cluster.NotMasterException) NodeNotConnectedException(org.opensearch.transport.NodeNotConnectedException) FailedToCommitClusterStateException(org.opensearch.cluster.coordination.FailedToCommitClusterStateException) NodeDisconnectedException(org.opensearch.transport.NodeDisconnectedException) TransportException(org.opensearch.transport.TransportException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongConsumer(java.util.function.LongConsumer) NodeNotConnectedException(org.opensearch.transport.NodeNotConnectedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NotMasterException(org.opensearch.cluster.NotMasterException) ShardRouting(org.opensearch.cluster.routing.ShardRouting)

Aggregations

IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ActionListener (org.opensearch.action.ActionListener)2 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)2 Collections (java.util.Collections)1 UUID (java.util.UUID)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Phaser (java.util.concurrent.Phaser)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LongConsumer (java.util.function.LongConsumer)1 Predicate (java.util.function.Predicate)1 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 SetOnce (org.apache.lucene.util.SetOnce)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1 CoreMatchers.instanceOf (org.hamcrest.CoreMatchers.instanceOf)1 Matchers.arrayWithSize (org.hamcrest.Matchers.arrayWithSize)1 Matchers.greaterThanOrEqualTo (org.hamcrest.Matchers.greaterThanOrEqualTo)1