Search in sources :

Example 11 with NodeEnvironment

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

the class MetaStateServiceTests method testWriteLoadIndex.

public void testWriteLoadIndex() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        IndexMetaData index = IndexMetaData.builder("test1").settings(indexSettings).build();
        metaStateService.writeIndex("test_write", index);
        assertThat(metaStateService.loadIndexState(index.getIndex()), equalTo(index));
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 12 with NodeEnvironment

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

the class IndexWithShadowReplicasIT method assertIndicesDirsDeleted.

private static void assertIndicesDirsDeleted(final List<String> nodes) throws IOException {
    for (String node : nodes) {
        final NodeEnvironment nodeEnv = internalCluster().getInstance(NodeEnvironment.class, node);
        assertThat(nodeEnv.availableIndexFolders(), equalTo(Collections.emptySet()));
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment)

Example 13 with NodeEnvironment

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

the class IndexShardIT method testLockTryingToDelete.

public void testLockTryingToDelete() throws Exception {
    createIndex("test");
    ensureGreen();
    NodeEnvironment env = getInstanceFromNode(NodeEnvironment.class);
    ClusterService cs = getInstanceFromNode(ClusterService.class);
    final Index index = cs.state().metaData().index("test").getIndex();
    Path[] shardPaths = env.availableShardPaths(new ShardId(index, 0));
    logger.info("--> paths: [{}]", (Object) shardPaths);
    // Should not be able to acquire the lock because it's already open
    try {
        NodeEnvironment.acquireFSLockForPaths(IndexSettingsModule.newIndexSettings("test", Settings.EMPTY), shardPaths);
        fail("should not have been able to acquire the lock");
    } catch (LockObtainFailedException e) {
        assertTrue("msg: " + e.getMessage(), e.getMessage().contains("unable to acquire write.lock"));
    }
    // Test without the regular shard lock to assume we can acquire it
    // (worst case, meaning that the shard lock could be acquired and
    // we're green to delete the shard's directory)
    ShardLock sLock = new DummyShardLock(new ShardId(index, 0));
    try {
        env.deleteShardDirectoryUnderLock(sLock, IndexSettingsModule.newIndexSettings("test", Settings.EMPTY));
        fail("should not have been able to delete the directory");
    } catch (LockObtainFailedException e) {
        assertTrue("msg: " + e.getMessage(), e.getMessage().contains("unable to acquire write.lock"));
    }
}
Also used : Path(java.nio.file.Path) ClusterService(org.elasticsearch.cluster.service.ClusterService) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) Index(org.elasticsearch.index.Index) DummyShardLock(org.elasticsearch.test.DummyShardLock) ShardLock(org.elasticsearch.env.ShardLock) DummyShardLock(org.elasticsearch.test.DummyShardLock)

Example 14 with NodeEnvironment

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

the class ShardPathTests method testFailLoadShardPathIndexUUIDMissmatch.

public void testFailLoadShardPathIndexUUIDMissmatch() throws IOException {
    try (NodeEnvironment env = newNodeEnvironment(Settings.builder().build())) {
        Settings.Builder builder = Settings.builder().put(IndexMetaData.SETTING_INDEX_UUID, "foobar").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
        Settings settings = builder.build();
        ShardId shardId = new ShardId("foo", "foobar", 0);
        Path[] paths = env.availableShardPaths(shardId);
        Path path = randomFrom(paths);
        ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, "0xDEADBEEF", AllocationId.newInitializing()), path);
        Exception e = expectThrows(IllegalStateException.class, () -> ShardPath.loadShardPath(logger, env, shardId, IndexSettingsModule.newIndexSettings(shardId.getIndex(), settings)));
        assertThat(e.getMessage(), containsString("expected: foobar on shard path"));
    }
}
Also used : Path(java.nio.file.Path) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Settings(org.elasticsearch.common.settings.Settings) IOException(java.io.IOException)

Example 15 with NodeEnvironment

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

the class ShardPathTests method testFailLoadShardPathOnMultiState.

public void testFailLoadShardPathOnMultiState() throws IOException {
    try (NodeEnvironment env = newNodeEnvironment(Settings.builder().build())) {
        final String indexUUID = "0xDEADBEEF";
        Settings.Builder builder = Settings.builder().put(IndexMetaData.SETTING_INDEX_UUID, indexUUID).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
        Settings settings = builder.build();
        ShardId shardId = new ShardId("foo", indexUUID, 0);
        Path[] paths = env.availableShardPaths(shardId);
        assumeTrue("This test tests multi data.path but we only got one", paths.length > 1);
        ShardStateMetaData.FORMAT.write(new ShardStateMetaData(true, indexUUID, AllocationId.newInitializing()), paths);
        Exception e = expectThrows(IllegalStateException.class, () -> ShardPath.loadShardPath(logger, env, shardId, IndexSettingsModule.newIndexSettings(shardId.getIndex(), settings)));
        assertThat(e.getMessage(), containsString("more than one shard state found"));
    }
}
Also used : Path(java.nio.file.Path) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings) 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