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:
David Turner 2020-07-09 11:43:12 +01:00
parent 10ef4d2140
commit c80a9e2ec2
1 changed files with 1 additions and 10 deletions

View File

@ -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;
}