Search in sources :

Example 1 with NodeEnvironment

use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.

the class UnsafeBootstrapAndDetachCommandIT method testDetachNodeLocked.

public void testDetachNodeLocked() throws IOException {
    Settings envSettings = buildEnvSettings(Settings.EMPTY);
    Environment environment = TestEnvironment.newEnvironment(envSettings);
    try (NodeEnvironment ignored = new NodeEnvironment(envSettings, environment)) {
        expectThrows(() -> detachCluster(environment), OpenSearchNodeCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
    }
}
Also used : NodeEnvironment(org.opensearch.env.NodeEnvironment) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Example 2 with NodeEnvironment

use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.

the class UnsafeBootstrapAndDetachCommandIT method testBootstrapNoClusterState.

public void testBootstrapNoClusterState() throws IOException {
    internalCluster().setBootstrapMasterNodeIndex(0);
    String node = internalCluster().startNode();
    Settings dataPathSettings = internalCluster().dataPathSettings(node);
    ensureStableCluster(1);
    NodeEnvironment nodeEnvironment = internalCluster().getMasterNodeInstance(NodeEnvironment.class);
    internalCluster().stopRandomDataNode();
    Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
    PersistedClusterStateService.deleteAll(nodeEnvironment.nodeDataPaths());
    expectThrows(() -> unsafeBootstrap(environment), OpenSearchNodeCommand.NO_NODE_METADATA_FOUND_MSG);
}
Also used : NodeEnvironment(org.opensearch.env.NodeEnvironment) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Example 3 with NodeEnvironment

use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.

the class GatewayIndexStateIT method testIndexDeletionWhenNodeRejoins.

/**
 * This test ensures that when an index deletion takes place while a node is offline, when that
 * node rejoins the cluster, it deletes the index locally instead of importing it as a dangling index.
 */
public void testIndexDeletionWhenNodeRejoins() throws Exception {
    final String indexName = "test-index-del-on-node-rejoin-idx";
    final int numNodes = 2;
    final List<String> nodes;
    logger.info("--> starting a cluster with " + numNodes + " nodes");
    nodes = internalCluster().startNodes(numNodes, Settings.builder().put(IndexGraveyard.SETTING_MAX_TOMBSTONES.getKey(), randomIntBetween(10, 100)).build());
    logger.info("--> create an index");
    createIndex(indexName);
    logger.info("--> waiting for green status");
    ensureGreen();
    final String indexUUID = resolveIndex(indexName).getUUID();
    logger.info("--> restart a random date node, deleting the index in between stopping and restarting");
    internalCluster().restartRandomDataNode(new RestartCallback() {

        @Override
        public Settings onNodeStopped(final String nodeName) throws Exception {
            nodes.remove(nodeName);
            logger.info("--> stopped node[{}], remaining nodes {}", nodeName, nodes);
            assert nodes.size() > 0;
            final String otherNode = nodes.get(0);
            logger.info("--> delete index and verify it is deleted");
            final Client client = client(otherNode);
            client.admin().indices().prepareDelete(indexName).execute().actionGet();
            assertFalse(client.admin().indices().prepareExists(indexName).execute().actionGet().isExists());
            logger.info("--> index deleted");
            return super.onNodeStopped(nodeName);
        }
    });
    logger.info("--> wait until all nodes are back online");
    client().admin().cluster().health(Requests.clusterHealthRequest().waitForEvents(Priority.LANGUID).waitForNodes(Integer.toString(numNodes))).actionGet();
    logger.info("--> waiting for green status");
    ensureGreen();
    logger.info("--> verify that the deleted index is removed from the cluster and not reimported as dangling by the restarted node");
    assertFalse(client().admin().indices().prepareExists(indexName).execute().actionGet().isExists());
    assertBusy(() -> {
        final NodeEnvironment nodeEnv = internalCluster().getInstance(NodeEnvironment.class);
        try {
            assertFalse("index folder " + indexUUID + " should be deleted", nodeEnv.availableIndexFolders().contains(indexUUID));
        } catch (IOException e) {
            logger.error("Unable to retrieve available index folders from the node", e);
            fail("Unable to retrieve available index folders from the node");
        }
    });
}
Also used : NodeEnvironment(org.opensearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) RestartCallback(org.opensearch.test.InternalTestCluster.RestartCallback) Client(org.opensearch.client.Client) OpenSearchException(org.opensearch.OpenSearchException) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) IndexClosedException(org.opensearch.indices.IndexClosedException) IOException(java.io.IOException) Settings(org.opensearch.common.settings.Settings)

