diff options
author | Harald Musum <musum@verizonmedia.com> | 2022-06-14 12:00:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-14 12:00:26 +0200 |
commit | ffc98bcd55d44f96a896e38507f7f7174989b758 (patch) | |
tree | 98d60c275b127c05045ca9d4eda3df002e9c070b /logserver/src/main | |
parent | e0e3ff465fcec5bb6a7253da2cd6df82f9701066 (diff) |
Revert "hack in zstd compression"
Diffstat (limited to 'logserver/src/main')
3 files changed, 7 insertions, 115 deletions
diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java index 50df160d01f..0b44e47f183 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java @@ -86,9 +86,9 @@ public class ArchiverHandler extends AbstractLogHandler { * Creates an ArchiverHandler which puts files under * the given root directory. */ - public ArchiverHandler(String rootDir, int maxFileSize, String zip) { + public ArchiverHandler(String rootDir, int maxFileSize) { this(); - setRootDir(rootDir, zip); + setRootDir(rootDir); this.maxFileSize = maxFileSize; } @@ -189,7 +189,7 @@ public class ArchiverHandler extends AbstractLogHandler { } } - private void setRootDir(String rootDir, String zip) { + private void setRootDir(String rootDir) { // roundabout way of setting things, but this way we can // get around Java's ineptitude for file handling (relative paths in File are broken) absoluteRootDir = new File(rootDir).getAbsolutePath(); @@ -205,7 +205,7 @@ public class ArchiverHandler extends AbstractLogHandler { log.log(Level.FINE, () -> "Created root at " + absoluteRootDir); } } - filesArchived = new FilesArchived(root, zip); + filesArchived = new FilesArchived(root); } public String toString() { diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverPlugin.java b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverPlugin.java index afbd12ab05f..deb3b1adcf4 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverPlugin.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverPlugin.java @@ -20,8 +20,6 @@ public class ArchiverPlugin implements Plugin { */ private static final String DEFAULT_MAXFILESIZE = "20971520"; - private static final String DEFAULT_COMPRESSION = "zstd"; - private final Server server = Server.getInstance(); private static final Logger log = Logger.getLogger(ArchiverPlugin.class.getName()); private ArchiverHandler archiver; @@ -54,10 +52,9 @@ public class ArchiverPlugin implements Plugin { String rootDir = config.get("dir", DEFAULT_DIR); int maxFileSize = config.getInt("maxfilesize", DEFAULT_MAXFILESIZE); String threadName = config.get("thread", getPluginName()); - String zip = config.get("compression", DEFAULT_COMPRESSION); // register log handler and flusher - archiver = new ArchiverHandler(rootDir, maxFileSize, zip); + archiver = new ArchiverHandler(rootDir, maxFileSize); server.registerLogHandler(archiver, threadName); server.registerFlusher(archiver); } diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/FilesArchived.java b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/FilesArchived.java index d1e9793ffaf..54e47e15d8e 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/FilesArchived.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/FilesArchived.java @@ -8,26 +8,10 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.zip.GZIPOutputStream; -import com.yahoo.compress.ZstdOutputStream; -import com.yahoo.io.NativeIO; -import com.yahoo.log.LogFileDb; -import com.yahoo.protect.Process; -import com.yahoo.yolean.Exceptions; - -import java.io.BufferedOutputStream; -import java.io.FileDescriptor; -import java.io.FileNotFoundException; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; - /** * This class holds information about all (log) files contained @@ -44,10 +28,6 @@ public class FilesArchived { */ private final File root; - enum Compression {NONE, GZIP, ZSTD} - private final Compression compression; - private final NativeIO nativeIO = new NativeIO(); - private final Object mutex = new Object(); // known-existing files inside the archive directory @@ -80,9 +60,8 @@ public class FilesArchived { /** * Creates an instance of FilesArchive managing the given directory */ - public FilesArchived(File rootDir, String zip) { + public FilesArchived(File rootDir) { this.root = rootDir; - this.compression = ("zstd".equals(zip)) ? Compression.ZSTD : Compression.GZIP; rescan(); Thread thread = new Thread(this::run); thread.setDaemon(true); @@ -173,24 +152,7 @@ public class FilesArchived { return count > 0; } - private void compress(File oldFile) { - switch (compression) { - case ZSTD: - runCompressionZstd(nativeIO, oldFile); - break; - case GZIP: - compressGzip(oldFile); - break; - case NONE: - runCompressionNone(nativeIO, oldFile); - break; - default: - throw new IllegalArgumentException("Unknown compression " + compression); - } - } - - private void compressGzip(File oldFile) { File gzippedFile = new File(oldFile.getPath() + ".gz"); try (GZIPOutputStream compressor = new GZIPOutputStream(new FileOutputStream(gzippedFile), 0x100000); FileInputStream inputStream = new FileInputStream(oldFile)) @@ -211,32 +173,6 @@ public class FilesArchived { } } - private static void runCompressionZstd(NativeIO nativeIO, File oldFile) { - try { - Path compressedFile = Paths.get(oldFile.toString() + ".zst"); - int bufferSize = 2*1024*1024; - long mtime = oldFile.lastModified(); - try (FileOutputStream fileOut = AtomicFileOutputStream.create(compressedFile); - ZstdOutputStream out = new ZstdOutputStream(fileOut, bufferSize); - FileInputStream in = new FileInputStream(oldFile)) - { - pageFriendlyTransfer(nativeIO, out, fileOut.getFD(), in, bufferSize); - out.flush(); - } - compressedFile.toFile().setLastModified(mtime); - oldFile.delete(); - nativeIO.dropFileFromCache(compressedFile.toFile()); - } catch (IOException e) { - log.log(Level.WARNING, "Failed to compress log file with zstd: " + oldFile, e); - } finally { - nativeIO.dropFileFromCache(oldFile); - } - } - - private static void runCompressionNone(NativeIO nativeIO, File oldFile) { - nativeIO.dropFileFromCache(oldFile); - } - long sumFileSizes() { long sum = 0; for (LogFile lf : knownFiles) { @@ -274,7 +210,7 @@ public class FilesArchived { } static class LogFile { - public final File path; + public final File path; public final String prefix; public final int generation; public final boolean zsuff; @@ -309,7 +245,6 @@ public class FilesArchived { } private static boolean zSuffix(String name) { if (name.endsWith(".gz")) return true; - if (name.endsWith(".zst")) return true; // add other compression suffixes here return false; } @@ -324,44 +259,4 @@ public class FilesArchived { return "FilesArchived.LogFile{name="+path+" prefix="+prefix+" gen="+generation+" z="+zsuff+"}"; } } - - private static class AtomicFileOutputStream extends FileOutputStream { - private final Path path; - private final Path tmpPath; - private volatile boolean closed = false; - - private AtomicFileOutputStream(Path path, Path tmpPath) throws FileNotFoundException { - super(tmpPath.toFile()); - this.path = path; - this.tmpPath = tmpPath; - } - - @Override - public synchronized void close() throws IOException { - super.close(); - if (!closed) { - Files.move(tmpPath, path, StandardCopyOption.ATOMIC_MOVE); - closed = true; - } - } - - private static AtomicFileOutputStream create(Path path) throws FileNotFoundException { - return new AtomicFileOutputStream(path, path.resolveSibling("." + path.getFileName() + ".tmp")); - } - } - - private static void pageFriendlyTransfer(NativeIO nativeIO, OutputStream out, FileDescriptor outDescriptor, FileInputStream in, int bufferSize) throws IOException { - int read; - long totalBytesRead = 0; - byte[] buffer = new byte[bufferSize]; - while ((read = in.read(buffer)) >= 0) { - out.write(buffer, 0, read); - if (read > 0) { - nativeIO.dropPartialFileFromCache(in.getFD(), totalBytesRead, read, false); - nativeIO.dropPartialFileFromCache(outDescriptor, totalBytesRead, read, false); - } - totalBytesRead += read; - } - } - } |