diff options
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/logging/Spooler.java | 18 | ||||
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/logging/SpoolerTest.java | 6 |
2 files changed, 12 insertions, 12 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/logging/Spooler.java b/container-search/src/main/java/com/yahoo/search/logging/Spooler.java index 39f088c4ee4..c4fe858dffc 100644 --- a/container-search/src/main/java/com/yahoo/search/logging/Spooler.java +++ b/container-search/src/main/java/com/yahoo/search/logging/Spooler.java @@ -36,7 +36,7 @@ public class Spooler { private static final Comparator<File> ordering = new TimestampCompare(); private static final int defaultMaxEntriesPerFile = 100; // Maximum delay between first write to a file and when we should close file and move it for further processing - static final Duration maxDelayAfterFirstWrite = Duration.ofSeconds(10); + static final Duration maxDelayAfterFirstWrite = Duration.ofSeconds(5); private Path processingPath; private Path readyPath; @@ -44,9 +44,9 @@ public class Spooler { private Path successesPath; // Number of next entry to be written to the current file - AtomicInteger entryCounter = new AtomicInteger(1); - AtomicLong fileNameBase = new AtomicLong(1); - AtomicInteger fileCounter = new AtomicInteger(1); + AtomicInteger entryCounter = new AtomicInteger(0); + AtomicLong fileNameBase = new AtomicLong(0); + AtomicInteger fileCounter = new AtomicInteger(0); private final Path spoolPath; private final int maxEntriesPerFile; @@ -172,20 +172,20 @@ public class Spooler { switchFileIfNeeded(file, fileName); } - private void switchFileIfNeeded(Path file, String fileName) throws IOException { + private synchronized void switchFileIfNeeded(Path file, String fileName) throws IOException { if (file.toFile().exists() - && (entryCounter.get() > maxEntriesPerFile || firstWriteTimestamp.get().plus(maxDelayAfterFirstWrite).isBefore(clock.instant()))) { + && (entryCounter.get() >= maxEntriesPerFile || firstWriteTimestamp.get().plus(maxDelayAfterFirstWrite).isBefore(clock.instant()))) { Path target = spoolPath.resolve(readyPath).resolve(file.relativize(file)).resolve(fileName); - log.log(Level.INFO, "Finished writing file " + file + " with " + entryCounter.get() + "entries, moving it to " + target); + log.log(Level.INFO, "Finished writing file " + file + " with " + entryCounter.get() + " entries, moving it to " + target); Files.move(file, target); entryCounter.set(1); - fileNameBase.set(newFileNameBase(clock)); fileCounter.incrementAndGet(); + fileNameBase.set(newFileNameBase(clock)); firstWriteTimestamp.set(Instant.EPOCH); } } - String currentFileName() { + synchronized String currentFileName() { return fileNameBase.get() + "-" + fileCounter; } diff --git a/container-search/src/test/java/com/yahoo/search/logging/SpoolerTest.java b/container-search/src/test/java/com/yahoo/search/logging/SpoolerTest.java index e07fdaf289e..bfcf3b5e3e5 100644 --- a/container-search/src/test/java/com/yahoo/search/logging/SpoolerTest.java +++ b/container-search/src/test/java/com/yahoo/search/logging/SpoolerTest.java @@ -35,9 +35,9 @@ public class SpoolerTest { assertTrue(sendEntry(logger, "Yo entry 2")); Path readyPath = spooler.readyPath(); - Path readyFile1 = readyPath.resolve(spooler.fileNameBase.get() + "-1"); + Path readyFile1 = readyPath.resolve(spooler.fileNameBase.get() + "-0"); waitUntilFileExists(readyFile1); - Path readyFile2 = readyPath.resolve(spooler.fileNameBase.get() + "-2"); + Path readyFile2 = readyPath.resolve(spooler.fileNameBase.get() + "-1"); waitUntilFileExists(readyFile2); // Check content after being moved to ready path @@ -67,7 +67,7 @@ public class SpoolerTest { assertTrue(sendEntry(logger, "Yo entry 2")); Path readyPath = spooler.readyPath(); - Path readyFile1 = readyPath.resolve(spooler.fileNameBase.get() + "-1"); + Path readyFile1 = readyPath.resolve(spooler.fileNameBase.get() + "-0"); waitUntilFileExists(readyFile1); // Check content after being moved to ready path |