Skip to content

Commit

Permalink
[Searchable Snapshot] Deleted the cache path on index deletion. (#6830)
Browse files Browse the repository at this point in the history
* [SearchableSnapshot] Deleted the cache path on index deletion.

Signed-off-by: Harsh Jain <harshjai@amazon.com>

* Added changelog, updated Integ Test.

Signed-off-by: Harsh Jain <harshjai@amazon.com>

* Removed changelog entry, updated validation in integ tests.

Signed-off-by: Harsh Jain <harshjai@amazon.com>

* Removed unused import statements.

Signed-off-by: Harsh Jain <harshjai@amazon.com>

---------

Signed-off-by: Harsh Jain <harshjai@amazon.com>
Co-authored-by: Harsh Jain <harshjai@amazon.com>
  • Loading branch information
harshjain2 and Harsh Jain authored Mar 28, 2023
1 parent 5f89081 commit bd9b00d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
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

0 comments on commit bd9b00d

Please sign in to comment.