Example 4 with NodeEnvironment

use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.

the class UnsafeBootstrapAndDetachCommandIT method test3MasterNodes2Failed.

public void test3MasterNodes2Failed() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(2);
    List<String> masterNodes = new ArrayList<>();
    logger.info("--> start 1st master-eligible node");
    masterNodes.add(internalCluster().startMasterOnlyNode(Settings.builder().put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build()));
    // node ordinal 0
    logger.info("--> start one data-only node");
    String dataNode = internalCluster().startDataOnlyNode(Settings.builder().put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build());
    // node ordinal 1
    logger.info("--> start 2nd and 3rd master-eligible nodes and bootstrap");
    // node ordinals 2 and 3
    masterNodes.addAll(internalCluster().startMasterOnlyNodes(2));
    logger.info("--> wait for all nodes to join the cluster");
    ensureStableCluster(4);
    List<String> currentClusterNodes = new ArrayList<>(masterNodes);
    currentClusterNodes.add(dataNode);
    currentClusterNodes.forEach(node -> ensureReadOnlyBlock(false, node));
    logger.info("--> create index test");
    createIndex("test");
    ensureGreen("test");
    Settings master1DataPathSettings = internalCluster().dataPathSettings(masterNodes.get(0));
    Settings master2DataPathSettings = internalCluster().dataPathSettings(masterNodes.get(1));
    Settings master3DataPathSettings = internalCluster().dataPathSettings(masterNodes.get(2));
    Settings dataNodeDataPathSettings = internalCluster().dataPathSettings(dataNode);
    logger.info("--> stop 2nd and 3d master eligible node");
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(1)));
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(2)));
    logger.info("--> ensure NO_MASTER_BLOCK on data-only node");
    assertBusy(() -> {
        ClusterState state = internalCluster().client(dataNode).admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
    });
    logger.info("--> try to unsafely bootstrap 1st master-eligible node, while node lock is held");
    Environment environmentMaster1 = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(master1DataPathSettings).build());
    expectThrows(() -> unsafeBootstrap(environmentMaster1), UnsafeBootstrapMasterCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);
    logger.info("--> stop 1st master-eligible node and data-only node");
    NodeEnvironment nodeEnvironment = internalCluster().getMasterNodeInstance(NodeEnvironment.class);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(0)));
    assertBusy(() -> internalCluster().getInstance(GatewayMetaState.class, dataNode).allPendingAsyncStatesWritten());
    internalCluster().stopRandomDataNode();
    logger.info("--> unsafely-bootstrap 1st master-eligible node");
    MockTerminal terminal = unsafeBootstrap(environmentMaster1, false, true);
    Metadata metadata = OpenSearchNodeCommand.createPersistedClusterStateService(Settings.EMPTY, nodeEnvironment.nodeDataPaths()).loadBestOnDiskState().metadata;
    assertThat(terminal.getOutput(), containsString(String.format(Locale.ROOT, UnsafeBootstrapMasterCommand.CLUSTER_STATE_TERM_VERSION_MSG_FORMAT, metadata.coordinationMetadata().term(), metadata.version())));
    logger.info("--> start 1st master-eligible node");
    String masterNode2 = internalCluster().startMasterOnlyNode(master1DataPathSettings);
    logger.info("--> detach-cluster on data-only node");
    Environment environmentData = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataNodeDataPathSettings).build());
    detachCluster(environmentData, false);
    logger.info("--> start data-only node");
    String dataNode2 = internalCluster().startDataOnlyNode(dataNodeDataPathSettings);
    logger.info("--> ensure there is no NO_MASTER_BLOCK and unsafe-bootstrap is reflected in cluster state");
    assertBusy(() -> {
        ClusterState state = internalCluster().client(dataNode2).admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
        assertFalse(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
        assertTrue(state.metadata().persistentSettings().getAsBoolean(UnsafeBootstrapMasterCommand.UNSAFE_BOOTSTRAP.getKey(), false));
    });
    List<String> bootstrappedNodes = new ArrayList<>();
    bootstrappedNodes.add(dataNode2);
    bootstrappedNodes.add(masterNode2);
    bootstrappedNodes.forEach(node -> ensureReadOnlyBlock(true, node));
    logger.info("--> ensure index test is green");
    ensureGreen("test");
    IndexMetadata indexMetadata = clusterService().state().metadata().index("test");
    assertThat(indexMetadata.getSettings().get(IndexMetadata.SETTING_HISTORY_UUID), notNullValue());
    logger.info("--> detach-cluster on 2nd and 3rd master-eligible nodes");
    Environment environmentMaster2 = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(master2DataPathSettings).build());
    detachCluster(environmentMaster2, false);
    Environment environmentMaster3 = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(master3DataPathSettings).build());
    detachCluster(environmentMaster3, false);
    logger.info("--> start 2nd and 3rd master-eligible nodes and ensure 4 nodes stable cluster");
    bootstrappedNodes.add(internalCluster().startMasterOnlyNode(master2DataPathSettings));
    bootstrappedNodes.add(internalCluster().startMasterOnlyNode(master3DataPathSettings));
    ensureStableCluster(4);
    bootstrappedNodes.forEach(node -> ensureReadOnlyBlock(true, node));
    removeBlock();
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) NodeEnvironment(org.opensearch.env.NodeEnvironment) ArrayList(java.util.ArrayList) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) MockTerminal(org.opensearch.cli.MockTerminal) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Example 5 with NodeEnvironment

