-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
A way to enforce leadership loss/switch. #4477
Comments
With #4318 you can do:
|
@shawkins - Thank you so much for the response. We tried this out, the idea was to switch the leadership periodically from one instance to another by making the leader instance lose the leadership. We observed the leadership status being passed on to other instances a couple of times after this, This is why I am looking for an appropriate way to do this using an API method. |
Yes it will only release if the current instance is the leader. That means you can get the behavior you want by using the onStartLeading callback to create a timer task or similar to cancel the current leader after whatever interval you see fit. Something like:
Obviously that's not very elegant, but I don't see that the go client implementation is designed for this either. Enhancements that would make this easier:
It may also be good to clarify / enforce that a LeaderElector instance should only have 1 election running at a time - simultaneous calls to run / start should be disallowed. @manusa any thoughts? |
This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions! |
ping! |
…d mock compatibility
…d mock compatibility
Is your enhancement related to a problem? Please describe
In the scope of leader election in a distributed environment. One of the best practices is that a given instance should not be the leader forever. After a certain interval of time, the leader instance should give up leadership so that the election happens again and a new leader is chosen.
Using fabric8 kubernetes client to implement leader election among replicas of a pod, we are able to observe a leader is elected. And leadership is transferred to a different pod once the leader pod is dead. The only missing part of the puzzle is, the fabric8 kubernetes client not having a way to enforce the leader pod to lose its leadership status.
Such an expected implementation can be used by the client to enforce a leadership switch periodically using appropriate methods provided by the JDK.
Describe the solution you'd like
The solution can be as simple as this method being marked as public.
Describe alternatives you've considered
To enforce leadership loss we can:
call
ExecutorService.shutdownNow()
on the ExecutorService running leader election. (Or basically, try to interrupt/kill the leader election thread)update the lease lock with a LeaderElectionRecord having an empty holder identity.
Additional context
After taking a look at the example code for leader election shared in this repo, I think the fabric8 leader election interface was never intended to be used for a use case like this. (Leader Election among replicas)
The text was updated successfully, but these errors were encountered: