Search in sources :

Example 1 with NetworkUnresponsive

use of org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive in project elasticsearch by elastic.

the class DiscoveryWithServiceDisruptionsIT method testSendingShardFailure.

// simulate handling of sending shard failure during an isolation
public void testSendingShardFailure() throws Exception {
    List<String> nodes = startCluster(3, 2);
    String masterNode = internalCluster().getMasterName();
    List<String> nonMasterNodes = nodes.stream().filter(node -> !node.equals(masterNode)).collect(Collectors.toList());
    String nonMasterNode = randomFrom(nonMasterNodes);
    assertAcked(prepareCreate("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 3).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 2)));
    ensureGreen();
    String nonMasterNodeId = internalCluster().clusterService(nonMasterNode).localNode().getId();
    // fail a random shard
    ShardRouting failedShard = randomFrom(clusterService().state().getRoutingNodes().node(nonMasterNodeId).shardsWithState(ShardRoutingState.STARTED));
    ShardStateAction service = internalCluster().getInstance(ShardStateAction.class, nonMasterNode);
    CountDownLatch latch = new CountDownLatch(1);
    AtomicBoolean success = new AtomicBoolean();
    String isolatedNode = randomBoolean() ? masterNode : nonMasterNode;
    TwoPartitions partitions = isolateNode(isolatedNode);
    // we cannot use the NetworkUnresponsive disruption type here as it will swallow the "shard failed" request, calling neither
    // onSuccess nor onFailure on the provided listener.
    NetworkLinkDisruptionType disruptionType = new NetworkDisconnect();
    NetworkDisruption networkDisruption = new NetworkDisruption(partitions, disruptionType);
    setDisruptionScheme(networkDisruption);
    networkDisruption.startDisrupting();
    service.localShardFailed(failedShard, "simulated", new CorruptIndexException("simulated", (String) null), new ShardStateAction.Listener() {

        @Override
        public void onSuccess() {
            success.set(true);
            latch.countDown();
        }

        @Override
        public void onFailure(Exception e) {
            success.set(false);
            latch.countDown();
            assert false;
        }
    });
    if (isolatedNode.equals(nonMasterNode)) {
        assertNoMaster(nonMasterNode);
    } else {
        ensureStableCluster(2, nonMasterNode);
    }
    // heal the partition
    networkDisruption.removeAndEnsureHealthy(internalCluster());
    // the cluster should stabilize
    ensureStableCluster(3);
    latch.await();
    // the listener should be notified
    assertTrue(success.get());
    // the failed shard should be gone
    List<ShardRouting> shards = clusterService().state().getRoutingTable().allShards("test");
    for (ShardRouting shard : shards) {
        assertThat(shard.allocationId(), not(equalTo(failedShard.allocationId())));
    }
}
Also used : Arrays(java.util.Arrays) Nullable(org.elasticsearch.common.Nullable) ZenDiscovery(org.elasticsearch.discovery.zen.ZenDiscovery) Matchers.not(org.hamcrest.Matchers.not) ZenPing(org.elasticsearch.discovery.zen.ZenPing) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Scope(org.elasticsearch.test.ESIntegTestCase.Scope) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) SlowClusterStateProcessing(org.elasticsearch.test.disruption.SlowClusterStateProcessing) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ServiceDisruptionScheme(org.elasticsearch.test.disruption.ServiceDisruptionScheme) Priority(org.elasticsearch.common.Priority) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging) Set(java.util.Set) ClusterDiscoveryConfiguration(org.elasticsearch.test.discovery.ClusterDiscoveryConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) Supplier(org.apache.logging.log4j.util.Supplier) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) IntermittentLongGCDisruption(org.elasticsearch.test.disruption.IntermittentLongGCDisruption) Matchers.is(org.hamcrest.Matchers.is) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) TestZenDiscovery(org.elasticsearch.test.discovery.TestZenDiscovery) ClusterService(org.elasticsearch.cluster.service.ClusterService) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) MembershipAction(org.elasticsearch.discovery.zen.MembershipAction) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TcpTransport(org.elasticsearch.transport.TcpTransport) IndicesStoreIntegrationIT(org.elasticsearch.indices.store.IndicesStoreIntegrationIT) TransportService(org.elasticsearch.transport.TransportService) Before(org.junit.Before) ConnectionProfile(org.elasticsearch.transport.ConnectionProfile) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) ClusterScope(org.elasticsearch.test.ESIntegTestCase.ClusterScope) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) ExecutionException(java.util.concurrent.ExecutionException) NetworkDisconnect(org.elasticsearch.test.disruption.NetworkDisruption.NetworkDisconnect) Tuple(org.elasticsearch.common.collect.Tuple) NetworkDelay(org.elasticsearch.test.disruption.NetworkDisruption.NetworkDelay) ElasticsearchAssertions.assertAcked(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked) ElasticsearchException(org.elasticsearch.ElasticsearchException) GetResponse(org.elasticsearch.action.get.GetResponse) UnicastZenPing(org.elasticsearch.discovery.zen.UnicastZenPing) NetworkDisruption(org.elasticsearch.test.disruption.NetworkDisruption) TransportRequest(org.elasticsearch.transport.TransportRequest) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongGCDisruption(org.elasticsearch.test.disruption.LongGCDisruption) XContentFactory.jsonBuilder(org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder) Bridge(org.elasticsearch.test.disruption.NetworkDisruption.Bridge) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HotThreads(org.elasticsearch.monitor.jvm.HotThreads) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) NetworkUnresponsive(org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive) INDEX_NUMBER_OF_REPLICAS_SETTING(org.elasticsearch.cluster.metadata.IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING) PublishClusterStateAction(org.elasticsearch.discovery.zen.PublishClusterStateAction) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ElectMasterService(org.elasticsearch.discovery.zen.ElectMasterService) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) XContentType(org.elasticsearch.common.xcontent.XContentType) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) FaultDetection(org.elasticsearch.discovery.zen.FaultDetection) AtomicReference(java.util.concurrent.atomic.AtomicReference) Strings(org.elasticsearch.common.Strings) HashSet(java.util.HashSet) TimeValue(org.elasticsearch.common.unit.TimeValue) IndexSettings(org.elasticsearch.index.IndexSettings) IndexResponse(org.elasticsearch.action.index.IndexResponse) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) TwoPartitions(org.elasticsearch.test.disruption.NetworkDisruption.TwoPartitions) INDEX_NUMBER_OF_SHARDS_SETTING(org.elasticsearch.cluster.metadata.IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING) DisruptedLinks(org.elasticsearch.test.disruption.NetworkDisruption.DisruptedLinks) Semaphore(java.util.concurrent.Semaphore) NetworkLinkDisruptionType(org.elasticsearch.test.disruption.NetworkDisruption.NetworkLinkDisruptionType) Plugin(org.elasticsearch.plugins.Plugin) NoShardAvailableActionException(org.elasticsearch.action.NoShardAvailableActionException) Murmur3HashFunction(org.elasticsearch.cluster.routing.Murmur3HashFunction) TimeUnit(java.util.concurrent.TimeUnit) SingleNodeDisruption(org.elasticsearch.test.disruption.SingleNodeDisruption) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Collections(java.util.Collections) NetworkLinkDisruptionType(org.elasticsearch.test.disruption.NetworkDisruption.NetworkLinkDisruptionType) TwoPartitions(org.elasticsearch.test.disruption.NetworkDisruption.TwoPartitions) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) CountDownLatch(java.util.concurrent.CountDownLatch) NetworkDisconnect(org.elasticsearch.test.disruption.NetworkDisruption.NetworkDisconnect) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ElasticsearchException(org.elasticsearch.ElasticsearchException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) NoShardAvailableActionException(org.elasticsearch.action.NoShardAvailableActionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) NetworkDisruption(org.elasticsearch.test.disruption.NetworkDisruption)

