Java Code Examples for org.elasticsearch.env.NodeEnvironment#NodePath

The following examples show how to use org.elasticsearch.env.NodeEnvironment#NodePath . 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: ShardPath.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/** Maps each path.data path to a "guess" of how many bytes the shards allocated to that path might additionally use over their
 *  lifetime; we do this so a bunch of newly allocated shards won't just all go the path with the most free space at this moment. */
private static Map<Path,Long> getEstimatedReservedBytes(NodeEnvironment env, long avgShardSizeInBytes, Iterable<IndexShard> shards) throws IOException {
    long totFreeSpace = 0;
    for (NodeEnvironment.NodePath nodePath : env.nodePaths()) {
        totFreeSpace += nodePath.getUsableSpace();
    }

    // Very rough heurisic of how much disk space we expect the shard will use over its lifetime, the max of current average
    // shard size across the cluster and 5% of the total available free space on this node:
    long estShardSizeInBytes = Math.max(avgShardSizeInBytes, (long) (totFreeSpace/20.0));

    // Collate predicted (guessed!) disk usage on each path.data:
    Map<Path,Long> reservedBytes = new HashMap<>();
    for (IndexShard shard : shards) {
        Path dataPath = NodeEnvironment.shardStatePathToDataPath(shard.shardPath().getShardStatePath());

        // Remove indices/<index>/<shardID> subdirs from the statePath to get back to the path.data/<lockID>:
        Long curBytes = reservedBytes.get(dataPath);
        if (curBytes == null) {
            curBytes = 0L;
        }
        reservedBytes.put(dataPath, curBytes + estShardSizeInBytes);
    }       

    return reservedBytes;
}
 
Example 2
Source File: ShardPath.java    From crate with Apache License 2.0 6 votes vote down vote up
static NodeEnvironment.NodePath getPathWithMostFreeSpace(NodeEnvironment env) throws IOException {
    final NodeEnvironment.NodePath[] paths = env.nodePaths();
    NodeEnvironment.NodePath bestPath = null;
    long maxUsableBytes = Long.MIN_VALUE;
    for (NodeEnvironment.NodePath nodePath : paths) {
        FileStore fileStore = nodePath.fileStore;
        long usableBytes = fileStore.getUsableSpace();
        assert usableBytes >= 0 : "usable bytes must be >= 0, got: " + usableBytes;

        if (bestPath == null || usableBytes > maxUsableBytes) {
            // This path has been determined to be "better" based on the usable bytes
            maxUsableBytes = usableBytes;
            bestPath = nodePath;
        }
    }
    return bestPath;
}
 
Example 3
Source File: MultiDataPathUpgrader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private ShardFileInfo[] getShardFileInfo(ShardId shard, NodeEnvironment.NodePath[] paths) throws IOException {
    final ShardFileInfo[] info = new ShardFileInfo[paths.length];
    for (int i = 0; i < info.length; i++) {
        Path path = paths[i].resolve(shard);
        final long usabelSpace = getUsabelSpace(paths[i]);
        info[i] = new ShardFileInfo(path, usabelSpace, getSpaceUsedByShard(path));
    }
    return info;
}
 
Example 4
Source File: ElasticsearchNodeCommand.java    From crate with Apache License 2.0 5 votes vote down vote up
private static NodeEnvironment.NodePath createNodePath(Path path) {
    try {
        return new NodeEnvironment.NodePath(path);
    } catch (IOException e) {
        throw new ElasticsearchException("Unable to investigate path [" + path + "]", e);
    }
}
 
Example 5
Source File: IndexShardTestCase.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * creates a new initializing shard. The shard will will be put in its proper path under the
 * current node id the shard is assigned to.
 * @param routing                shard routing to use
 * @param indexMetaData          indexMetaData for the shard, including any mapping
 * @param indexSearcherWrapper   an optional wrapper to be used during searchers
 * @param globalCheckpointSyncer callback for syncing global checkpoints
 * @param listeners              an optional set of listeners to add to the shard
 */
protected IndexShard newShard(ShardRouting routing, IndexMetaData indexMetaData,
                              @Nullable IndexSearcherWrapper indexSearcherWrapper,
                              @Nullable EngineFactory engineFactory,
                              Runnable globalCheckpointSyncer,
                              IndexingOperationListener... listeners)
    throws IOException {
    // add node id as name to settings for proper logging
    final ShardId shardId = routing.shardId();
    final NodeEnvironment.NodePath nodePath = new NodeEnvironment.NodePath(createTempDir());
    ShardPath shardPath = new ShardPath(false, nodePath.resolve(shardId), nodePath.resolve(shardId), shardId);
    return newShard(routing, shardPath, indexMetaData, null, indexSearcherWrapper, engineFactory, globalCheckpointSyncer,
        EMPTY_EVENT_LISTENER, listeners);
}
 
Example 6
Source File: MultiDataPathUpgrader.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
protected long getUsabelSpace(NodeEnvironment.NodePath path) throws IOException {
    return path.getUsableSpace();
}
 
Example 7
Source File: ElasticsearchNodeCommand.java    From crate with Apache License 2.0 4 votes vote down vote up
protected NodeEnvironment.NodePath[] toNodePaths(Path[] dataPaths) {
    return Arrays.stream(dataPaths).map(ElasticsearchNodeCommand::createNodePath).toArray(NodeEnvironment.NodePath[]::new);
}