Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Searchable Snapshot] Deleted the cache path on index deletion. #6830

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@
import org.opensearch.monitor.fs.FsInfo;
import org.opensearch.repositories.fs.FsRepository;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -559,22 +555,15 @@ public void testCacheFilesAreClosedAfterUse() throws Exception {
// The local cache files should be closed by deleting the restored index
deleteIndicesAndEnsureGreen(client, restoredIndexName);

logger.info("--> validate all the cache files are closed");
logger.info("--> validate cache file path is deleted");
// Get path of cache files
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 path for the cache files doesn't exist");

if (Files.exists(fileCachePath)) {
fail("Cache file path isn't deleted.");
} else {
logger.info("--> validated that the cache file path doesn't exist");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.opensearch.common.io.FileSystemUtils;
import org.opensearch.common.settings.Settings;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.index.IndexModule;
Expand Down Expand Up @@ -60,6 +61,7 @@ public void beforeIndexShardDeleted(ShardId shardId, Settings settings) {
fileCache.remove(subPath.toRealPath());
}
}
FileSystemUtils.deleteSubDirectories(shardPath.getRootDataPath());
}
} catch (IOException ioe) {
log.error(() -> new ParameterizedMessage("Error removing items from cache during shard deletion {})", shardId), ioe);
Expand Down