Example 2 with NetworkUnresponsive

use of org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive in project elasticsearch by elastic.

the class DiscoveryWithServiceDisruptionsIT method addRandomDisruptionScheme.

private ServiceDisruptionScheme addRandomDisruptionScheme() {
    // TODO: add partial partitions
    final DisruptedLinks disruptedLinks;
    if (randomBoolean()) {
        disruptedLinks = TwoPartitions.random(random(), internalCluster().getNodeNames());
    } else {
        disruptedLinks = Bridge.random(random(), internalCluster().getNodeNames());
    }
    final NetworkLinkDisruptionType disruptionType;
    switch(randomInt(2)) {
        case 0:
            disruptionType = new NetworkUnresponsive();
            break;
        case 1:
            disruptionType = new NetworkDisconnect();
            break;
        case 2:
            disruptionType = NetworkDelay.random(random());
            break;
        default:
            throw new IllegalArgumentException();
    }
    final ServiceDisruptionScheme scheme;
    if (rarely()) {
        scheme = new SlowClusterStateProcessing(random());
    } else {
        scheme = new NetworkDisruption(disruptedLinks, disruptionType);
    }
    setDisruptionScheme(scheme);
    return scheme;
}
Also used : SlowClusterStateProcessing(org.elasticsearch.test.disruption.SlowClusterStateProcessing) NetworkLinkDisruptionType(org.elasticsearch.test.disruption.NetworkDisruption.NetworkLinkDisruptionType) DisruptedLinks(org.elasticsearch.test.disruption.NetworkDisruption.DisruptedLinks) NetworkUnresponsive(org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive) ServiceDisruptionScheme(org.elasticsearch.test.disruption.ServiceDisruptionScheme) NetworkDisruption(org.elasticsearch.test.disruption.NetworkDisruption) NetworkDisconnect(org.elasticsearch.test.disruption.NetworkDisruption.NetworkDisconnect)

Example 3 with NetworkUnresponsive

use of org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive in project elasticsearch by elastic.

the class DiscoveryWithServiceDisruptionsIT method testIndicesDeleted.

/**
     * Tests that indices are properly deleted even if there is a master transition in between.
     * Test for https://github.com/elastic/elasticsearch/issues/11665
     */
