Skip to content

Commit

Permalink
in_tail: position_file: Define path based equalities on TargetInfo
Browse files Browse the repository at this point in the history
In the previous Fluentd v1.11.x implementation uses patch based tailing
keys.
We wouldn't rewrite tailing mechanism entirely.
And also we're implicitly assuming path based equality for TargetInfo in tailing logic.
We should handle TargetInfo with path based equality instead of path and
inode based equality.

Signed-off-by: Hiroshi Hatake <hatake@calyptia.com>
  • Loading branch information
cosmo0920 committed May 25, 2021
1 parent 7c0fce6 commit 2c9b31f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/fluent/plugin/in_tail/position_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,20 @@ def read_inode
end
end

TargetInfo = Struct.new(:path, :ino)
TargetInfo = Struct.new(:path, :ino) do
def ==(other)
return false unless other.is_a?(TargetInfo)
self.path == other.path
end

def hash
self.path.hash
end

def eql?(other)
return false unless other.is_a?(TargetInfo)
self.path == other.path
end
end
end
end
25 changes: 25 additions & 0 deletions test/plugin/in_tail/test_position_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,29 @@ def build_files(file)
assert_equal 2, f.read_inode
end
end

sub_test_case "TargetInfo" do
def test_equal
t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1235)

assert_equal t1, t2
end

def test_eql?
t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 5321)

assert do
t1.eql? t2
end
end

def test_hash
t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 7321)

assert_equal t1.hash, t2.hash
end
end
end

0 comments on commit 2c9b31f

Please sign in to comment.