diff options
3 files changed, 38 insertions, 19 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 d729b092670..95f056288d5 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 @@ -2,6 +2,7 @@ package com.yahoo.container.logging; import com.yahoo.container.core.AccessLogConfig; +import com.yahoo.io.NativeIO; import com.yahoo.log.LogFileDb; import java.io.File; @@ -263,15 +264,28 @@ public class LogFileHandler extends StreamHandler { numberOfRecords = 0; lastRotationTime = now; nextRotationTime = 0; //figure it out later (lazy evaluation) - if (compressOnRotation && (oldFileName != null)) { - triggerCompression(oldFileName); + if ((oldFileName != null)) { + if (compressOnRotation) { + triggerCompression(oldFileName); + } else { + NativeIO nativeIO = new NativeIO(); + nativeIO.dropFileFromCache(new File(oldFileName)); + } } } private void triggerCompression(String oldFileName) { try { + String zippedFileName = oldFileName + ".gz"; Runtime r = Runtime.getRuntime(); - Process p = r.exec(new String[] { "gzip", oldFileName }); + StringBuilder cmd = new StringBuilder("gzip"); + cmd.append(" < "). append(oldFileName).append(" > ").append(zippedFileName); + Process p = r.exec(cmd.toString()); + NativeIO nativeIO = new NativeIO(); + File oldFile = new File(oldFileName); + nativeIO.dropFileFromCache(oldFile); + oldFile.delete(); + nativeIO.dropFileFromCache(new File(zippedFileName)); // Detonator pattern: Think of all the fun we can have if gzip isn't what we // think it is, if it doesn't return, etc, etc } catch (IOException e) { diff --git a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java index 5adb509ac3b..18779022d99 100644 --- a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java +++ b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java @@ -34,16 +34,20 @@ public class NativeIO { public NativeIO() { if (!initialized) { - logger.warning("native IO not possible due to " + initError); - if (initError != null) { - throw new RuntimeException(initError); - } else { - throw new RuntimeException("Platform is unsúpported. Only supported on linux."); - } + logger.warning("native IO not possible due to " + getError().getMessage()); } fieldFD = getField(FileDescriptor.class, "fd"); } + public boolean valid() { return initialized; } + public Throwable getError() { + if (initError != null) { + return initError; + } else { + return new RuntimeException("Platform is unsúpported. Only supported on linux."); + } + } + public void dropFileFromCache(FileDescriptor fd) { if (initialized) { posix_fadvise(getfh(fd), 0, 0, POSIX_FADV_DONTNEED); diff --git a/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java b/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java index 91144d5999f..8616427b78b 100644 --- a/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/NativeIOTestCase.java @@ -9,6 +9,8 @@ import java.io.IOException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + public class NativeIOTestCase { @@ -20,16 +22,15 @@ public class NativeIOTestCase { output.write('t'); output.flush(); output.close(); - try { - NativeIO nativeIO = new NativeIO(); - nativeIO.dropFileFromCache(output.getFD()); - nativeIO.dropFileFromCache(testFile); - } catch (Throwable e) { - if (Platform.isLinux()) { - assertTrue(false); - } else { - assertEquals("Platform is unsúpported. Only supported on linux.", e.getMessage()); - } + NativeIO nativeIO = new NativeIO(); + if (Platform.isLinux()) { + assertTrue(nativeIO.valid()); + } else { + assertFalse(nativeIO.valid()); + assertEquals("Platform is unsúpported. Only supported on linux.", nativeIO.getError().getMessage()); } + nativeIO.dropFileFromCache(output.getFD()); + nativeIO.dropFileFromCache(testFile); + testFile.delete(); } } |