Search in sources :

Example 1 with ClearVotingConfigExclusionsRequest

use of org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest in project OpenSearch by opensearch-project.

the class MinimumMasterNodesIT method testTwoNodesNoMasterBlock.

public void testTwoNodesNoMasterBlock() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(1);
    Settings settings = Settings.builder().put("discovery.initial_state_timeout", "500ms").build();
    logger.info("--> start first node");
    String node1Name = internalCluster().startNode(settings);
    logger.info("--> should be blocked, no master...");
    ClusterState state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
    // verify that we still see the local node in the cluster state
    assertThat(state.nodes().getSize(), equalTo(1));
    logger.info("--> start second node, cluster should be formed");
    String node2Name = internalCluster().startNode(settings);
    ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("2").execute().actionGet();
    assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.nodes().getSize(), equalTo(2));
    assertThat(state.metadata().indices().containsKey("test"), equalTo(false));
    createIndex("test");
    NumShards numShards = getNumShards("test");
    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        client().prepareIndex("test").setId(Integer.toString(i)).setSource("field", "value").execute().actionGet();
    }
    // make sure that all shards recovered before trying to flush
    assertThat(client().admin().cluster().prepareHealth("test").setWaitForActiveShards(numShards.totalNumShards).execute().actionGet().getActiveShards(), equalTo(numShards.totalNumShards));
    // flush for simpler debugging
    flushAndRefresh();
    logger.info("--> verify we get the data back");
    for (int i = 0; i < 10; i++) {
        assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(100L));
    }
    String masterNode = internalCluster().getMasterName();
    String otherNode = node1Name.equals(masterNode) ? node2Name : node1Name;
    logger.info("--> add voting config exclusion for non-master node, to be sure it's not elected");
    client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(otherNode)).get();
    logger.info("--> stop master node, no master block should appear");
    Settings masterDataPathSettings = internalCluster().dataPathSettings(masterNode);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNode));
    assertBusy(() -> {
        ClusterState clusterState = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertTrue(clusterState.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
    });
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
    // verify that both nodes are still in the cluster state but there is no master
    assertThat(state.nodes().getSize(), equalTo(2));
    assertThat(state.nodes().getMasterNode(), equalTo(null));
    logger.info("--> starting the previous master node again...");
    node2Name = internalCluster().startNode(Settings.builder().put(settings).put(masterDataPathSettings).build());
    clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().setWaitForNodes("2").execute().actionGet();
    assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.nodes().getSize(), equalTo(2));
    assertThat(state.metadata().indices().containsKey("test"), equalTo(true));
    ensureGreen();
    logger.info("--> verify we get the data back after cluster reform");
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
    }
    logger.info("--> clearing voting config exclusions");
    ClearVotingConfigExclusionsRequest clearRequest = new ClearVotingConfigExclusionsRequest();
    clearRequest.setWaitForRemoval(false);
    client().execute(ClearVotingConfigExclusionsAction.INSTANCE, clearRequest).get();
    masterNode = internalCluster().getMasterName();
    otherNode = node1Name.equals(masterNode) ? node2Name : node1Name;
    logger.info("--> add voting config exclusion for master node, to be sure it's not elected");
    client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(masterNode)).get();
    logger.info("--> stop non-master node, no master block should appear");
    Settings otherNodeDataPathSettings = internalCluster().dataPathSettings(otherNode);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(otherNode));
    assertBusy(() -> {
        ClusterState state1 = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertThat(state1.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
    });
    logger.info("--> starting the previous master node again...");
    internalCluster().startNode(Settings.builder().put(settings).put(otherNodeDataPathSettings).build());
    ensureGreen();
    clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("2").setWaitForGreenStatus().execute().actionGet();
    assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.nodes().getSize(), equalTo(2));
    assertThat(state.metadata().indices().containsKey("test"), equalTo(true));
    logger.info("Running Cluster Health");
    ensureGreen();
    logger.info("--> verify we the data back");
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
    }
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) AddVotingConfigExclusionsRequest(org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest) ClearVotingConfigExclusionsRequest(org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest) Settings(org.opensearch.common.settings.Settings)

