Search in sources :

Example 6 with NodeEnvironment

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

the class DanglingIndicesStateTests method testDanglingProcessing.

public void testDanglingProcessing() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
        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);
        // check that several runs when not in the metadata still keep the dangled index around
        int numberOfChecks = randomIntBetween(1, 10);
        for (int i = 0; i < numberOfChecks; i++) {
            Map<Index, IndexMetaData> newDanglingIndices = danglingState.findNewDanglingIndices(metaData);
            assertThat(newDanglingIndices.size(), equalTo(1));
            assertThat(newDanglingIndices.keySet(), Matchers.hasItems(dangledIndex.getIndex()));
            assertTrue(danglingState.getDanglingIndices().isEmpty());
        }
        for (int i = 0; i < numberOfChecks; i++) {
            danglingState.findNewAndAddDanglingIndices(metaData);
            assertThat(danglingState.getDanglingIndices().size(), equalTo(1));
            assertThat(danglingState.getDanglingIndices().keySet(), Matchers.hasItems(dangledIndex.getIndex()));
        }
        // simulate allocation to the metadata
        metaData = MetaData.builder(metaData).put(dangledIndex, true).build();
        // check that several runs when in the metadata, but not cleaned yet, still keeps dangled
        for (int i = 0; i < numberOfChecks; i++) {
            Map<Index, IndexMetaData> newDanglingIndices = danglingState.findNewDanglingIndices(metaData);
            assertTrue(newDanglingIndices.isEmpty());
            assertThat(danglingState.getDanglingIndices().size(), equalTo(1));
            assertThat(danglingState.getDanglingIndices().keySet(), Matchers.hasItems(dangledIndex.getIndex()));
        }
        danglingState.cleanupAllocatedDangledIndices(metaData);
        assertTrue(danglingState.getDanglingIndices().isEmpty());
    }
}
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 7 with NodeEnvironment

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

the class DanglingIndicesStateTests method testDanglingIndicesNotImportedWhenTombstonePresent.

public void testDanglingIndicesNotImportedWhenTombstonePresent() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);
        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);
        final IndexGraveyard graveyard = IndexGraveyard.builder().addTombstone(dangledIndex.getIndex()).build();
        final MetaData metaData = MetaData.builder().indexGraveyard(graveyard).build();
        assertThat(danglingState.findNewDanglingIndices(metaData).size(), equalTo(0));
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) IndexGraveyard(org.elasticsearch.cluster.metadata.IndexGraveyard) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 8 with NodeEnvironment

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

the class DanglingIndicesStateTests method testCleanupWhenEmpty.

public void testCleanupWhenEmpty() 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();
        danglingState.cleanupAllocatedDangledIndices(metaData);
        assertTrue(danglingState.getDanglingIndices().isEmpty());
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 9 with NodeEnvironment

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

the class GatewayIndexStateIT method testArchiveBrokenClusterSettings.

public void testArchiveBrokenClusterSettings() throws Exception {
    logger.info("--> starting one node");
    internalCluster().startNode();
    client().prepareIndex("test", "type1", "1").setSource("field1", "value1").setRefreshPolicy(IMMEDIATE).get();
    logger.info("--> waiting for green status");
    if (usually()) {
        ensureYellow();
    } else {
        internalCluster().startNode();
        client().admin().cluster().health(Requests.clusterHealthRequest().waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForNoRelocatingShards(true).waitForNodes("2")).actionGet();
    }
    ClusterState state = client().admin().cluster().prepareState().get().getState();
    MetaData metaData = state.getMetaData();
    for (NodeEnvironment nodeEnv : internalCluster().getInstances(NodeEnvironment.class)) {
        MetaData brokenMeta = MetaData.builder(metaData).persistentSettings(Settings.builder().put(metaData.persistentSettings()).put("this.is.unknown", true).put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), "broken").build()).build();
        MetaData.FORMAT.write(brokenMeta, nodeEnv.nodeDataPaths());
    }
    internalCluster().fullRestart();
    // wait for state recovery
    ensureYellow("test");
    state = client().admin().cluster().prepareState().get().getState();
    assertEquals("true", state.metaData().persistentSettings().get("archived.this.is.unknown"));
    assertEquals("broken", state.metaData().persistentSettings().get("archived." + ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey()));
    // delete these settings
    client().admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder().putNull("archived.*")).get();
    state = client().admin().cluster().prepareState().get().getState();
    assertNull(state.metaData().persistentSettings().get("archived.this.is.unknown"));
    assertNull(state.metaData().persistentSettings().get("archived." + ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey()));
    assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MetaData(org.elasticsearch.cluster.metadata.MetaData) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 10 with NodeEnvironment

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

the class MetaStateServiceTests method testLoadMissingIndex.

public void testLoadMissingIndex() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        assertThat(metaStateService.loadIndexState(new Index("test1", "test1UUID")), nullValue());
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Index(org.elasticsearch.index.Index)

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