HDFS-15557. Log the reason why a storage log file can't be deleted (#2274)
This commit is contained in:
parent
7fae4133e0
commit
ae089f2db7
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue