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

in_tail: Add debug log for pos file compaction #4228

Merged
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
26 changes: 15 additions & 11 deletions lib/fluent/plugin/in_tail/position_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def try_compact
end

entries = fetch_compacted_entries
@logger&.debug "Compacted entries: ", entries.keys

@file_mutex.synchronize do
if last_modified == @file.mtime && size == @file.size
Expand All @@ -119,15 +120,23 @@ def try_compact

def compact(existing_targets = nil)
@file_mutex.synchronize do
entries = fetch_compacted_entries(existing_targets).values.map(&:to_entry_fmt)
entries = fetch_compacted_entries
@logger&.debug "Compacted entries: ", entries.keys

if existing_targets
entries = remove_deleted_files_entries(entries, existing_targets)
@logger&.debug "Remove missing entries.",
existing_targets: existing_targets.keys,
entries_after_removing: entries.keys
end

@file.pos = 0
@file.truncate(0)
@file.write(entries.join)
@file.write(entries.values.map(&:to_entry_fmt).join)
end
end

def fetch_compacted_entries(existing_targets = nil)
def fetch_compacted_entries
entries = {}

@file.pos = 0
Expand Down Expand Up @@ -156,18 +165,13 @@ def fetch_compacted_entries(existing_targets = nil)
end
end

entries = remove_deleted_files_entries(entries, existing_targets)
entries
end

def remove_deleted_files_entries(existent_entries, existing_targets)
if existing_targets
existent_entries.select { |path_or_ino|
existing_targets.key?(path_or_ino)
}
else
existent_entries
end
existent_entries.select { |path_or_ino|
existing_targets.key?(path_or_ino)
}
end
end

Expand Down