Skip to content

Commit

Permalink
delete the directory too, not just the files in it
Browse files Browse the repository at this point in the history
  • Loading branch information
autata committed Nov 22, 2024
1 parent 52083ac commit bfb3406
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions astra/src/main/java/com/slack/astra/chunk/ReadOnlyChunkImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ private void handleChunkAssignment(CacheSlotMetadata cacheSlotMetadata) {
// also clean up downloaded files if the chunk could not be assigned as we're marking the as
// FREE / available
if (Files.isDirectory(dataDirectory)) {
LOG.info("Cleaning up directory after failed chunk assignment{}", dataDirectory);
cleanDirectory();
LOG.info("Deleting directory after failed chunk assignment{}", dataDirectory);
deleteDirectory();
}
assignmentTimer.stop(chunkAssignmentTimerFailure);
} finally {
Expand Down Expand Up @@ -526,6 +526,16 @@ private void cleanDirectory() {
}
}

private void deleteDirectory() {
if (dataDirectory != null) {
try {
FileUtils.deleteDirectory(dataDirectory.toFile());
} catch (Exception e) {
LOG.error("Error deleting directory {}", dataDirectory.toString(), e);
}
}
}

@VisibleForTesting
public Metadata.CacheSlotMetadata.CacheSlotState getChunkMetadataState() {
return cacheSlotMetadataStore.getSync(searchContext.hostname, slotId).cacheSlotState;
Expand Down

0 comments on commit bfb3406

Please sign in to comment.