-
-
Notifications
You must be signed in to change notification settings - Fork 196
Add lock to log rotation #1406
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
base: dev
Are you sure you want to change the base?
Add lock to log rotation #1406
Conversation
1209c4b to
6dd4876
Compare
6744a90 to
abf1347
Compare
6e8342b to
b6204f1
Compare
|
This is done. Went ahead to just implement RotatingLog, among other things. A temporary solution (given it's only been a week), but should fix the current problem of log-baased data integrity issues and a certain class of random, logging-induced 500 server errors, while maintaining existing performance. RotatingLog inherits from Mojo::Log, and does a couple extra things on top:
Additionally, loggers are now cached in-memory per-process, which noticably helped with permission failures (probably due to file races). And if cache fails, we have the following redundancy to escape a die:
Current and beta integration tests passed, including windows/docker logging api stress tests on both concurrent logging pressure and append-time log rotation. I won't include them here. QAs bc decisions are made:
Some things I should probably note:
Dogfooding this now, lmk if there are any regressions in performance, or Windows-related. I'm curious how the unit tests go, I can only hope they don't fail. |
lib/LANraragi/Utils/Logging.pm
Outdated
| rename( $prev, $next ) or die "error: rename failed: ($prev,$next)"; | ||
| } | ||
| my $logpath = get_logdir . "/$logfile.log"; | ||
| my $cache_key = "$logfile|$pgname"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be cached per log file. This causes issues with the counter not actually counting correctly as it counts per "script" and it breaks rotation on Windows because each logger instance has an open handle to the lock file such that flock exclusive access will never work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pressure tests pass for me so no complaints here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to mojo log's context feature after a bit of TDD, hopefully it works now (possible refactor notwithstanding).
46a0eb4 to
4a615a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to actually give this a spin but I have a few codestyle suggestions to start with.
I think this is the first time we're actually doing real perl oop with extension classes and all that jazz!
|
Thanks, yeah the code is kinda messy atm, will work around eventually to get it into a presentable way! I'm aiming for the unit tests to test against the interface provided by get_logger, so that it's (somewhat) implementation-free. Luckily, logging is a feature for which unit testing works wonders towards development. There's a lingering issue (not prod-side) of RotatingLog causing my LSP (https://github.com/richterger/Perl-LanguageServer) to act up and create lock/log files in not-so-random places. Not sure what's going on there but once that's out I will undraft |
5b7502c to
e0909b0
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Implement log rotating logger with RotatingLog Co-authored-by: Difegue <[email protected]>
e0909b0 to
8669e3a
Compare
Implement log rotating logger with RotatingLog Co-authored-by: Difegue <[email protected]>
Implement log rotating logger with RotatingLog Co-authored-by: Difegue <[email protected]>
8669e3a to
b8de48c
Compare


Issue #1405 . Adds a lock to log rotation, and moves gzip target to prevent new writes from happening.