From c80a9e2ec2e2aca33270f8b070f2cbe1347c6493 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 9 Jul 2020 11:43:12 +0100 Subject: [PATCH] Skip unnecessary directory iteration (#59007) Today `NodeEnvironment#findAllShardIds` enumerates the index directories in each data path in order to find one with a specific name. Since we already know the name of the folder we seek we can construct the path directly and avoid this directory listing. This commit does that. --- .../java/org/elasticsearch/env/NodeEnvironment.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 125041f02b5..6f084684b0d 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -964,16 +964,7 @@ public final class NodeEnvironment implements Closeable { final Set shardIds = new HashSet<>(); final String indexUniquePathId = index.getUUID(); for (final NodePath nodePath : nodePaths) { - Path location = nodePath.indicesPath; - if (Files.isDirectory(location)) { - try (DirectoryStream indexStream = Files.newDirectoryStream(location)) { - for (Path indexPath : indexStream) { - if (indexUniquePathId.equals(indexPath.getFileName().toString())) { - shardIds.addAll(findAllShardsForIndex(indexPath, index)); - } - } - } - } + shardIds.addAll(findAllShardsForIndex(nodePath.indicesPath.resolve(indexUniquePathId), index)); } return shardIds; }