Java Code Examples for org.elasticsearch.env.NodeEnvironment#nodeDataPaths()

The following examples show how to use org.elasticsearch.env.NodeEnvironment#nodeDataPaths() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiDataPathUpgrader.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Runs an upgrade on all shards located under the given node environment if there is more than 1 data.path configured
 * otherwise this method will return immediately.
 */
public static void upgradeMultiDataPath(NodeEnvironment nodeEnv, ESLogger logger) throws IOException {
    if (nodeEnv.nodeDataPaths().length > 1) {
        final MultiDataPathUpgrader upgrader = new MultiDataPathUpgrader(nodeEnv);
        final Set<String> allIndices = nodeEnv.findAllIndices();

        for (String index : allIndices) {
            for (ShardId shardId : findAllShardIds(nodeEnv.indexPaths(new Index(index)))) {
                try (ShardLock lock = nodeEnv.shardLock(shardId, 0)) {
                    if (upgrader.needsUpgrading(shardId)) {
                        final ShardPath shardPath = upgrader.pickShardPath(shardId);
                        upgrader.upgrade(shardId, shardPath);
                        // we have to check if the index path exists since we might
                        // have only upgraded the shard state that is written under /indexname/shardid/_state
                        // in the case we upgraded a dedicated index directory index
                        if (Files.exists(shardPath.resolveIndex())) {
                            upgrader.checkIndex(shardPath);
                        }
                    } else {
                        logger.debug("{} no upgrade needed - already upgraded", shardId);
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: GatewayMetaState.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void ensureNoPre019ShardState(NodeEnvironment nodeEnv) throws Exception {
    for (Path dataLocation : nodeEnv.nodeDataPaths()) {
        final Path stateLocation = dataLocation.resolve(MetaDataStateFormat.STATE_DIR_NAME);
        if (Files.exists(stateLocation)) {
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(stateLocation, "shards-*")) {
                for (Path stateFile : stream) {
                    throw new IllegalStateException("Detected pre 0.19 shard state file please upgrade to a version before "
                            + Version.CURRENT.minimumCompatibilityVersion()
                            + " first to upgrade state structures - shard state found: [" + stateFile.getParent().toAbsolutePath());
                }
            }
        }
    }
}
 
Example 3
Source File: InternalTestCluster.java    From crate with Apache License 2.0 5 votes vote down vote up
private void clearDataIfNeeded(RestartCallback callback) throws IOException {
    if (callback.clearData(name)) {
        NodeEnvironment nodeEnv = node.getNodeEnvironment();
        if (nodeEnv.hasNodeFile()) {
            final Path[] locations = nodeEnv.nodeDataPaths();
            logger.debug("removing node data paths: [{}]", Arrays.toString(locations));
            IOUtils.rm(locations);
        }
    }
}