You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Yi Chen <yi...@symphonycommerce.com> on 2016/07/08 14:37:02 UTC

Can I use a single-partition topic for leader election?

Hello,

I am developing a service so that all clustered nodes form a consumer
group. I also need to run some logic on only one of the node. Can I use a
special single-partition topic for leader election? That is, in my node I
can use ConsumerRebalanceListener to make sure that if the "leader"
TopicPartition is being assigned to this node, then it is now the leader,
otherwise, it is not a leader.

Thanks,
Yi

Re: Can I use a single-partition topic for leader election?

Posted by Ewen Cheslack-Postava <ew...@confluent.io>.
If you have a consumer group, you can use whichever member is assigned
partition 0 of a topic as the leader. Just note that this does *not* handle
zombie leader scenarios, e.g. if a member of the group has a very long GC
and then wakes up later thinking it is still the leader, it will execute
any leader-only actions normally. The consumer group handles this by having
the broker track generation IDs and rejecting requests for older
generations, but if you're using this for some external functionality (e.g.
writing to some external system), you won't have that same protection.

-Ewen

On Fri, Jul 8, 2016 at 7:37 AM, Yi Chen <yi...@symphonycommerce.com> wrote:

> Hello,
>
> I am developing a service so that all clustered nodes form a consumer
> group. I also need to run some logic on only one of the node. Can I use a
> special single-partition topic for leader election? That is, in my node I
> can use ConsumerRebalanceListener to make sure that if the "leader"
> TopicPartition is being assigned to this node, then it is now the leader,
> otherwise, it is not a leader.
>
> Thanks,
> Yi
>



-- 
Thanks,
Ewen