Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clenanup in tail #2830

Merged
merged 4 commits into from
Feb 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 32 additions & 36 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,14 @@ def initialize(path, rotate_wait, pe, log, read_from_head, enable_watch_timer, e
@receive_lines = receive_lines
@update_watcher = update_watcher

@stat_trigger = @enable_stat_watcher ? StatWatcher.new(self, &method(:on_notify)) : nil
@stat_trigger = @enable_stat_watcher ? StatWatcher.new(path, log, &method(:on_notify)) : nil
@timer_trigger = @enable_watch_timer ? TimerTrigger.new(1, log, &method(:on_notify)) : nil

@rotate_handler = RotateHandler.new(self, &method(:on_rotate))
@rotate_handler = RotateHandler.new(log, &method(:on_rotate))
@io_handler = nil
@log = log

@line_buffer = nil
@line_buffer_timer_flusher = line_buffer_timer_flusher
@from_encoding = from_encoding
@encoding = encoding
Expand Down Expand Up @@ -690,18 +691,18 @@ def on_timer
end

class StatWatcher < Coolio::StatWatcher
def initialize(watcher, &callback)
@watcher = watcher
def initialize(path, log, &callback)
@callback = callback
super(watcher.path)
@log = log
super(path)
end

def on_change(prev, cur)
@callback.call
rescue
# TODO log?
@watcher.log.error $!.to_s
@watcher.log.error_backtrace
@log.error $!.to_s
@log.error_backtrace
end
end

Expand Down Expand Up @@ -834,26 +835,24 @@ def open
end

def with_io
begin
if @watcher.open_on_every_update
io = open
begin
yield io
ensure
io.close unless io.nil?
end
else
@io ||= open
yield @io
if @watcher.open_on_every_update
io = open
begin
yield io
ensure
io.close unless io.nil?
end
rescue WatcherSetupError => e
close
raise e
rescue
@watcher.log.error $!.to_s
@watcher.log.error_backtrace
close
else
@io ||= open
yield @io
end
rescue WatcherSetupError => e
close
raise e
rescue
@watcher.log.error $!.to_s
@watcher.log.error_backtrace
close
end
end

Expand All @@ -876,8 +875,8 @@ def opened?
end

class RotateHandler
def initialize(watcher, &on_rotate)
@watcher = watcher
def initialize(log, &on_rotate)
@log = log
@inode = nil
@fsize = -1 # first
@on_rotate = on_rotate
Expand All @@ -892,17 +891,14 @@ def on_notify(stat)
fsize = stat.size
end

begin
if @inode != inode || fsize < @fsize
@on_rotate.call(stat)
end
@inode = inode
@fsize = fsize
if @inode != inode || fsize < @fsize
@on_rotate.call(stat)
end

@inode = inode
@fsize = fsize
rescue
@watcher.log.error $!.to_s
@watcher.log.error_backtrace
@log.error $!.to_s
@log.error_backtrace
end
end

Expand Down