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

Resiliency: Add logging/safety when deleting files #7628

Closed
wants to merge 2 commits into from

Conversation

rmuir
Copy link
Contributor

@rmuir rmuir commented Sep 6, 2014

File.delete() is not great as it just returns a boolean if it succeeds or fails.

Instead we can use Files.delete/Files.deleteIfExists, which throws a real exception when it fails (e.g. DirectoryNotEmptyException, Access Denied, etc)

Brings in helpers from lucene (temporarily as XIOUtils):

  • deleteFilesIfExist(File...): removes all the files, throwing the first exception with suppressions for other exceptions, but always attempts to remove all files
  • deleteFilesIgnoringExceptions(File...): removes all files, suppressing all exceptions. good for when handling other exceptions
  • rm(File...): recursive removal of all files, on any failure throws exception that contains each file name and the exception it hit.

Bans File.delete() with forbidden APIs.

This is also an opportunity to review all places in the codebase where we delete files, since they are all touched in this PR.

@rmuir
Copy link
Contributor Author

rmuir commented Sep 6, 2014

Some possible bugs i might have made to look out for:

  • Not being picky enough in tests (e.g. suppressing an exception when we should fail the test because it will just cause another confusing test failure if we can't delete the file)
  • Calling Files.delete when it should be Files.deleteIfExists in source code (could cause excessive logging)

Additionally, since we have the chance now, we may want to also add any missing logging before we try to delete any file, so when debugging you can see all file deletes (in the successful case, too)

@clintongormley clintongormley changed the title add logging/safety when deleting files Resiliency: Add logging/safety when deleting files Sep 8, 2014
}
}

private void deleteShardState(ShardId shardId) {
Copy link
Member

Choose a reason for hiding this comment

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

was this unused?

@rjernst
Copy link
Member

rjernst commented Sep 13, 2014

LGTM!

@@ -677,7 +703,11 @@ public void run() {
return;
}
logger.info("[{}] deleting dangling index", index);
FileSystemUtils.deleteRecursively(nodeEnv.indexLocations(new Index(index)));
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of all these try catch blocks can we have a utility that accepts a logger?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could, but I worry this would mostly defeat the benefit of this patch.

One main reason Files.delete is better than File.delete, because instead of returning a boolean value on failure (which is easily ignored), it forces you to think about what should happen on IOException, since its a checked exception.

If we make an "easy-to-use" utility method that "shoves it under the rug", we gain nothing.
So I think call sites should deal with this on a case-by-case basis.

Deleting files is serious business: I don't think we need a lot of abstractions and ease-of-use around it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the way, an alternative, that might make us both happy, would be to ban all other deletion methods, and add a utility method as you suggest that always logs any errors but still throws them.

This would enforce that both all file deletions are logged, and still enforce that callers have to deal with "what to do when things go wrong".

The cost would be some more complexity though.

@s1monw
Copy link
Contributor

s1monw commented Oct 7, 2014

I left one comment other than that LGTM

@s1monw
Copy link
Contributor

s1monw commented Nov 11, 2014

this has been fixed by #8366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants