-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
session: add session var to update global logger max days #27595
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Please follow PR Title Format:
Or if the count of mainly changed packages are more than 3, use
After you have format title, you can leave a comment |
/assign @morgo |
/run-check_title |
sessionctx/variable/sysvar.go
Outdated
|
||
return nil | ||
}, GetSession: func(s *SessionVars) (string, error) { | ||
return strconv.FormatInt(int64(atomic.LoadInt32(&GeneralLogMaxAge)), 10), nil |
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.
I think this will be out of sync until the first ReplaceLogger
event happens right? So if they never replace the logger, it will not be safe to read TiDBGeneralLogMaxAge
to see what the value defined in config is.
A workaround is, you can set the sysvar in tidb-server/main.go
when the server starts up. We have some examples for global sysvars, but because you have a getter func (and it's session scope) you can just atomic.StoreInt32(&GeneralLogMaxAge, maxAge)
?
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.
i found setGlobalVars
in tidb-server/main.go
initialize variables during startup, from what i can tell, we can actually change this to be global variable here and i think it make more sense.
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.
Most of these are setting ScopeNone
(read-only) sysvars. If you make this ScopeGlobal
it will be cluster wide.
The behavior of ScopeGlobal
+ config file is weird, because any new joining server would overwrite the other server's log configuration. Usually with logs (or things refering to the local filesystem) we have kept them instance scoped. This also supports the use case that a user might want to have one server log everything.
I hope in future we clean this up though, so there is a native concept of instance scope.
@db-will Please run |
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.
LGTM
/assign @SabaPing |
@db-will: GitHub didn't allow me to assign the following users: SabaPing. Note that only pingcap members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This variable is named 'tidb_general_log_max_days' but it is not limited to the 'general log' actually. Is it a good idea to name it 'tidb_log_file_max_days'? |
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 are max-size
and max-backups
variables in log config. Should we add them to session var to make the behavior consistent?
sessionctx/variable/tidb_vars.go
Outdated
@@ -121,6 +121,9 @@ const ( | |||
// tidb_general_log is used to log every query in the server in info level. | |||
TiDBGeneralLog = "tidb_general_log" | |||
|
|||
// tidb_general_log is used to log every query in the server in info level. | |||
TiDBGeneralLogMaxDays = "tidb_general_log_max_days" |
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.
As @bb7133 said, should we rename it to tidb_log_file_max_days
?
@@ -143,6 +144,24 @@ func initGRPCLogger(cfg *LogConfig) (*zap.Logger, *log.ZapProperties, error) { | |||
return l, prop, nil | |||
} | |||
|
|||
// ReplaceLogger replace global logger instance with given log config. | |||
func ReplaceLogger(cfg *LogConfig) error { |
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.
Do we need to replace slow query logger to enable slow log runtime modification either?
/assign @bb7133 |
/assign @yudongusa Looking for one another approval to meet the merge criterial |
Unfortunately libfaketime doesn't work with Go, that would have made testing easier and/or more realistic. Interesting enough the golang playground etc are using a fake time (example). However I think the testing here is sufficient for this PR. In MySQL Another option is to leave some of this work to the OS, like |
please format the code and then the pr can be merge |
@xiongjiwei May i merge this PR? |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 125887b
|
@db-will: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: close #27520
Problem Summary: Currently, it is required to restart instance to change max-days of log files(log.file.max-days in config file). We want to enable user to change such config dynamically.
What is changed and how it works?
What's Changed:
How it Works:
Check List
Tests
We setup and run an tidb cluster with a given max-days=30 and max-size=30 in config
Enable general log
Run sysbench prepare to init table and add data, so that we can generate some general logs
We can fake some last 5 days log files by creating similar log files with different timestamp and clean up the generate logs:
Let set max days to some values and run sysbench to generate new logs, and check if logs are purged as expected(this is due to purge only happen when new logs are generated):
change max days to larger value, and we expect it won't wrongly purge files:
Set to max days = 1
Side effects
Documentation
Release note