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.
This commit is contained in:
parent
10ef4d2140
commit
c80a9e2ec2
|
@ -964,16 +964,7 @@ public final class NodeEnvironment implements Closeable {
|
|||
final Set<ShardId> shardIds = new HashSet<>();
|
||||
final String indexUniquePathId = index.getUUID();
|
||||
for (final NodePath nodePath : nodePaths) {
|
||||
Path location = nodePath.indicesPath;
|
||||
if (Files.isDirectory(location)) {
|
||||
try (DirectoryStream<Path> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue