lib/fluent/plugin/in_tail.rb in fluentd-0.12.3 vs lib/fluent/plugin/in_tail.rb in fluentd-0.12.4
- old
+ new
@@ -595,11 +595,11 @@
@file.pos = @last_pos
@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)
end
@@ -621,49 +621,52 @@
end
# 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)
file.write(existent_entries.join)
end
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
@seek = seek
end
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)
@file.pos = @seek
@file.write "%016x" % pos
end
def read_inode
@file.pos = @seek + INO_OFFSET
- raw = @file.read(8)
+ raw = @file.read(16)
raw ? raw.to_i(16) : 0
end
def read_pos
@file.pos = @seek