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

Support 64bit inode environment in in_tail #542

Merged
merged 1 commit into from
Jan 23, 2015
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
23 changes: 13 additions & 10 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def [](path)
@file.write path
@file.write "\t"
seek = @file.pos
@file.write "0000000000000000\t00000000\n"
@file.write "0000000000000000\t0000000000000000\n"
@last_pos = @file.pos

@map[path] = FilePositionEntry.new(@file, seek)
Expand All @@ -623,12 +623,15 @@ def self.parse(file)
# Clean up unwatched file entries
def self.compact(file)
file.pos = 0
existent_entries = file.each_line.select { |line|
existent_entries = file.each_line.map { |line|
m = /^([^\t]+)\t([0-9a-fA-F]+)\t([0-9a-fA-F]+)/.match(line)
next unless m
path = m[1]
pos = m[2].to_i(16)
pos == UNWATCHED_POSITION ? nil : line
}
ino = m[3].to_i(16)
# 32bit inode converted to 64bit at this phase
pos == UNWATCHED_POSITION ? nil : ("%s\t%016x\t%016x\n" % [path, pos, ino])
}.compact

file.pos = 0
file.truncate(0)
Expand All @@ -637,13 +640,13 @@ def self.compact(file)
end

# pos inode
# ffffffffffffffff\tffffffff\n
# ffffffffffffffff\tffffffffffffffff\n
class FilePositionEntry
POS_SIZE = 16
INO_OFFSET = 17
INO_SIZE = 8
LN_OFFSET = 25
SIZE = 26
INO_SIZE = 16
LN_OFFSET = 33
SIZE = 34

def initialize(file, seek)
@file = file
Expand All @@ -652,7 +655,7 @@ def initialize(file, seek)

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

def update_pos(pos)
Expand All @@ -662,7 +665,7 @@ def update_pos(pos)

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

Expand Down