Skip to content

Commit

Permalink
in_tail: Handle records in the correct order on file rotation
Browse files Browse the repository at this point in the history
This is a fix for the events-emitted-in-the-wrong-order bug reported by
fluentd#1055. It turned out that this bug was a matter of the calling
order of functions in TailWatcher.on_rotate().

In particular, when TailWatcher detects a log rotation and immediately
finds a new file, it performs the following steps:

  1) Create a new TailWatcher for the new file.
    * In this process, it reads the new file and emit its contents.
    * All of this happens before proceeding to (2).
  2) Read the old file and emit its contents.

So naturally, newer log records (written to the new log file) will be
emitted before older records in the archived log file.

This patch fixes it by enforcing flush of older log records before
performing the step (1).
  • Loading branch information
Fujimoto Seiji committed Mar 6, 2018
1 parent fa35835 commit 9578a51
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ def on_rotate(stat)
@pe.update(inode, 0)
else # file is rotated and new file found
watcher_needs_update = true
# Handle the old log file before renewing TailWatcher [fluentd#1055]
@io_handler.on_notify
end
else # file is rotated and new file not found
# Clear RotateHandler to avoid duplicated file watch in same path.
Expand Down

0 comments on commit 9578a51

Please sign in to comment.