aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-09-26 21:42:08 +0200
committerGitHub <noreply@github.com>2018-09-26 21:42:08 +0200
commit93e547e793ff05135689c8175daf464a8be1dcdd (patch)
tree1dec06cb12b52059f6758dec5e225b948367638d
parenta1637a132dac7a934bf82a0932c01515de5d8a2f (diff)
parent02e4ae8fce3ec254f57c7ff865a60cfb31930f05 (diff)
Merge pull request #7118 from vespa-engine/balder/handle-that-files-does-not-exist
Balder/handle that files does not exist
-rw-r--r--container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java17
-rw-r--r--vespajlib/src/main/java/com/yahoo/io/NativeIO.java8
-rw-r--r--vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java1
3 files changed, 18 insertions, 8 deletions
diff --git a/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java b/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java
index 9963429bf97..805fa52c105 100644
--- a/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java
+++ b/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java
@@ -265,24 +265,27 @@ public class LogFileHandler extends StreamHandler {
lastRotationTime = now;
nextRotationTime = 0; //figure it out later (lazy evaluation)
if ((oldFileName != null)) {
- if (compressOnRotation) {
- triggerCompression(oldFileName);
- } else {
- NativeIO nativeIO = new NativeIO();
- nativeIO.dropFileFromCache(new File(oldFileName));
+ File oldFile = new File(oldFileName);
+ if (oldFile.exists()) {
+ if (compressOnRotation) {
+ triggerCompression(oldFile);
+ } else {
+ NativeIO nativeIO = new NativeIO();
+ nativeIO.dropFileFromCache(oldFile);
+ }
}
}
}
- private void triggerCompression(String oldFileName) {
+ private void triggerCompression(File oldFile) {
try {
+ String oldFileName = oldFile.getPath();
String gzippedFileName = oldFileName + ".gz";
Runtime r = Runtime.getRuntime();
StringBuilder cmd = new StringBuilder("gzip");
cmd.append(" < "). append(oldFileName).append(" > ").append(gzippedFileName);
Process p = r.exec(cmd.toString());
NativeIO nativeIO = new NativeIO();
- File oldFile = new File(oldFileName);
nativeIO.dropFileFromCache(oldFile); // Drop from cache in case somebody else has a reference to it preventing from dying quickly.
oldFile.delete();
nativeIO.dropFileFromCache(new File(gzippedFileName));
diff --git a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
index 99c70b405b1..f08e01070d7 100644
--- a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
+++ b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
@@ -5,6 +5,7 @@ import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.SyncFailedException;
import java.lang.reflect.Field;
import java.util.logging.Logger;
@@ -56,6 +57,11 @@ public class NativeIO {
* @param fd The file descriptor to drop from buffer cache.
*/
public void dropFileFromCache(FileDescriptor fd) {
+ try {
+ fd.sync();
+ } catch (SyncFailedException e) {
+ logger.warning("Sync failed while dropping cache: " + e.getMessage());
+ }
if (initialized) {
posix_fadvise(getNativeFD(fd), 0, 0, POSIX_FADV_DONTNEED);
}
@@ -69,7 +75,7 @@ public class NativeIO {
try {
dropFileFromCache(new FileInputStream(file).getFD());
} catch (FileNotFoundException e) {
- throw new RuntimeException(e);
+ logger.warning("No point in dropping a non-existing file from the buffer cache: " + e.getMessage());
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java b/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java
index ecd38056a19..6018a195b6a 100644
--- a/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java
@@ -30,5 +30,6 @@ public class NativeIOTestCase {
nativeIO.dropFileFromCache(output.getFD());
nativeIO.dropFileFromCache(testFile);
testFile.delete();
+ nativeIO.dropFileFromCache(new File("file.that.does.not.exist"));
}
}