Example 2 with ClearVotingConfigExclusionsRequest

use of org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest in project OpenSearch by opensearch-project.

the class MinimumClusterManagerNodesIT method testTwoNodesNoClusterManagerBlock.

public void testTwoNodesNoClusterManagerBlock() throws Exception {
    internalCluster().setBootstrapClusterManagerNodeIndex(1);
    Settings settings = Settings.builder().put("discovery.initial_state_timeout", "500ms").build();
    logger.info("--> start first node");
    String node1Name = internalCluster().startNode(settings);
    logger.info("--> should be blocked, no cluster-manager...");
    ClusterState state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
    // verify that we still see the local node in the cluster state
    assertThat(state.nodes().getSize(), equalTo(1));
    logger.info("--> start second node, cluster should be formed");
    String node2Name = internalCluster().startNode(settings);
    ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("2").execute().actionGet();
    assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.nodes().getSize(), equalTo(2));
    assertThat(state.metadata().indices().containsKey("test"), equalTo(false));
    createIndex("test");
    NumShards numShards = getNumShards("test");
    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        client().prepareIndex("test").setId(Integer.toString(i)).setSource("field", "value").execute().actionGet();
    }
    // make sure that all shards recovered before trying to flush
    assertThat(client().admin().cluster().prepareHealth("test").setWaitForActiveShards(numShards.totalNumShards).execute().actionGet().getActiveShards(), equalTo(numShards.totalNumShards));
    // flush for simpler debugging
    flushAndRefresh();
    logger.info("--> verify we get the data back");
    for (int i = 0; i < 10; i++) {
        assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits().value, equalTo(100L));
    }
    String clusterManagerNode = internalCluster().getMasterName();
    String otherNode = node1Name.equals(clusterManagerNode) ? node2Name : node1Name;
    logger.info("--> add voting config exclusion for non-cluster-manager node, to be sure it's not elected");
    client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(otherNode)).get();
    logger.info("--> stop cluster-manager node, no cluster-manager block should appear");
    Settings clusterManagerDataPathSettings = internalCluster().dataPathSettings(clusterManagerNode);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(clusterManagerNode));
    assertBusy(() -> {
        ClusterState clusterState = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertTrue(clusterState.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
    });
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
    // verify that both nodes are still in the cluster state but there is no cluster-manager
    assertThat(state.nodes().getSize(), equalTo(2));
    assertThat(state.nodes().getMasterNode(), equalTo(null));
    logger.info("--> starting the previous cluster-manager node again...");
    node2Name = internalCluster().startNode(Settings.builder().put(settings).put(clusterManagerDataPathSettings).build());
    clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().setWaitForNodes("2").execute().actionGet();
    assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.nodes().getSize(), equalTo(2));
    assertThat(state.metadata().indices().containsKey("test"), equalTo(true));
    ensureGreen();
    logger.info("--> verify we get the data back after cluster reform");
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
    }
    logger.info("--> clearing voting config exclusions");
    ClearVotingConfigExclusionsRequest clearRequest = new ClearVotingConfigExclusionsRequest();
    clearRequest.setWaitForRemoval(false);
    client().execute(ClearVotingConfigExclusionsAction.INSTANCE, clearRequest).get();
    clusterManagerNode = internalCluster().getMasterName();
    otherNode = node1Name.equals(clusterManagerNode) ? node2Name : node1Name;
    logger.info("--> add voting config exclusion for cluster-manager node, to be sure it's not elected");
    client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(clusterManagerNode)).get();
    logger.info("--> stop non-cluster-manager node, no cluster-manager block should appear");
    Settings otherNodeDataPathSettings = internalCluster().dataPathSettings(otherNode);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(otherNode));
    assertBusy(() -> {
        ClusterState state1 = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertThat(state1.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
    });
    logger.info("--> starting the previous cluster-manager node again...");
    internalCluster().startNode(Settings.builder().put(settings).put(otherNodeDataPathSettings).build());
    ensureGreen();
    clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("2").setWaitForGreenStatus().execute().actionGet();
    assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
    assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.nodes().getSize(), equalTo(2));
    assertThat(state.metadata().indices().containsKey("test"), equalTo(true));
    logger.info("Running Cluster Health");
    ensureGreen();
    logger.info("--> verify we the data back");
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
    }
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) AddVotingConfigExclusionsRequest(org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest) ClearVotingConfigExclusionsRequest(org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest) Settings(org.opensearch.common.settings.Settings)

