From 05e7caf493ab07f91b6f58468883518de8a30cd8 Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Wed, 12 Jun 2024 17:47:30 +0900 Subject: [PATCH] make has_skipped_line local variable Signed-off-by: Daijiro Fukuda --- lib/fluent/plugin/in_tail.rb | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 5b92d955bc..6c600847b5 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -1012,7 +1012,6 @@ def initialize(from_encoding, encoding, log, max_line_size=nil) @eol = "\n".encode(from_encoding).freeze @max_line_size = max_line_size @was_long_line = false - @has_skipped_line = false @log = log end @@ -1048,7 +1047,7 @@ def convert(s) def read_lines(lines) idx = @buffer.index(@eol) - @has_skipped_line = false + has_skipped_line = false until idx.nil? # Using freeze and slice is faster than slice! @@ -1066,7 +1065,7 @@ def read_lines(lines) @log.warn "received line length is longer than #{@max_line_size}" @log.debug("skipped line: ") { convert(rbuf).chomp } @was_long_line = false - @has_skipped_line = true + has_skipped_line = true next end @@ -1080,17 +1079,14 @@ def read_lines(lines) if is_long_line @buffer.clear @was_long_line = true - @has_skipped_line = true end + + return has_skipped_line end def bytesize @buffer.bytesize end - - def has_skipped_line? - @has_skipped_line - end end class IOHandler @@ -1203,8 +1199,7 @@ def handle_notify @fifo << data n_lines_before_read = @lines.size - @fifo.read_lines(@lines) - has_skipped_line = @fifo.has_skipped_line? + has_skipped_line = @fifo.read_lines(@lines) || has_skipped_line group_watcher&.update_lines_read(@path, @lines.size - n_lines_before_read) group_watcher_limit = group_watcher&.limit_lines_reached?(@path) @@ -1227,11 +1222,9 @@ def handle_notify end end - if @lines.empty? && has_skipped_line - @watcher.pe.update_pos(io.pos - @fifo.bytesize) - end - - unless @lines.empty? + if @lines.empty? + @watcher.pe.update_pos(io.pos - @fifo.bytesize) if has_skipped_line + else if @receive_lines.call(@lines, @watcher) @watcher.pe.update_pos(io.pos - @fifo.bytesize) @lines.clear