public void testIndicesDeleted() throws Exception {
    final Settings settings = Settings.builder().put(DEFAULT_SETTINGS).put(DiscoverySettings.PUBLISH_TIMEOUT_SETTING.getKey(), // don't wait on isolated data node
    "0s").put(DiscoverySettings.COMMIT_TIMEOUT_SETTING.getKey(), // wait till cluster state is committed
    "30s").build();
    final String idxName = "test";
    configureCluster(settings, 3, null, 2);
    final List<String> allMasterEligibleNodes = internalCluster().startMasterOnlyNodes(2);
    final String dataNode = internalCluster().startDataOnlyNode();
    ensureStableCluster(3);
    assertAcked(prepareCreate("test"));
    final String masterNode1 = internalCluster().getMasterName();
    NetworkDisruption networkDisruption = new NetworkDisruption(new TwoPartitions(masterNode1, dataNode), new NetworkUnresponsive());
    internalCluster().setDisruptionScheme(networkDisruption);
    networkDisruption.startDisrupting();
    // We know this will time out due to the partition, we check manually below to not proceed until
    // the delete has been applied to the master node and the master eligible node.
    internalCluster().client(masterNode1).admin().indices().prepareDelete(idxName).setTimeout("0s").get();
    // Don't restart the master node until we know the index deletion has taken effect on master and the master eligible node.
    assertBusy(() -> {
        for (String masterNode : allMasterEligibleNodes) {
            final ClusterState masterState = internalCluster().clusterService(masterNode).state();
            assertTrue("index not deleted on " + masterNode, masterState.metaData().hasIndex(idxName) == false);
        }
    });
    internalCluster().restartNode(masterNode1, InternalTestCluster.EMPTY_CALLBACK);
    ensureYellow();
    assertFalse(client().admin().indices().prepareExists(idxName).get().isExists());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) TwoPartitions(org.elasticsearch.test.disruption.NetworkDisruption.TwoPartitions) NetworkUnresponsive(org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive) NetworkDisruption(org.elasticsearch.test.disruption.NetworkDisruption) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 4 with NetworkUnresponsive

use of org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive in project elasticsearch by elastic.

the class DiscoveryWithServiceDisruptionsIT method addRandomDisruptionType.

protected NetworkDisruption addRandomDisruptionType(TwoPartitions partitions) {
    final NetworkLinkDisruptionType disruptionType;
    if (randomBoolean()) {
        disruptionType = new NetworkUnresponsive();
    } else {
        disruptionType = new NetworkDisconnect();
    }
    NetworkDisruption partition = new NetworkDisruption(partitions, disruptionType);
    setDisruptionScheme(partition);
    return partition;
}
Also used : NetworkLinkDisruptionType(org.elasticsearch.test.disruption.NetworkDisruption.NetworkLinkDisruptionType) NetworkUnresponsive(org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive) NetworkDisruption(org.elasticsearch.test.disruption.NetworkDisruption) NetworkDisconnect(org.elasticsearch.test.disruption.NetworkDisruption.NetworkDisconnect)

Example 5 with NetworkUnresponsive

use of org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive in project elasticsearch by elastic.

the class NetworkDisruptionIT method testNetworkPartitionWithNodeShutdown.

public void testNetworkPartitionWithNodeShutdown() throws IOException {
    internalCluster().ensureAtLeastNumDataNodes(2);
    String[] nodeNames = internalCluster().getNodeNames();
    NetworkDisruption networkDisruption = new NetworkDisruption(new TwoPartitions(nodeNames[0], nodeNames[1]), new NetworkUnresponsive());
    internalCluster().setDisruptionScheme(networkDisruption);
    networkDisruption.startDisrupting();
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeNames[0]));
    internalCluster().clearDisruptionScheme();
}
Also used : TwoPartitions(org.elasticsearch.test.disruption.NetworkDisruption.TwoPartitions) NetworkUnresponsive(org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive)

Aggregations

NetworkUnresponsive (org.elasticsearch.test.disruption.NetworkDisruption.NetworkUnresponsive)5 NetworkDisruption (org.elasticsearch.test.disruption.NetworkDisruption)4 NetworkDisconnect (org.elasticsearch.test.disruption.NetworkDisruption.NetworkDisconnect)3 NetworkLinkDisruptionType (org.elasticsearch.test.disruption.NetworkDisruption.NetworkLinkDisruptionType)3 TwoPartitions (org.elasticsearch.test.disruption.NetworkDisruption.TwoPartitions)3 ClusterState (org.elasticsearch.cluster.ClusterState)2 Settings (org.elasticsearch.common.settings.Settings)2 IndexSettings (org.elasticsearch.index.IndexSettings)2 DisruptedLinks (org.elasticsearch.test.disruption.NetworkDisruption.DisruptedLinks)2 ServiceDisruptionScheme (org.elasticsearch.test.disruption.ServiceDisruptionScheme)2 SlowClusterStateProcessing (org.elasticsearch.test.disruption.SlowClusterStateProcessing)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1