Class: Fluent::Plugin::TailInput::PositionFile
- Inherits:
-
Object
- Object
- Fluent::Plugin::TailInput::PositionFile
- Defined in:
- lib/fluent/plugin/in_tail.rb
Constant Summary collapse
- UNWATCHED_POSITION =
0xffffffffffffffff
Class Method Summary collapse
-
.compact(file) ⇒ Object
Clean up unwatched file entries.
- .parse(file) ⇒ Object
Instance Method Summary collapse
- #[](path) ⇒ Object
-
#initialize(file, map, last_pos) ⇒ PositionFile
constructor
A new instance of PositionFile.
Constructor Details
#initialize(file, map, last_pos) ⇒ PositionFile
Returns a new instance of PositionFile.
687 688 689 690 691 |
# File 'lib/fluent/plugin/in_tail.rb', line 687 def initialize(file, map, last_pos) @file = file @map = map @last_pos = last_pos end |
Class Method Details
.compact(file) ⇒ Object
Clean up unwatched file entries
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/fluent/plugin/in_tail.rb', line 724 def self.compact(file) file.pos = 0 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) 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 |
.parse(file) ⇒ Object
708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'lib/fluent/plugin/in_tail.rb', line 708 def self.parse(file) compact(file) map = {} file.pos = 0 file.each_line {|line| m = /^([^\t]+)\t([0-9a-fA-F]+)\t([0-9a-fA-F]+)/.match(line) next unless m path = m[1] seek = file.pos - line.bytesize + path.bytesize + 1 map[path] = FilePositionEntry.new(file, seek) } new(file, map, file.pos) end |
Instance Method Details
#[](path) ⇒ Object
693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
# File 'lib/fluent/plugin/in_tail.rb', line 693 def [](path) if m = @map[path] return m end @file.pos = @last_pos @file.write path @file.write "\t" seek = @file.pos @file.write "0000000000000000\t0000000000000000\n" @last_pos = @file.pos @map[path] = FilePositionEntry.new(@file, seek) end |