Skip to content

Fix silent backup loss and test pollution in log rotation - #73

Open
Sherlock0203 wants to merge 1 commit into
LinQuickDev:logfrom
Sherlock0203:log
Open

Sherlock0203 wants to merge 1 commit into
LinQuickDev:logfrom
Sherlock0203:log

Conversation

@Sherlock0203

Copy link
Copy Markdown

No description provided.

Review fixes for the size based log rotation of apache#2696:

The shift of the backups ignored the result of every rename, so when
".1" could not be moved to ".2" (a tail tool holding the backup open on
Windows, a non-empty directory on the slot) the final rename went on
anyway and silently replaced ".1" with the current file: every rotation
dropped a generation while being accounted as a success. A shift that
fails now aborts the rotation through the back off path and leaves
every backup in place.

The shift also renamed one index per --log_rotate_max_backups, which is
only validated to be a positive int. A huge value turned every rotation
into as many rename() calls under the logging lock, stalling both
synchronous and asynchronous logging for minutes. Backups are numbered
contiguously, so the highest existing one is probed and only the
existing files are shifted.

A rotation failure was never printed on Windows, and a log file that
disappeared from under the process reset the back off: the ".\debug.log"
that Windows falls back to when the requested name cannot be opened was
then closed and reopened on every single log once over the limit. The
error is now printed on every platform through SystemErrorCodeToString()
and PathAsString(), and the disappeared file backs off too; the fresh
file reopened under the original name is smaller, which lets rotation
resume right away.

LogRotationTest pointed the global logging destination at its temp file
and never restored it: once CloseLogFile() had closed the handle, every
later suite of test_butil appended to a file under that path and lost
its stderr, leaving stray temp_file_XXXXXX files in the run directory.
TearDown() now restores the default destination and also removes the
obstacle directories that a failed test may leave behind.

New tests: a failed shift keeps the newest backup (rotation resumes once
the obstacle is gone); a huge --log_rotate_max_backups stays fast;
threads logging synchronously through rotations lose and duplicate no
log. docs/cn and docs/en now state that a backup which cannot be moved
stops the rotation instead of being overwritten.

StackTraceTest.find_symbol fails on the base commit of this branch
(efef0e6) as well: pre-existing environment issue, unrelated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant