-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
mysqlctl: Improve handling of the lock file #15404
mysqlctl: Improve handling of the lock file #15404
Conversation
This handles the case where mysqlctld might get assigned the same pid and improves the logging for when this case happens. Signed-off-by: Dirkjan Bussink <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #15404 +/- ##
=======================================
Coverage 65.65% 65.66%
=======================================
Files 1562 1562
Lines 193940 193948 +8
=======================================
+ Hits 127328 127352 +24
+ Misses 66612 66596 -16 ☔ View full report in Codecov by Sentry. |
@@ -460,6 +460,10 @@ func cleanupLockfile(socket string, ts string) error { | |||
log.Errorf("%v: error parsing pid from lock file: %v", ts, err) | |||
return err | |||
} | |||
if os.Getpid() == p { | |||
log.Infof("%v: lock file at %s is ours, removing it", ts, lockPath) |
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'd take the opportunity to rename ts
as ts == *topo.Server
in the code base. :-)
No idea why that was chosen for:
ts := fmt.Sprintf("Mysqld.Start(%v)", time.Now().Unix())
time start, I guess? Up to you if you want to change it.
@@ -460,6 +460,10 @@ func cleanupLockfile(socket string, ts string) error { | |||
log.Errorf("%v: error parsing pid from lock file: %v", ts, err) | |||
return err | |||
} | |||
if os.Getpid() == p { | |||
log.Infof("%v: lock file at %s is ours, removing it", ts, lockPath) | |||
return os.Remove(lockPath) |
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 really want to do this? I'm curious how this happens, where we have the same PID we had before? Or am I missing something. That being said, I suppose it's fine since eventually the PID will get reused and could be reused by another mysqld process. In that case though I'm also not sure what "ours" really means in that context.
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.
@mattlord It can happen inside containers. Each container is unique and gets new PIDs so it's possible there to have PID reusage much more often.
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.
Yes, when using persistent storage for the lock file that lives across containers. Makes sense. Thanks!
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!
This handles the case where mysqlctld might get assigned the same pid and improves the logging for when this case happens.
Related Issue(s)
Part of addressing #14552
Checklist