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

If the chunk fails and we keep the 'slot' as free, make sure to remove the files from disk #17

Open
wants to merge 4 commits into
base: airbnb-main
Choose a base branch
from
Open
Changes from 3 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
16 changes: 16 additions & 0 deletions astra/src/main/java/com/slack/astra/chunk/ReadOnlyChunkImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ private void handleChunkAssignment(CacheSlotMetadata cacheSlotMetadata) {
// disregarding any errors
setChunkMetadataState(cacheSlotMetadata, Metadata.CacheSlotMetadata.CacheSlotState.FREE);
LOG.error("Error handling chunk assignment", e);
// also clean up downloaded files if the chunk could not be assigned as we're marking the as
// FREE / available
if (Files.isDirectory(dataDirectory)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a cleanDirectory method in this class that can do this. Can we call that method here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can you please add a unit test for this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanDirectory only deletes the files in the directory. i used that one first, but it doesn't have the desired result

LOG.info("Deleting directory after failed chunk assignment{}", dataDirectory);
deleteDirectory();
}
assignmentTimer.stop(chunkAssignmentTimerFailure);
} finally {
chunkAssignmentLock.unlock();
Expand Down Expand Up @@ -520,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
Loading