rotatelog: add fix cleaning up partially cleaned up logs

Summary:
Our log deletion is a two step process. First it deletes the meta file,
then it deletes the log. There was a bug where if the meta file deletion
succeeded but the log deletion failed (often because Eden has the log open) then
future attempts to delete the log will fail because it fails to delete the meta
file.

Reviewed By: quark-zju

Differential Revision: D29035913

fbshipit-source-id: 33ab9a4e46b285819c4bf14031426983d2b4342f
This commit is contained in:
Durham Goode 2021-06-11 11:35:08 -07:00 committed by Facebook GitHub Bot
parent 60001b5161
commit 63884d65c1

View File

@ -571,8 +571,21 @@ impl RotateLog {
// Newly opened or flushed RotateLog will unmap files.
// New rotation would trigger remove_dir_all to try
// remove old logs again.
let res = fs::remove_file(entry.path().join(log::META_FILE))
.and_then(|_| fs::remove_dir_all(entry.path()));
match fs::remove_file(entry.path().join(log::META_FILE)) {
Ok(()) => {}
Err(e) if e.kind() == io::ErrorKind::NotFound => {
// Meta file is already deleted.
}
Err(e) => {
// Don't delete the log if we were unable to delete the
// meta file.
debug!("Error removing rotate log meta: {:?}", name);
continue;
}
}
// Delete the rest of the directory.
let res = fs::remove_dir_all(entry.path());
match res {
Ok(_) => debug!("Removed rotate log: {:?}", name),
Err(err) => {