Skip to content

Commit c80a9e2

Browse files
committed
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.
1 parent 10ef4d2 commit c80a9e2

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

server/src/main/java/org/elasticsearch/env/NodeEnvironment.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -964,16 +964,7 @@ public Set<ShardId> findAllShardIds(final Index index) throws IOException {
964964
final Set<ShardId> shardIds = new HashSet<>();
965965
final String indexUniquePathId = index.getUUID();
966966
for (final NodePath nodePath : nodePaths) {
967-
Path location = nodePath.indicesPath;
968-
if (Files.isDirectory(location)) {
969-
try (DirectoryStream<Path> indexStream = Files.newDirectoryStream(location)) {
970-
for (Path indexPath : indexStream) {
971-
if (indexUniquePathId.equals(indexPath.getFileName().toString())) {
972-
shardIds.addAll(findAllShardsForIndex(indexPath, index));
973-
}
974-
}
975-
}
976-
}
967+
shardIds.addAll(findAllShardsForIndex(nodePath.indicesPath.resolve(indexUniquePathId), index));
977968
}
978969
return shardIds;
979970
}

0 commit comments

Comments
 (0)