Skip to content

Commit

Permalink
fix: handle cached file delete where path does not exist
Browse files Browse the repository at this point in the history
While testing flakiness of disk-based cache delete metrics, it was found that eviction may happen from different reasons and the path may already be deleted.
To avoid a runtime exception (that is anyway shallowed by listener execution), this PR introduces some validation before checking size.
  • Loading branch information
jeqo committed Aug 8, 2024
1 parent 0c89f1b commit aea3ec7
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,16 @@ public RemovalListener<ChunkKey, Path> removalListener() {
return (key, path, cause) -> {
try {
if (path != null) {
final long fileSize = Files.size(path);
Files.delete(path);
metrics.chunkDeleted(fileSize);
log.trace("Deleted cached file for key {} with path {} from cache directory."
+ " The reason of the deletion is {}", key, path, cause);
if (Files.exists(path)) {
final long fileSize = Files.size(path);
Files.delete(path);
metrics.chunkDeleted(fileSize);
log.trace("Deleted cached file for key {} with path {} from cache directory."
+ " The reason of the deletion is {}", key, path, cause);
} else {
log.debug("Deletion of cached file for key {} with "
+ "path {} is requested by file is not found", key, path);
}
} else {
log.warn("Path not present when trying to delete cached file for key {} from cache directory."
+ " The reason of the deletion is {}", key, cause);
Expand Down

0 comments on commit aea3ec7

Please sign in to comment.