summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2020-08-05 13:06:30 +0200
committerGitHub <noreply@github.com>2020-08-05 13:06:30 +0200
commitb3ecf097a1a73e2a9706addbb82b06a597cece43 (patch)
tree9f0116b503b58a632ad58c83356c6657d39e25d2
parentf7423759eb99d7cfdf0aba3117dcd185a59ee9be (diff)
parent18fdf7c0c7c56c3fcff19582d1a9ae3240bcd107 (diff)
Merge pull request #13993 from vespa-engine/jonmv/flush-log-handler-output-stream-more-often
Flush output from log handler more often
-rw-r--r--container-core/src/main/java/com/yahoo/container/handler/LogReader.java44
1 files changed, 20 insertions, 24 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java
index 8e4b9aea9b8..3532dac09f5 100644
--- a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java
+++ b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java
@@ -62,34 +62,30 @@ class LogReader {
double fromSeconds = from.getEpochSecond() + from.getNano() / 1e9;
double toSeconds = to.getEpochSecond() + to.getNano() / 1e9;
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
- try {
- for (List<Path> logs : getMatchingFiles(from, to)) {
- List<LogLineIterator> logLineIterators = new ArrayList<>();
- try {
- // Logs in each sub-list contain entries covering the same time interval, so do a merge sort while reading
- for (Path log : logs)
- logLineIterators.add(new LogLineIterator(log, fromSeconds, toSeconds, hostname));
-
- Iterator<LineWithTimestamp> lines = Iterators.mergeSorted(logLineIterators,
- Comparator.comparingDouble(LineWithTimestamp::timestamp));
- while (lines.hasNext()) {
- writer.write(lines.next().line());
- writer.newLine();
- }
- }
- catch (IOException e) {
- throw new UncheckedIOException(e);
+ for (List<Path> logs : getMatchingFiles(from, to)) {
+ List<LogLineIterator> logLineIterators = new ArrayList<>();
+ try {
+ // Logs in each sub-list contain entries covering the same time interval, so do a merge sort while reading
+ for (Path log : logs)
+ logLineIterators.add(new LogLineIterator(log, fromSeconds, toSeconds, hostname));
+
+ Iterator<LineWithTimestamp> lines = Iterators.mergeSorted(logLineIterators,
+ Comparator.comparingDouble(LineWithTimestamp::timestamp));
+ while (lines.hasNext()) {
+ writer.write(lines.next().line());
+ writer.newLine();
}
- finally {
- for (LogLineIterator ll : logLineIterators) {
- try { ll.close(); } catch (IOException ignored) { }
- }
+ }
+ catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ finally {
+ for (LogLineIterator ll : logLineIterators) {
+ try { ll.close(); } catch (IOException ignored) { }
}
+ Exceptions.uncheck(writer::flush);
}
}
- finally {
- Exceptions.uncheck(writer::flush);
- }
}
private static class LogLineIterator implements Iterator<LineWithTimestamp>, AutoCloseable {