Skip to content

Commit

Permalink
Merge pull request #4228 from daipom/in_tail-add-debug-log-for-pos-fi…
Browse files Browse the repository at this point in the history
…le-compaction

in_tail: Add debug log for pos file compaction
  • Loading branch information
ashie authored Jul 7, 2023
2 parents 09617b4 + 2a5b2d1 commit aaa40f7
Showing 1 changed file with 15 additions and 11 deletions.
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

0 comments on commit aaa40f7

Please sign in to comment.