Search in sources :

Example 1 with MasterFaultDetection

use of org.elasticsearch.discovery.zen.MasterFaultDetection in project elasticsearch by elastic.

the class ZenFaultDetectionTests method testMasterFaultDetectionConnectOnDisconnect.

public void testMasterFaultDetectionConnectOnDisconnect() throws InterruptedException {
    Settings.Builder settings = Settings.builder();
    boolean shouldRetry = randomBoolean();
    ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20));
    // make sure we don't ping
    settings.put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry).put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").put("cluster.name", clusterName.value());
    final ClusterState state = ClusterState.builder(clusterName).nodes(buildNodesForA(false)).build();
    setState(clusterServiceA, state);
    MasterFaultDetection masterFD = new MasterFaultDetection(settings.build(), threadPool, serviceA, clusterServiceA);
    masterFD.restart(nodeB, "test");
    final String[] failureReason = new String[1];
    final DiscoveryNode[] failureNode = new DiscoveryNode[1];
    final CountDownLatch notified = new CountDownLatch(1);
    masterFD.addListener((masterNode, cause, reason) -> {
        failureNode[0] = masterNode;
        failureReason[0] = reason;
        notified.countDown();
    });
    // will raise a disconnect on A
    serviceB.stop();
    notified.await(30, TimeUnit.SECONDS);
    CircuitBreaker inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
    assertThat(inFlightRequestsBreaker.getTrippedCount(), equalTo(0L));
    assertEquals(nodeB, failureNode[0]);
    Matcher<String> matcher = Matchers.containsString("verified");
    if (!shouldRetry) {
        matcher = Matchers.not(matcher);
    }
    assertThat(failureReason[0], matcher);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) CountDownLatch(java.util.concurrent.CountDownLatch) MasterFaultDetection(org.elasticsearch.discovery.zen.MasterFaultDetection) ClusterName(org.elasticsearch.cluster.ClusterName) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Example 2 with MasterFaultDetection

use of org.elasticsearch.discovery.zen.MasterFaultDetection in project elasticsearch by elastic.

the class ZenFaultDetectionTests method testMasterFaultDetectionNotSizeLimited.

public void testMasterFaultDetectionNotSizeLimited() throws InterruptedException {
    boolean shouldRetry = randomBoolean();
    ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20));
    final Settings settings = Settings.builder().put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry).put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "1s").put("cluster.name", clusterName.value()).build();
    final ClusterState stateNodeA = ClusterState.builder(clusterName).nodes(buildNodesForA(false)).build();
    setState(clusterServiceA, stateNodeA);
    int minExpectedPings = 2;
    PingProbe pingProbeA = new PingProbe(minExpectedPings);
    PingProbe pingProbeB = new PingProbe(minExpectedPings);
    serviceA.addTracer(pingProbeA);
    serviceB.addTracer(pingProbeB);
    MasterFaultDetection masterFDNodeA = new MasterFaultDetection(Settings.builder().put(settingsA).put(settings).build(), threadPool, serviceA, clusterServiceA);
    masterFDNodeA.restart(nodeB, "test");
    final ClusterState stateNodeB = ClusterState.builder(clusterName).nodes(buildNodesForB(true)).build();
    setState(clusterServiceB, stateNodeB);
    MasterFaultDetection masterFDNodeB = new MasterFaultDetection(Settings.builder().put(settingsB).put(settings).build(), threadPool, serviceB, clusterServiceB);
    masterFDNodeB.restart(nodeB, "test");
    // let's do a few pings
    pingProbeA.awaitMinCompletedPings();
    pingProbeB.awaitMinCompletedPings();
    CircuitBreaker inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
    assertThat(inFlightRequestsBreaker.getTrippedCount(), equalTo(0L));
    assertThat(pingProbeA.completedPings(), greaterThanOrEqualTo(minExpectedPings));
    assertThat(pingProbeB.completedPings(), greaterThanOrEqualTo(minExpectedPings));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MasterFaultDetection(org.elasticsearch.discovery.zen.MasterFaultDetection) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) ClusterName(org.elasticsearch.cluster.ClusterName) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Aggregations

ClusterName (org.elasticsearch.cluster.ClusterName)2 ClusterState (org.elasticsearch.cluster.ClusterState)2 CircuitBreaker (org.elasticsearch.common.breaker.CircuitBreaker)2 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)2 Settings (org.elasticsearch.common.settings.Settings)2 MasterFaultDetection (org.elasticsearch.discovery.zen.MasterFaultDetection)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1