Example 3 with ClearVotingConfigExclusionsRequest

use of org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest in project OpenSearch by opensearch-project.

the class InternalTestCluster method removeExclusions.

private void removeExclusions(Set<String> excludedNodeIds) {
    assert Thread.holdsLock(this);
    if (excludedNodeIds.isEmpty() == false) {
        logger.info("removing voting config exclusions for {} after restart/shutdown", excludedNodeIds);
        try {
            Client client = getRandomNodeAndClient(node -> excludedNodeIds.contains(node.name) == false).client();
            client.execute(ClearVotingConfigExclusionsAction.INSTANCE, new ClearVotingConfigExclusionsRequest()).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new AssertionError("unexpected", e);
        }
    }
}
Also used : SeqNoStats(org.opensearch.index.seqno.SeqNoStats) SequenceNumbers(org.opensearch.index.seqno.SequenceNumbers) Arrays(java.util.Arrays) ClusterBootstrapService(org.opensearch.cluster.coordination.ClusterBootstrapService) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) ScriptModule(org.opensearch.script.ScriptModule) Matchers.not(org.hamcrest.Matchers.not) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ThrottlingAllocationDecider(org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) FileSystemUtils(org.opensearch.common.io.FileSystemUtils) FutureUtils(org.opensearch.common.util.concurrent.FutureUtils) LuceneTestCase.rarely(org.apache.lucene.tests.util.LuceneTestCase.rarely) NodeRoles.dataOnlyNode(org.opensearch.test.NodeRoles.dataOnlyNode) Strings(org.opensearch.common.Strings) ClearVotingConfigExclusionsRequest(org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest) InternalEngine(org.opensearch.index.engine.InternalEngine) IndexShardTestCase(org.opensearch.index.shard.IndexShardTestCase) Future(java.util.concurrent.Future) RandomNumbers(com.carrotsearch.randomizedtesting.generators.RandomNumbers) NodeRoles.removeRoles(org.opensearch.test.NodeRoles.removeRoles) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ObjectLongMap(com.carrotsearch.hppc.ObjectLongMap) Path(java.nio.file.Path) RandomStrings(com.carrotsearch.randomizedtesting.generators.RandomStrings) NodeEnvironment(org.opensearch.env.NodeEnvironment) ScriptService(org.opensearch.script.ScriptService) Client(org.opensearch.client.Client) ClearVotingConfigExclusionsAction(org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction) TimeValue(org.opensearch.common.unit.TimeValue) Index(org.opensearch.index.Index) AddVotingConfigExclusionsRequest(org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) TaskManager(org.opensearch.tasks.TaskManager) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest) TimeValue.timeValueSeconds(org.opensearch.common.unit.TimeValue.timeValueSeconds) Engine(org.opensearch.index.engine.Engine) UncheckedIOException(java.io.UncheckedIOException) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) Randomness(org.opensearch.common.Randomness) Assert.assertFalse(org.junit.Assert.assertFalse) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Builder(org.opensearch.common.settings.Settings.Builder) IntObjectCursor(com.carrotsearch.hppc.cursors.IntObjectCursor) RandomPicks(com.carrotsearch.randomizedtesting.generators.RandomPicks) LifecycleListener(org.opensearch.common.component.LifecycleListener) HierarchyCircuitBreakerService(org.opensearch.indices.breaker.HierarchyCircuitBreakerService) Node(org.opensearch.node.Node) MockTransportService(org.opensearch.test.transport.MockTransportService) ZEN2_DISCOVERY_TYPE(org.opensearch.discovery.DiscoveryModule.ZEN2_DISCOVERY_TYPE) UNICAST_HOSTS_FILE(org.opensearch.discovery.FileBasedSeedHostsProvider.UNICAST_HOSTS_FILE) OpenSearchExecutors(org.opensearch.common.util.concurrent.OpenSearchExecutors) ArrayList(java.util.ArrayList) DISCOVERY_TYPE_SETTING(org.opensearch.discovery.DiscoveryModule.DISCOVERY_TYPE_SETTING) DocIdSeqNoAndSource(org.opensearch.index.engine.DocIdSeqNoAndSource) ClusterState(org.opensearch.cluster.ClusterState) NoMasterBlockService(org.opensearch.cluster.coordination.NoMasterBlockService) HttpServerTransport(org.opensearch.http.HttpServerTransport) Environment(org.opensearch.env.Environment) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Files(java.nio.file.Files) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) IndexService(org.opensearch.index.IndexService) Plugin(org.opensearch.plugins.Plugin) SeedUtils(com.carrotsearch.randomizedtesting.SeedUtils) NodeValidationException(org.opensearch.node.NodeValidationException) SecureSettings(org.opensearch.common.settings.SecureSettings) ExecutionException(java.util.concurrent.ExecutionException) TransportSettings(org.opensearch.transport.TransportSettings) TreeMap(java.util.TreeMap) Flag(org.opensearch.action.admin.indices.stats.CommonStatsFlags.Flag) ClusterService(org.opensearch.cluster.service.ClusterService) PageCacheRecycler(org.opensearch.common.util.PageCacheRecycler) Assert.assertEquals(org.junit.Assert.assertEquals) ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit) Random(java.util.Random) CircuitBreaker(org.opensearch.common.breaker.CircuitBreaker) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Releasables(org.opensearch.common.lease.Releasables) CommonStatsFlags(org.opensearch.action.admin.indices.stats.CommonStatsFlags) INITIAL_CLUSTER_MANAGER_NODES_SETTING(org.opensearch.cluster.coordination.ClusterBootstrapService.INITIAL_CLUSTER_MANAGER_NODES_SETTING) Assert.assertThat(org.junit.Assert.assertThat) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assert.fail(org.junit.Assert.fail) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) IndexShardRoutingTable(org.opensearch.cluster.routing.IndexShardRoutingTable) EngineTestCase(org.opensearch.index.engine.EngineTestCase) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IndicesService(org.opensearch.indices.IndicesService) ServiceDisruptionScheme(org.opensearch.test.disruption.ServiceDisruptionScheme) NavigableMap(java.util.NavigableMap) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Nullable(org.opensearch.common.Nullable) Objects(java.util.Objects) OperationRouting(org.opensearch.cluster.routing.OperationRouting) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TEST_NIGHTLY(org.apache.lucene.tests.util.LuceneTestCase.TEST_NIGHTLY) NodeRoles.onlyRole(org.opensearch.test.NodeRoles.onlyRole) IntStream(java.util.stream.IntStream) TimeValue.timeValueMillis(org.opensearch.common.unit.TimeValue.timeValueMillis) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) IndexingPressure(org.opensearch.index.IndexingPressure) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) NodeRoles.noRoles(org.opensearch.test.NodeRoles.noRoles) IndicesFieldDataCache(org.opensearch.indices.fielddata.cache.IndicesFieldDataCache) DiskThresholdSettings(org.opensearch.cluster.routing.allocation.DiskThresholdSettings) Function(java.util.function.Function) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) OpenSearchTestCase.randomFrom(org.opensearch.test.OpenSearchTestCase.randomFrom) MappingUpdatedAction(org.opensearch.cluster.action.index.MappingUpdatedAction) HashSet(java.util.HashSet) IndexRoutingTable(org.opensearch.cluster.routing.IndexRoutingTable) IndexShard(org.opensearch.index.shard.IndexShard) AddVotingConfigExclusionsAction(org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction) ExecutorService(java.util.concurrent.ExecutorService) SearchService(org.opensearch.search.SearchService) OpenSearchTestCase.assertBusy(org.opensearch.test.OpenSearchTestCase.assertBusy) Iterator(java.util.Iterator) NodeService(org.opensearch.node.NodeService) ShardLockObtainFailedException(org.opensearch.env.ShardLockObtainFailedException) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings) TransportReplicationAction(org.opensearch.action.support.replication.TransportReplicationAction) MockNode(org.opensearch.node.MockNode) ShardRouting(org.opensearch.cluster.routing.ShardRouting) IOUtils(org.opensearch.core.internal.io.IOUtils) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) Sets(org.opensearch.common.util.set.Sets) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) Closeable(java.io.Closeable) ClusterName(org.opensearch.cluster.ClusterName) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) ClearVotingConfigExclusionsRequest(org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest) Client(org.opensearch.client.Client) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with ClearVotingConfigExclusionsRequest

