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

make FilePositionEntry thread-safe #1966

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 21 additions & 10 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -912,32 +912,43 @@ def initialize(file, seek)
@file = file
@seek = seek
@pos = nil
@mutex = Mutex.new
end

def update(ino, pos)
@file.pos = @seek
@file.write "%016x\t%016x" % [pos, ino]
@pos = pos
@mutex.synchronize do
@file.pos = @seek
@file.write "%016x\t%016x" % [pos, ino]
@pos = pos
end
end

def update_pos(pos)
@file.pos = @seek
@file.write "%016x" % pos
@pos = pos
@mutex.synchronize do
@file.pos = @seek
@file.write "%016x" % pos
@pos = pos
end
end

def read_inode
@file.pos = @seek + INO_OFFSET
raw = @file.read(16)
raw = nil
@mutex.synchronize do
@file.pos = @seek + INO_OFFSET
raw = @file.read(16)
end
raw ? raw.to_i(16) : 0
end

def read_pos
@pos ||= begin
pos = nil
@mutex.synchronize do
@file.pos = @seek
raw = @file.read(16)
raw ? raw.to_i(16) : 0
pos = raw ? raw.to_i(16) : 0
@pos = pos
end
pos
end
end

Expand Down