HDFS-15557. Log the reason why a storage log file can't be deleted (#2274)

This commit is contained in:
Ye Ni 2020-09-22 13:23:20 -07:00 committed by GitHub
parent 7fae4133e0
commit ae089f2db7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FilterOutputStream; import java.io.FilterOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -75,8 +76,12 @@ public class AtomicFileOutputStream extends FilterOutputStream {
boolean renamed = tmpFile.renameTo(origFile); boolean renamed = tmpFile.renameTo(origFile);
if (!renamed) { if (!renamed) {
// On windows, renameTo does not replace. // On windows, renameTo does not replace.
if (origFile.exists() && !origFile.delete()) { if (origFile.exists()) {
throw new IOException("Could not delete original file " + origFile); try {
Files.delete(origFile.toPath());
} catch (IOException e) {
throw new IOException("Could not delete original file " + origFile, e);
}
} }
try { try {
NativeIO.renameTo(tmpFile, origFile); NativeIO.renameTo(tmpFile, origFile);