use of org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest in project OpenSearch by opensearch-project.

the class RecoveryFromGatewayIT method testTwoNodeFirstNodeCleared.

public void testTwoNodeFirstNodeCleared() throws Exception {
    final String firstNode = internalCluster().startNode();
    internalCluster().startNode();
    client().prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().field("field", "value1").endObject()).execute().actionGet();
    flush();
    client().prepareIndex("test").setId("2").setSource(jsonBuilder().startObject().field("field", "value2").endObject()).execute().actionGet();
    refresh();
    logger.info("Running Cluster Health (wait for the shards to startup)");
    ensureGreen();
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 2);
    }
    Map<String, long[]> primaryTerms = assertAndCapturePrimaryTerms(null);
    client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(firstNode)).get();
    internalCluster().fullRestart(new RestartCallback() {

        @Override
        public Settings onNodeStopped(String nodeName) {
            return Settings.builder().put(RECOVER_AFTER_NODES_SETTING.getKey(), 2).putList(// disable bootstrapping
            INITIAL_CLUSTER_MANAGER_NODES_SETTING.getKey()).build();
        }

        @Override
        public boolean clearData(String nodeName) {
            return firstNode.equals(nodeName);
        }
    });
    logger.info("Running Cluster Health (wait for the shards to startup)");
    ensureGreen();
    primaryTerms = assertAndCapturePrimaryTerms(primaryTerms);
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 2);
    }
    client().execute(ClearVotingConfigExclusionsAction.INSTANCE, new ClearVotingConfigExclusionsRequest()).get();
}
Also used : AddVotingConfigExclusionsRequest(org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest) ClearVotingConfigExclusionsRequest(org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest) RestartCallback(org.opensearch.test.InternalTestCluster.RestartCallback) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Aggregations

AddVotingConfigExclusionsRequest (org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest)4 ClearVotingConfigExclusionsRequest (org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest)4 Settings (org.opensearch.common.settings.Settings)4 ClusterHealthResponse (org.opensearch.action.admin.cluster.health.ClusterHealthResponse)2 ObjectLongMap (com.carrotsearch.hppc.ObjectLongMap)1 IntObjectCursor (com.carrotsearch.hppc.cursors.IntObjectCursor)1 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)1 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)1 SeedUtils (com.carrotsearch.randomizedtesting.SeedUtils)1 RandomNumbers (com.carrotsearch.randomizedtesting.generators.RandomNumbers)1 RandomPicks (com.carrotsearch.randomizedtesting.generators.RandomPicks)1 RandomStrings (com.carrotsearch.randomizedtesting.generators.RandomStrings)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1