-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Relax fault detector in some disruption tests #38101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DaveCTurner
merged 4 commits into
elastic:master
from
DaveCTurner:2019-01-31-less-enthusiastic-failure-detector-in-tests
Feb 1, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.