Search in sources :

Example 81 with Index

use of org.elasticsearch.index.Index in project elasticsearch by elastic.

the class NodeEnvironmentTests method testCustomDataPaths.

public void testCustomDataPaths() throws Exception {
    String[] dataPaths = tmpPaths();
    NodeEnvironment env = newNodeEnvironment(dataPaths, "/tmp", Settings.EMPTY);
    final Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_INDEX_UUID, "myindexUUID").build();
    IndexSettings s1 = IndexSettingsModule.newIndexSettings("myindex", indexSettings);
    IndexSettings s2 = IndexSettingsModule.newIndexSettings("myindex", Settings.builder().put(indexSettings).put(IndexMetaData.SETTING_DATA_PATH, "/tmp/foo").build());
    Index index = new Index("myindex", "myindexUUID");
    ShardId sid = new ShardId(index, 0);
    assertFalse("no settings should mean no custom data path", s1.hasCustomDataPath());
    assertTrue("settings with path_data should have a custom data path", s2.hasCustomDataPath());
    assertThat(env.availableShardPaths(sid), equalTo(env.availableShardPaths(sid)));
    assertThat(env.resolveCustomLocation(s2, sid), equalTo(PathUtils.get("/tmp/foo/0/" + index.getUUID() + "/0")));
    assertThat("shard paths with a custom data_path should contain only regular paths", env.availableShardPaths(sid), equalTo(stringsToPaths(dataPaths, "nodes/0/indices/" + index.getUUID() + "/0")));
    assertThat("index paths uses the regular template", env.indexPaths(index), equalTo(stringsToPaths(dataPaths, "nodes/0/indices/" + index.getUUID())));
    IndexSettings s3 = new IndexSettings(s2.getIndexMetaData(), Settings.builder().put(NodeEnvironment.ADD_NODE_LOCK_ID_TO_CUSTOM_PATH.getKey(), false).build());
    assertThat(env.availableShardPaths(sid), equalTo(env.availableShardPaths(sid)));
    assertThat(env.resolveCustomLocation(s3, sid), equalTo(PathUtils.get("/tmp/foo/" + index.getUUID() + "/0")));
    assertThat("shard paths with a custom data_path should contain only regular paths", env.availableShardPaths(sid), equalTo(stringsToPaths(dataPaths, "nodes/0/indices/" + index.getUUID() + "/0")));
    assertThat("index paths uses the regular template", env.indexPaths(index), equalTo(stringsToPaths(dataPaths, "nodes/0/indices/" + index.getUUID())));
    env.close();
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexSettings(org.elasticsearch.index.IndexSettings) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 82 with Index

use of org.elasticsearch.index.Index in project elasticsearch by elastic.

the class NodeEnvironmentTests method testResolveIndexFolders.

public void testResolveIndexFolders() throws Exception {
    final NodeEnvironment env = newNodeEnvironment();
    final int numIndices = randomIntBetween(1, 10);
    Map<String, List<Path>> actualIndexDataPaths = new HashMap<>();
    for (int i = 0; i < numIndices; i++) {
        Index index = new Index("foo" + i, "fooUUID" + i);
        Path[] indexPaths = env.indexPaths(index);
        for (Path path : indexPaths) {
            Files.createDirectories(path);
            String fileName = path.getFileName().toString();
            List<Path> paths = actualIndexDataPaths.get(fileName);
            if (paths == null) {
                paths = new ArrayList<>();
            }
            paths.add(path);
            actualIndexDataPaths.put(fileName, paths);
        }
    }
    for (Map.Entry<String, List<Path>> actualIndexDataPathEntry : actualIndexDataPaths.entrySet()) {
        List<Path> actual = actualIndexDataPathEntry.getValue();
        Path[] actualPaths = actual.toArray(new Path[actual.size()]);
        assertThat(actualPaths, equalTo(env.resolveIndexFolder(actualIndexDataPathEntry.getKey())));
    }
    assertTrue("LockedShards: " + env.lockedShards(), env.lockedShards().isEmpty());
    env.close();
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 83 with Index

use of org.elasticsearch.index.Index 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 84 with Index

use of org.elasticsearch.index.Index in project elasticsearch by elastic.

the class MetaDataStateFormatTests method randomMeta.

private MetaData randomMeta() throws IOException {
    int numIndices = randomIntBetween(1, 10);
    MetaData.Builder mdBuilder = MetaData.builder();
    mdBuilder.generateClusterUuidIfNeeded();
    for (int i = 0; i < numIndices; i++) {
        mdBuilder.put(indexBuilder(randomAsciiOfLength(10) + "idx-" + i));
    }
    int numDelIndices = randomIntBetween(0, 5);
    final IndexGraveyard.Builder graveyard = IndexGraveyard.builder();
    for (int i = 0; i < numDelIndices; i++) {
        graveyard.addTombstone(new Index(randomAsciiOfLength(10) + "del-idx-" + i, UUIDs.randomBase64UUID()));
    }
    mdBuilder.indexGraveyard(graveyard.build());
    return mdBuilder.build();
}
Also used : IndexGraveyard(org.elasticsearch.cluster.metadata.IndexGraveyard) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Index(org.elasticsearch.index.Index)

Example 85 with Index

use of org.elasticsearch.index.Index 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

Index (org.elasticsearch.index.Index)366 ShardId (org.elasticsearch.index.shard.ShardId)108 Settings (org.elasticsearch.common.settings.Settings)95 ClusterState (org.elasticsearch.cluster.ClusterState)88 ArrayList (java.util.ArrayList)79 IOException (java.io.IOException)74 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)65 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)65 HashMap (java.util.HashMap)61 Map (java.util.Map)61 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)59 List (java.util.List)56 HashSet (java.util.HashSet)50 Path (java.nio.file.Path)45 IndexSettings (org.elasticsearch.index.IndexSettings)44 IndexService (org.elasticsearch.index.IndexService)43 Set (java.util.Set)40 Metadata (org.elasticsearch.cluster.metadata.Metadata)39 ClusterService (org.elasticsearch.cluster.service.ClusterService)39 ActionListener (org.elasticsearch.action.ActionListener)35