Skip to content

Commit

Permalink
Get file cache path directly
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed Feb 28, 2023
1 parent 0c607bd commit 4c11f9f
Showing 1 changed file with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.index.Index;
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.index.query.QueryBuilders;
Expand Down Expand Up @@ -528,33 +529,20 @@ public void testCacheFilesAreClosedAfterUse() throws Exception {
deleteIndicesAndEnsureGreen(client, restoredIndexName);

logger.info("--> validate all the cache files are closed");
// Iterate all the primary shards to get all the possible path that contains local cache file
for (ShardIterator shardIterator : shardIterators) {
final ShardRouting shardRouting = shardIterator.nextOrNull();
final String nodeId = shardRouting.currentNodeId();
final NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats(nodeId).addMetric(FS.metricName()).get();
for (FsInfo.Path info : nodeStats.getNodes().get(0).getFs()) {
// Build the expected root path for the index shard data
final Path shardRootPath = PathUtils.get(info.getPath())
.resolve("indices")
.resolve(index.getUUID())
.resolve(Integer.toString(shardRouting.getId()));
logger.debug("--> the root path for the shard is: {}", shardRootPath);

// Find all the files in the path
try (Stream<Path> paths = Files.walk(shardRootPath)) {
paths.filter(Files::isRegularFile).forEach(path -> {
// Testing moving the file to check the file is closed or not.
try {
Files.move(path, path, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
fail("No exception is expected. The file can't be moved, so it may not be closed.");
}
});
} catch (NoSuchFileException e) {
logger.debug("--> the root path for the restored index data doesn't exist.");
final NodeEnvironment nodeEnv = internalCluster().getInstance(NodeEnvironment.class);
Path fileCachePath = nodeEnv.fileCacheNodePath().fileCachePath;
// Find all the files in the path
try (Stream<Path> paths = Files.walk(fileCachePath)) {
paths.filter(Files::isRegularFile).forEach(path -> {
// Testing moving the file to check the file is closed or not.
try {
Files.move(path, path, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
fail("No exception is expected. The file can't be moved, so it may not be closed.");
}
}
});
} catch (NoSuchFileException e) {
logger.debug("--> the root path for the restored index data doesn't exist.");
}
}
}

0 comments on commit 4c11f9f

Please sign in to comment.