spring-cloud / spring-cloud/spring-cloud-zookeeper
Feature Request: Support for Leader Election
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 574
- Forks
- 408
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 4
Description
I noticed a pattern we use occasionally at Netflix (Leader Election) wasn't represented in this framework so I thought I'd raise an issue and outline some of the nice features that a good Spring wrapper around the Curator recipe could offer.
- Enabling the feature
- Suggest something like @EnableLeaderElection(zkPath="/some/zookeeper/path")
- Extra nice if we can make this Repeatable or or take an array argument for zkPath to multiple leadership for multiple topics
- Discovery/Eureka integration
- If an application is marked out of service or unhealthy in Eureka (or just unhealthy in terms of Spring Boot HealthIndicators possibly), the application should give up its LeaderLatch so that another instance can take over. This helps to support Red/Black pushes.
- Implementation note, when coming back into service or healthy again, we would want the application to again request leadership. This may require re-creating the Curator LeaderLatch, so that bean may not be a good fit for Singleton scope and instead may need some proxy.
- Event Integration
- A LeadershipEvent should be fired whenever status changes. This would be used to support batch processes.
- Common patterns that may be useful to expose via Config are to shut down framework components such as MessagingContainers (JMS, SQS, RabbitMQ) doing queue consumption, Spring Integration channel adapters, Spring Batch jobs, @Scheduled pollers, etc. Obviously users can subscribe to the events themselves to manage each of these frameworks, but I'm considering a config pattern as follows
spring.leadership.manage.messaging=aContainerName //some specific container bean name
spring.leadership.manage.messaging=* //all the containers
spring.leadership.manage.integration=aChannel,anotherChannel,*Channel //bean names that support start/stop
spring.leadership.manage.batch=aJob, anotherJob
- Actuator
- An actuator for leadership that can indicate if the current instance is a leader (Helpful if status code also reflects this, 2xx for yes, something else for no)
- Actuator should indicate what beans/channels are being governed by Leadership as in the above point
- Actuator should accept POST requests to force an instance to relinquish leadership (a handy testing util)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Curator LeaderLatch recipe and the Spring wrapper proposed in the issue. Break the work into enabling leadership, health and Eureka integration, leadership events, managed components, and actuator support; done would require an agreed scope and implementation covering the selected requirements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- backend, cloud, distributed-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100