Search in sources :

Example 1 with StatusInfo

use of org.opensearch.monitor.StatusInfo in project OpenSearch by opensearch-project.

the class JoinHelper method sendJoinRequest.

public void sendJoinRequest(DiscoveryNode destination, long term, Optional<Join> optionalJoin, Runnable onCompletion) {
    assert destination.isMasterNode() : "trying to join master-ineligible " + destination;
    final StatusInfo statusInfo = nodeHealthService.getHealth();
    if (statusInfo.getStatus() == UNHEALTHY) {
        logger.debug("dropping join request to [{}]: [{}]", destination, statusInfo.getInfo());
        return;
    }
    final JoinRequest joinRequest = new JoinRequest(transportService.getLocalNode(), term, optionalJoin);
    final Tuple<DiscoveryNode, JoinRequest> dedupKey = Tuple.tuple(destination, joinRequest);
    if (pendingOutgoingJoins.add(dedupKey)) {
        logger.debug("attempting to join {} with {}", destination, joinRequest);
        transportService.sendRequest(destination, JOIN_ACTION_NAME, joinRequest, TransportRequestOptions.EMPTY, new TransportResponseHandler<Empty>() {

            @Override
            public Empty read(StreamInput in) {
                return Empty.INSTANCE;
            }

            @Override
            public void handleResponse(Empty response) {
                pendingOutgoingJoins.remove(dedupKey);
                logger.debug("successfully joined {} with {}", destination, joinRequest);
                lastFailedJoinAttempt.set(null);
                onCompletion.run();
            }

            @Override
            public void handleException(TransportException exp) {
                pendingOutgoingJoins.remove(dedupKey);
                logger.info(() -> new ParameterizedMessage("failed to join {} with {}", destination, joinRequest), exp);
                FailedJoinAttempt attempt = new FailedJoinAttempt(destination, joinRequest, exp);
                attempt.logNow();
                lastFailedJoinAttempt.set(attempt);
                onCompletion.run();
            }

            @Override
            public String executor() {
                return Names.SAME;
            }
        });
    } else {
        logger.debug("already attempting to join {} with request {}, not sending request", destination, joinRequest);
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Empty(org.opensearch.transport.TransportResponse.Empty) StatusInfo(org.opensearch.monitor.StatusInfo) StreamInput(org.opensearch.common.io.stream.StreamInput) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) TransportException(org.opensearch.transport.TransportException)

Example 2 with StatusInfo

use of org.opensearch.monitor.StatusInfo in project OpenSearch by opensearch-project.

the class NodeJoinTests method setupRealMasterServiceAndCoordinator.

private void setupRealMasterServiceAndCoordinator(long term, ClusterState initialState) {
    MasterService masterService = new MasterService(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "test_node").build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadPool);
    AtomicReference<ClusterState> clusterStateRef = new AtomicReference<>(initialState);
    masterService.setClusterStatePublisher((event, publishListener, ackListener) -> {
        clusterStateRef.set(event.state());
        publishListener.onResponse(null);
    });
    setupMasterServiceAndCoordinator(term, initialState, masterService, threadPool, new Random(Randomness.get().nextLong()), () -> new StatusInfo(HEALTHY, "healthy-info"));
    masterService.setClusterStateSupplier(clusterStateRef::get);
    masterService.start();
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Random(java.util.Random) StatusInfo(org.opensearch.monitor.StatusInfo) AtomicReference(java.util.concurrent.atomic.AtomicReference) MasterService(org.opensearch.cluster.service.MasterService) FakeThreadPoolMasterService(org.opensearch.cluster.service.FakeThreadPoolMasterService)

Example 3 with StatusInfo

use of org.opensearch.monitor.StatusInfo in project OpenSearch by opensearch-project.

the class NodeJoinTests method testJoinWithHigherTermButBetterStateStillElectsMasterThroughSelfJoin.

public void testJoinWithHigherTermButBetterStateStillElectsMasterThroughSelfJoin() {
    DiscoveryNode node0 = newNode(0, true);
    DiscoveryNode node1 = newNode(1, true);
    long initialTerm = randomLongBetween(1, 10);
    long initialVersion = randomLongBetween(1, 10);
    setupFakeMasterServiceAndCoordinator(initialTerm, initialState(node0, initialTerm, initialVersion, VotingConfiguration.of(node0)), () -> new StatusInfo(HEALTHY, "healthy-info"));
    assertFalse(isLocalNodeElectedMaster());
    long newTerm = initialTerm + randomLongBetween(1, 10);
    long higherVersion = initialVersion + randomLongBetween(1, 10);
    joinNodeAndRun(new JoinRequest(node1, newTerm, Optional.of(new Join(node1, node0, newTerm, initialTerm, higherVersion))));
    assertTrue(isLocalNodeElectedMaster());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) StatusInfo(org.opensearch.monitor.StatusInfo)

Example 4 with StatusInfo

use of org.opensearch.monitor.StatusInfo in project OpenSearch by opensearch-project.

the class NodeJoinTests method testJoinWithHigherTermButBetterStateGetsRejected.

public void testJoinWithHigherTermButBetterStateGetsRejected() {
    DiscoveryNode node0 = newNode(0, true);
    DiscoveryNode node1 = newNode(1, true);
    long initialTerm = randomLongBetween(1, 10);
    long initialVersion = randomLongBetween(1, 10);
    setupFakeMasterServiceAndCoordinator(initialTerm, initialState(node0, initialTerm, initialVersion, VotingConfiguration.of(node1)), () -> new StatusInfo(HEALTHY, "healthy-info"));
    assertFalse(isLocalNodeElectedMaster());
    long newTerm = initialTerm + randomLongBetween(1, 10);
    long higherVersion = initialVersion + randomLongBetween(1, 10);
    expectThrows(CoordinationStateRejectedException.class, () -> joinNodeAndRun(new JoinRequest(node1, newTerm, Optional.of(new Join(node1, node0, newTerm, initialTerm, higherVersion)))));
    assertFalse(isLocalNodeElectedMaster());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) StatusInfo(org.opensearch.monitor.StatusInfo)

Example 5 with StatusInfo

use of org.opensearch.monitor.StatusInfo in project OpenSearch by opensearch-project.

the class NodeJoinTests method testJoinElectedLeader.

public void testJoinElectedLeader() {
    DiscoveryNode node0 = newNode(0, true);
    DiscoveryNode node1 = newNode(1, true);
    long initialTerm = randomLongBetween(1, 10);
    long initialVersion = randomLongBetween(1, 10);
    setupFakeMasterServiceAndCoordinator(initialTerm, initialState(node0, initialTerm, initialVersion, VotingConfiguration.of(node0)), () -> new StatusInfo(HEALTHY, "healthy-info"));
    assertFalse(isLocalNodeElectedMaster());
    long newTerm = initialTerm + randomLongBetween(1, 10);
    joinNodeAndRun(new JoinRequest(node0, newTerm, Optional.of(new Join(node0, node0, newTerm, initialTerm, initialVersion))));
    assertTrue(isLocalNodeElectedMaster());
    assertFalse(clusterStateHasNode(node1));
    joinNodeAndRun(new JoinRequest(node1, newTerm, Optional.of(new Join(node1, node0, newTerm, initialTerm, initialVersion))));
    assertTrue(isLocalNodeElectedMaster());
    assertTrue(clusterStateHasNode(node1));
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) StatusInfo(org.opensearch.monitor.StatusInfo)

Aggregations

StatusInfo (org.opensearch.monitor.StatusInfo)45 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)33 Settings (org.opensearch.common.settings.Settings)18 TransportService (org.opensearch.transport.TransportService)14 ClusterState (org.opensearch.cluster.ClusterState)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 TransportRequest (org.opensearch.transport.TransportRequest)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 MockTransport (org.opensearch.test.transport.MockTransport)9 ClusterFormationState (org.opensearch.cluster.coordination.ClusterFormationFailureHelper.ClusterFormationState)8 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)7 ConnectTransportException (org.opensearch.transport.ConnectTransportException)6 TransportException (org.opensearch.transport.TransportException)6 TransportResponse (org.opensearch.transport.TransportResponse)6 Empty (org.opensearch.transport.TransportResponse.Empty)6 HashSet (java.util.HashSet)5 VotingConfiguration (org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)5 TransportAddress (org.opensearch.common.transport.TransportAddress)5 CapturingTransport (org.opensearch.test.transport.CapturingTransport)5 Set (java.util.Set)4