Refactor whole_file overwrite detection and chunked output in LogFileReader#2577
Open
beartyson-tech wants to merge 3 commits into
Open
Refactor whole_file overwrite detection and chunked output in LogFileReader#2577beartyson-tech wants to merge 3 commits into
beartyson-tech wants to merge 3 commits into
Conversation
- Improved detection of file modifications in WHOLE_FILE overwrite mode by combining mtime, size, and signature checks. - Added new methods for chunked draining of whole files, ensuring chunks end on line boundaries or character boundaries for better readability. - Updated unit tests to validate chunk alignment for both line and character boundaries. - Adjusted documentation for input configurations to include new parameters related to whole file processing. Co-authored-by: Cursor <cursoragent@cursor.com>
f3b2e70 to
6073bb7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
In whole_file overwrite mode the entire file is one log record, but relying solely on second-precision mtime
missed same-second in-place rewrites; oversized files were also split on fixed byte counts, breaking lines and
multibyte characters and making downstream output unreadable.
Scope of Changes
CheckFileSignatureAndOffsetnow combines nanosecond mtime, file size, and thefirst-1KB signature (OR), reads the signature only when mtime/size are unchanged, and adds the
mLastMTimeNs/mLastWholeFileSizebaselines.DrainWholeFileChunk/GetWholeFileChunkSize/CountWholeFileChunks, sizingchunks line-first with a character-aligned fallback and converting GBK to UTF8 per chunk so each chunk is
independently readable.
MaxWholeFileByteswarning ingetNextReadSizeis throttled bylogtail_alarm_intervalto avoid flooding the log on every read (mWholeFileOversizeWarnTime).TestChunkLineAlignment/TestChunkCharAlignmentand fixes the caseSetUpto setOVERWRITE; docs add whole_file,
FileWriteMode,MaxWholeFileBytes, and fix theFlushTimeoutSecsdefault to 60.reader_whole_file_overwritecase switches to the@hostenvironment and theslssubscriber, seeding alpha and overwriting it in place with beta viarun command on loongcollector,validating single-record whole-file collection and a full re-read triggered by the overwrite.
test/e2e/e2e_host_test.go(TestE2EOnHost) to drive@host-tagged cases, fillingthe gap where the open-source test/e2e only had a
@docker-composerunner (with a minorgo.modindirectdependency adjustment).