Skip to content
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

Fix slow leader reelection #2156

Merged
merged 3 commits into from
Jun 11, 2024

Conversation

pjuarezd
Copy link
Member

@pjuarezd pjuarezd commented Jun 11, 2024

The leader lost was not being invoked properly, by moving leaderelection.RunOrDie out of a goroutine will ensure that a new leader is elected as soon as the existing leader pod exits, making any Operator restarts snappier.

You can confirm that the Leader lost was not being reported by Operator on SIGTERM because the log line leader lost: minio-operator-<pod id> was not printed, ergo OnStoppedLeading was not invoked.

https://github.com/minio/operator/blob/37194d9ad52edae98f2c3ec3295cf916c113ac73/pkg/controller/main-controller.go#L600C5-L603

Now, by waiting for the RunOrDie to exit we can guarantee the OnStoppedLeading is executed, the Operator logs show the log message to confirm it, and more important, a new leader is elected in matter of seconds instead of having to wait for the lease to expire.

Example output:

I0611 01:35:09.619847       1 main-controller.go:551] Received termination, signaling shutdown
I0611 01:35:09.625653       1 main-controller.go:610] leader lost: minio-operator-78b6fb57b5-n865f
I0611 01:35:09.625682       1 controller.go:185] Shutting down the MinIO Operator
I0611 01:35:09.625686       1 main-controller.go:655] Stopping the minio controller webservers
I0611 01:35:09.625817       1 main-controller.go:662] Stopping the minio controller
Stream closed EOF for minio-operator/minio-operator-78b6fb57b5-n865f (minio-operator)

Signed-off-by: pjuarezd <pjuarezd@users.noreply.github.com>
@pjuarezd pjuarezd self-assigned this Jun 11, 2024
@pjuarezd pjuarezd changed the title Fix slow reelection Fix slow leader reelection Jun 11, 2024
jiuker
jiuker previously approved these changes Jun 11, 2024
Signed-off-by: pjuarezd <pjuarezd@users.noreply.github.com>
jiuker
jiuker previously approved these changes Jun 11, 2024
shtripat
shtripat previously approved these changes Jun 11, 2024
Copy link
Contributor

@shtripat shtripat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

pkg/controller/main-controller.go Outdated Show resolved Hide resolved
Signed-off-by: pjuarezd <pjuarezd@users.noreply.github.com>
@pjuarezd pjuarezd dismissed stale reviews from shtripat and jiuker via 4ee6963 June 11, 2024 05:00
Copy link
Contributor

@shtripat shtripat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@harshavardhana harshavardhana merged commit 3da4006 into minio:master Jun 11, 2024
31 checks passed
@pjuarezd pjuarezd deleted the snappy-leader-reelection branch June 11, 2024 06:54
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.

4 participants