use of org.opensearch.env.NodeEnvironment in project OpenSearch by opensearch-project.

the class UnsafeBootstrapAndDetachCommandIT method testDetachNoClusterState.

public void testDetachNoClusterState() throws IOException {
    internalCluster().setBootstrapMasterNodeIndex(0);
    String node = internalCluster().startNode();
    Settings dataPathSettings = internalCluster().dataPathSettings(node);
    ensureStableCluster(1);
    NodeEnvironment nodeEnvironment = internalCluster().getMasterNodeInstance(NodeEnvironment.class);
    internalCluster().stopRandomDataNode();
    Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
    PersistedClusterStateService.deleteAll(nodeEnvironment.nodeDataPaths());
    expectThrows(() -> detachCluster(environment), OpenSearchNodeCommand.NO_NODE_METADATA_FOUND_MSG);
}
Also used : NodeEnvironment(org.opensearch.env.NodeEnvironment) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings)

Aggregations

NodeEnvironment (org.opensearch.env.NodeEnvironment)62 Settings (org.opensearch.common.settings.Settings)36 Path (java.nio.file.Path)32 Matchers.containsString (org.hamcrest.Matchers.containsString)22 ClusterState (org.opensearch.cluster.ClusterState)21 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)19 ClusterSettings (org.opensearch.common.settings.ClusterSettings)17 IndexWriter (org.apache.lucene.index.IndexWriter)16 Metadata (org.opensearch.cluster.metadata.Metadata)16 Writer (org.opensearch.gateway.PersistedClusterStateService.Writer)16 Index (org.opensearch.index.Index)13 IOException (java.io.IOException)12 FilterDirectory (org.apache.lucene.store.FilterDirectory)9 Environment (org.opensearch.env.Environment)9 ArrayList (java.util.ArrayList)7 Directory (org.apache.lucene.store.Directory)7 TestThreadPool (org.opensearch.threadpool.TestThreadPool)7 FileSystem (java.nio.file.FileSystem)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)6