Search in sources :

Example 21 with NodeEnvironment

use of org.elasticsearch.env.NodeEnvironment in project elasticsearch by elastic.

the class MetaStateServiceTests method testWriteGlobalStateWithIndexAndNoIndexIsLoaded.

public void testWriteGlobalStateWithIndexAndNoIndexIsLoaded() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        MetaData metaData = MetaData.builder().persistentSettings(Settings.builder().put("test1", "value1").build()).build();
        IndexMetaData index = IndexMetaData.builder("test1").settings(indexSettings).build();
        MetaData metaDataWithIndex = MetaData.builder(metaData).put(index, true).build();
        metaStateService.writeGlobalState("test_write", metaDataWithIndex);
        assertThat(metaStateService.loadGlobalState().persistentSettings(), equalTo(metaData.persistentSettings()));
        assertThat(metaStateService.loadGlobalState().hasIndex("test1"), equalTo(false));
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 22 with NodeEnvironment

use of org.elasticsearch.env.NodeEnvironment in project elasticsearch by elastic.

the class RelocationIT method testCancellationCleansTempFiles.

public void testCancellationCleansTempFiles() throws Exception {
    final String indexName = "test";
    final String p_node = internalCluster().startNode();
    prepareCreate(indexName, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1, IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)).get();
    internalCluster().startNode();
    internalCluster().startNode();
    List<IndexRequestBuilder> requests = new ArrayList<>();
    int numDocs = scaledRandomIntBetween(25, 250);
    for (int i = 0; i < numDocs; i++) {
        requests.add(client().prepareIndex(indexName, "type").setSource("{}", XContentType.JSON));
    }
    indexRandom(true, requests);
    assertFalse(client().admin().cluster().prepareHealth().setWaitForNodes("3").setWaitForGreenStatus().get().isTimedOut());
    flush();
    int allowedFailures = randomIntBetween(3, 10);
    logger.info("--> blocking recoveries from primary (allowed failures: [{}])", allowedFailures);
    CountDownLatch corruptionCount = new CountDownLatch(allowedFailures);
    ClusterService clusterService = internalCluster().getInstance(ClusterService.class, p_node);
    MockTransportService mockTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, p_node);
    for (DiscoveryNode node : clusterService.state().nodes()) {
        if (!node.equals(clusterService.localNode())) {
            mockTransportService.addDelegate(internalCluster().getInstance(TransportService.class, node.getName()), new RecoveryCorruption(mockTransportService.original(), corruptionCount));
        }
    }
    client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)).get();
    corruptionCount.await();
    logger.info("--> stopping replica assignment");
    assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none")));
    logger.info("--> wait for all replica shards to be removed, on all nodes");
    assertBusy(() -> {
        for (String node : internalCluster().getNodeNames()) {
            if (node.equals(p_node)) {
                continue;
            }
            ClusterState state = client(node).admin().cluster().prepareState().setLocal(true).get().getState();
            assertThat(node + " indicates assigned replicas", state.getRoutingTable().index(indexName).shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(1));
        }
    });
    logger.info("--> verifying no temporary recoveries are left");
    for (String node : internalCluster().getNodeNames()) {
        NodeEnvironment nodeEnvironment = internalCluster().getInstance(NodeEnvironment.class, node);
        for (final Path shardLoc : nodeEnvironment.availableShardPaths(new ShardId(indexName, "_na_", 0))) {
            if (Files.exists(shardLoc)) {
                assertBusy(() -> {
                    try {
                        Files.walkFileTree(shardLoc, new SimpleFileVisitor<Path>() {

                            @Override
                            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                                assertThat("found a temporary recovery file: " + file, file.getFileName().toString(), not(startsWith("recovery.")));
                                return FileVisitResult.CONTINUE;
                            }
                        });
                    } catch (IOException e) {
                        throw new AssertionError("failed to walk file tree starting at [" + shardLoc + "]", e);
                    }
                });
            }
        }
    }
}
Also used : Path(java.nio.file.Path) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportService(org.elasticsearch.test.transport.MockTransportService) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) ArrayList(java.util.ArrayList) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ShardId(org.elasticsearch.index.shard.ShardId) ClusterService(org.elasticsearch.cluster.service.ClusterService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 23 with NodeEnvironment

use of org.elasticsearch.env.NodeEnvironment in project elasticsearch by elastic.

the class FsProbeTests method testFsInfo.

public void testFsInfo() throws IOException {
    try (NodeEnvironment env = newNodeEnvironment()) {
        FsProbe probe = new FsProbe(Settings.EMPTY, env);
        FsInfo stats = probe.stats(null, null);
        assertNotNull(stats);
        assertThat(stats.getTimestamp(), greaterThan(0L));
        if (Constants.LINUX) {
            assertNotNull(stats.getIoStats());
            assertNotNull(stats.getIoStats().devicesStats);
            for (int i = 0; i < stats.getIoStats().devicesStats.length; i++) {
                final FsInfo.DeviceStats deviceStats = stats.getIoStats().devicesStats[i];
                assertNotNull(deviceStats);
                assertThat(deviceStats.currentReadsCompleted, greaterThanOrEqualTo(0L));
                assertThat(deviceStats.previousReadsCompleted, equalTo(-1L));
                assertThat(deviceStats.currentSectorsRead, greaterThanOrEqualTo(0L));
                assertThat(deviceStats.previousSectorsRead, equalTo(-1L));
                assertThat(deviceStats.currentWritesCompleted, greaterThanOrEqualTo(0L));
                assertThat(deviceStats.previousWritesCompleted, equalTo(-1L));
                assertThat(deviceStats.currentSectorsWritten, greaterThanOrEqualTo(0L));
                assertThat(deviceStats.previousSectorsWritten, equalTo(-1L));
            }
        } else {
            assertNull(stats.getIoStats());
        }
        FsInfo.Path total = stats.getTotal();
        assertNotNull(total);
        assertThat(total.total, greaterThan(0L));
        assertThat(total.free, greaterThan(0L));
        assertThat(total.available, greaterThan(0L));
        for (FsInfo.Path path : stats) {
            assertNotNull(path);
            assertThat(path.getPath(), not(isEmptyOrNullString()));
            assertThat(path.getMount(), not(isEmptyOrNullString()));
            assertThat(path.getType(), not(isEmptyOrNullString()));
            assertThat(path.total, greaterThan(0L));
            assertThat(path.free, greaterThan(0L));
            assertThat(path.available, greaterThan(0L));
        }
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment)

Example 24 with NodeEnvironment

use of org.elasticsearch.env.NodeEnvironment in project elasticsearch by elastic.

the class DanglingIndicesStateTests method testDanglingIndicesDiscovery.

public void testDanglingIndicesDiscovery() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
        assertTrue(danglingState.getDanglingIndices().isEmpty());
        MetaData metaData = MetaData.builder().build();
        final Settings.Builder settings = Settings.builder().put(indexSettings).put(IndexMetaData.SETTING_INDEX_UUID, "test1UUID");
        IndexMetaData dangledIndex = IndexMetaData.builder("test1").settings(settings).build();
        metaStateService.writeIndex("test_write", dangledIndex);
        Map<Index, IndexMetaData> newDanglingIndices = danglingState.findNewDanglingIndices(metaData);
        assertTrue(newDanglingIndices.containsKey(dangledIndex.getIndex()));
        metaData = MetaData.builder().put(dangledIndex, false).build();
        newDanglingIndices = danglingState.findNewDanglingIndices(metaData);
        assertFalse(newDanglingIndices.containsKey(dangledIndex.getIndex()));
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Index(org.elasticsearch.index.Index) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 25 with NodeEnvironment

use of org.elasticsearch.env.NodeEnvironment in project elasticsearch by elastic.

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;
    if (randomBoolean()) {
        // test with a regular index
        logger.info("--> starting a cluster with " + numNodes + " nodes");
        nodes = internalCluster().startNodes(numNodes);
        logger.info("--> create an index");
        createIndex(indexName);
    } else {
        // test with a shadow replica index
        final Path dataPath = createTempDir();
        logger.info("--> created temp data path for shadow replicas [{}]", dataPath);
        logger.info("--> starting a cluster with " + numNodes + " nodes");
        final Settings nodeSettings = Settings.builder().put("node.add_lock_id_to_custom_path", false).put(Environment.PATH_SHARED_DATA_SETTING.getKey(), dataPath.toString()).put("index.store.fs.fs_lock", randomFrom("native", "simple")).build();
        nodes = internalCluster().startNodes(numNodes, nodeSettings);
        logger.info("--> create a shadow replica index");
        createShadowReplicaIndex(indexName, dataPath, numNodes - 1);
    }
    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());
            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 : Path(java.nio.file.Path) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) RestartCallback(org.elasticsearch.test.InternalTestCluster.RestartCallback) Client(org.elasticsearch.client.Client) Settings(org.elasticsearch.common.settings.Settings) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexClosedException(org.elasticsearch.indices.IndexClosedException) MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) IOException(java.io.IOException)

Aggregations

NodeEnvironment (org.elasticsearch.env.NodeEnvironment)39 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)19 Path (java.nio.file.Path)17 Settings (org.elasticsearch.common.settings.Settings)15 Index (org.elasticsearch.index.Index)11 MetaData (org.elasticsearch.cluster.metadata.MetaData)10 IndexSettings (org.elasticsearch.index.IndexSettings)7 IOException (java.io.IOException)5 ClusterState (org.elasticsearch.cluster.ClusterState)5 ShardId (org.elasticsearch.index.shard.ShardId)4 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 ClusterService (org.elasticsearch.cluster.service.ClusterService)3 Environment (org.elasticsearch.env.Environment)3 ShardPath (org.elasticsearch.index.shard.ShardPath)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 SigarModule (io.crate.module.SigarModule)1 DummyExtendedNodeInfo (io.crate.monitor.DummyExtendedNodeInfo)1 ExtendedNodeInfo (io.crate.monitor.ExtendedNodeInfo)1