Search in sources :

Example 36 with NodeEnvironment

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

the class IndexFolderUpgraderTests method testNeedsUpgrade.

public void testNeedsUpgrade() throws IOException {
    final Index index = new Index("foo", UUIDs.randomBase64UUID());
    IndexMetaData indexState = IndexMetaData.builder(index.getName()).settings(Settings.builder().put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)).numberOfShards(1).numberOfReplicas(0).build();
    try (NodeEnvironment nodeEnvironment = newNodeEnvironment()) {
        IndexMetaData.FORMAT.write(indexState, nodeEnvironment.indexPaths(index));
        assertFalse(IndexFolderUpgrader.needsUpgrade(index, index.getUUID()));
    }
}
Also used : NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Index(org.elasticsearch.index.Index) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 37 with NodeEnvironment

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

the class IndexFolderUpgraderTests method testPartialUpgradeCustomDataPath.

/**
     * tests upgrade on partially upgraded index, when we crash while upgrading
     */
public void testPartialUpgradeCustomDataPath() throws IOException {
    Path customPath = createTempDir();
    final Settings nodeSettings = Settings.builder().put(NodeEnvironment.ADD_NODE_LOCK_ID_TO_CUSTOM_PATH.getKey(), randomBoolean()).put(Environment.PATH_SHARED_DATA_SETTING.getKey(), customPath.toAbsolutePath().toString()).build();
    try (NodeEnvironment nodeEnv = newNodeEnvironment(nodeSettings)) {
        final Index index = new Index(randomAsciiOfLength(10), UUIDs.randomBase64UUID());
        Settings settings = Settings.builder().put(nodeSettings).put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_0_0).put(IndexMetaData.SETTING_DATA_PATH, customPath.toAbsolutePath().toString()).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 5)).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build();
        IndexMetaData indexState = IndexMetaData.builder(index.getName()).settings(settings).build();
        int numIdxFiles = randomIntBetween(1, 5);
        int numTranslogFiles = randomIntBetween(1, 5);
        IndexSettings indexSettings = new IndexSettings(indexState, nodeSettings);
        writeIndex(nodeEnv, indexSettings, numIdxFiles, numTranslogFiles);
        IndexFolderUpgrader helper = new IndexFolderUpgrader(settings, nodeEnv) {

            @Override
            void upgrade(Index index, Path source, Path target) throws IOException {
                if (randomBoolean()) {
                    throw new FileNotFoundException("simulated");
                }
            }
        };
        // only upgrade some paths
        try {
            helper.upgrade(index.getName());
        } catch (IOException e) {
            assertTrue(e instanceof FileNotFoundException);
        }
        helper = new IndexFolderUpgrader(settings, nodeEnv);
        // try to upgrade again
        helper.upgrade(indexSettings.getIndex().getName());
        checkIndex(nodeEnv, indexSettings, numIdxFiles, numTranslogFiles);
    }
}
Also used : Path(java.nio.file.Path) ShardPath(org.elasticsearch.index.shard.ShardPath) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) IndexSettings(org.elasticsearch.index.IndexSettings) FileNotFoundException(java.io.FileNotFoundException) Index(org.elasticsearch.index.Index) IOException(java.io.IOException) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 38 with NodeEnvironment

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

the class IndicesStoreIntegrationIT method shardDirectory.

private Path shardDirectory(String server, Index index, int shard) {
    NodeEnvironment env = internalCluster().getInstance(NodeEnvironment.class, server);
    final Path[] paths = env.availableShardPaths(new ShardId(index, shard));
    assert paths.length == 1;
    return paths[0];
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Path(java.nio.file.Path) NodeEnvironment(org.elasticsearch.env.NodeEnvironment)

Example 39 with NodeEnvironment

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

the class IndicesStoreIntegrationIT method indexDirectory.

private Path indexDirectory(String server, Index index) {
    NodeEnvironment env = internalCluster().getInstance(NodeEnvironment.class, server);
    final Path[] paths = env.indexPaths(index);
    assert paths.length == 1;
    return paths[0];
}
Also used : Path(java.nio.file.Path) NodeEnvironment(org.elasticsearch.env.NodeEnvironment)

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