aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-09-26 21:03:18 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2018-09-26 21:03:18 +0200
commit7d9f51e9a229ec67b68a37d7091cc69f1ed5add2 (patch)
treea626be2d6d97697fc303c867ba00c1b003d7ea3e
parentef525252f8eadd7593aea702a984b086ff22d3bd (diff)
Just accept that the file being dropped does not exist. Also sync the file before the dropping it.
-rw-r--r--vespajlib/src/main/java/com/yahoo/io/NativeIO.java8
-rw-r--r--vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java1
2 files changed, 8 insertions, 1 deletions
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"));
}
}