-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax fault detector in some disruption tests (#38101)
Today we use `AbstractDisruptionTestCase` to test the behaviour of things like master elections in the presence of cluster disruptions. These tests have rather enthusiastic fault detection settings, detecting a fault if a single ping fails, with a one-second timeout. Furthermore there are some tests that assert the identity of the master remains unchanged during some disruption, and these assertions fail rather often thanks to the overly sensitive fault detector. However in a number of these tests the fault detector need not be this sensitive. This commit moves some such tests into their own test suite and uses more sensible fault-detection settings to avoid the kind of master instability that is causing CI failures. Closes #37699
- Loading branch information
1 parent
c02cd3e
commit 23f00e3
Showing
2 changed files
with
170 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
server/src/test/java/org/elasticsearch/discovery/StableMasterDisruptionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.discovery; | ||
|
||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; | ||
import org.elasticsearch.cluster.coordination.FollowersChecker; | ||
import org.elasticsearch.cluster.coordination.LeaderChecker; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.set.Sets; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.test.disruption.NetworkDisruption; | ||
import org.elasticsearch.test.disruption.NetworkDisruption.NetworkDisconnect; | ||
import org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive; | ||
import org.elasticsearch.test.junit.annotations.TestLogging; | ||
import org.elasticsearch.test.transport.MockTransportService.TestPlugin; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static java.util.Collections.singleton; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/** | ||
* Tests relating to the loss of the master, but which work with the default fault detection settings which are rather lenient and will | ||
* not detect a master failure too quickly. | ||
*/ | ||
@TestLogging("_root:DEBUG,org.elasticsearch.cluster.service:TRACE") | ||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, transportClientRatio = 0) | ||
public class StableMasterDisruptionIT extends ESIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Collections.singletonList(TestPlugin.class); | ||
} | ||
|
||
/** | ||
* Test that no split brain occurs under partial network partition. See https://github.com/elastic/elasticsearch/issues/2488 | ||
*/ | ||
public void testFailWithMinimumMasterNodesConfigured() throws Exception { | ||
List<String> nodes = internalCluster().startNodes(3); | ||
ensureStableCluster(3); | ||
|
||
// Figure out what is the elected master node | ||
final String masterNode = internalCluster().getMasterName(); | ||
logger.info("---> legit elected master node={}", masterNode); | ||
|
||
// Pick a node that isn't the elected master. | ||
Set<String> nonMasters = new HashSet<>(nodes); | ||
nonMasters.remove(masterNode); | ||
final String unluckyNode = randomFrom(nonMasters.toArray(Strings.EMPTY_ARRAY)); | ||
|
||
// Simulate a network issue between the unlucky node and elected master node in both directions. | ||
|
||
NetworkDisruption networkDisconnect = new NetworkDisruption( | ||
new NetworkDisruption.TwoPartitions(masterNode, unluckyNode), | ||
new NetworkDisruption.NetworkDisconnect()); | ||
setDisruptionScheme(networkDisconnect); | ||
networkDisconnect.startDisrupting(); | ||
|
||
// Wait until elected master has removed that the unlucky node... | ||
ensureStableCluster(2, masterNode); | ||
|
||
// The unlucky node must report *no* master node, since it can't connect to master and in fact it should | ||
// continuously ping until network failures have been resolved. However | ||
// It may a take a bit before the node detects it has been cut off from the elected master | ||
assertBusy(() -> assertNull(client(unluckyNode).admin().cluster().state( | ||
new ClusterStateRequest().local(true)).get().getState().nodes().getMasterNode())); | ||
|
||
networkDisconnect.stopDisrupting(); | ||
|
||
// Wait until the master node sees all 3 nodes again. | ||
ensureStableCluster(3); | ||
|
||
// The elected master shouldn't have changed, since the unlucky node never could have elected itself as master | ||
assertThat(internalCluster().getMasterName(), equalTo(masterNode)); | ||
} | ||
|
||
/** | ||
* Verify that nodes fault detection works after master (re) election | ||
*/ | ||
public void testFollowerCheckerDetectsUnresponsiveNodeAfterMasterReelection() throws Exception { | ||
internalCluster().startNodes(4, | ||
Settings.builder() | ||
.put(LeaderChecker.LEADER_CHECK_TIMEOUT_SETTING.getKey(), "1s") | ||
.put(LeaderChecker.LEADER_CHECK_RETRY_COUNT_SETTING.getKey(), "10") | ||
.put(FollowersChecker.FOLLOWER_CHECK_TIMEOUT_SETTING.getKey(), "1s") | ||
.put(FollowersChecker.FOLLOWER_CHECK_RETRY_COUNT_SETTING.getKey(), 1).build()); | ||
ensureStableCluster(4); | ||
|
||
logger.info("--> stopping current master"); | ||
internalCluster().stopCurrentMasterNode(); | ||
|
||
ensureStableCluster(3); | ||
|
||
final String master = internalCluster().getMasterName(); | ||
final List<String> nonMasters = Arrays.stream(internalCluster().getNodeNames()).filter(n -> master.equals(n) == false) | ||
.collect(Collectors.toList()); | ||
final String isolatedNode = randomFrom(nonMasters); | ||
final String otherNode = nonMasters.get(nonMasters.get(0).equals(isolatedNode) ? 1 : 0); | ||
|
||
logger.info("--> isolating [{}]", isolatedNode); | ||
|
||
final NetworkDisruption networkDisruption = new NetworkDisruption(new NetworkDisruption.TwoPartitions( | ||
singleton(isolatedNode), Sets.newHashSet(master, otherNode)), new NetworkUnresponsive()); | ||
setDisruptionScheme(networkDisruption); | ||
networkDisruption.startDisrupting(); | ||
|
||
logger.info("--> waiting for master to remove it"); | ||
ensureStableCluster(2, master); | ||
|
||
networkDisruption.stopDisrupting(); | ||
ensureStableCluster(3); | ||
} | ||
|
||
/** | ||
* Verify that nodes fault detection works after master (re) election | ||
*/ | ||
public void testFollowerCheckerDetectsDisconnectedNodeAfterMasterReelection() throws Exception { | ||
internalCluster().startNodes(4); | ||
ensureStableCluster(4); | ||
|
||
logger.info("--> stopping current master"); | ||
internalCluster().stopCurrentMasterNode(); | ||
|
||
ensureStableCluster(3); | ||
|
||
final String master = internalCluster().getMasterName(); | ||
final List<String> nonMasters = Arrays.stream(internalCluster().getNodeNames()).filter(n -> master.equals(n) == false) | ||
.collect(Collectors.toList()); | ||
final String isolatedNode = randomFrom(nonMasters); | ||
final String otherNode = nonMasters.get(nonMasters.get(0).equals(isolatedNode) ? 1 : 0); | ||
|
||
logger.info("--> isolating [{}]", isolatedNode); | ||
|
||
final NetworkDisruption networkDisruption = new NetworkDisruption(new NetworkDisruption.TwoPartitions( | ||
singleton(isolatedNode), Stream.of(master, otherNode).collect(Collectors.toSet())), new NetworkDisconnect()); | ||
setDisruptionScheme(networkDisruption); | ||
networkDisruption.startDisrupting(); | ||
|
||
logger.info("--> waiting for master to remove it"); | ||
ensureStableCluster(2, master); | ||
|
||
networkDisruption.stopDisrupting(); | ||
ensureStableCluster(3); | ||
} | ||
} |