Search code examples
aeron

How to dynamically designate and Aeron Cluster leader node?


I would like to direct any node in Aeron Cluster to become leader, no elections. The previous leader automatically becomes a follower, never attempting to assume leadership (unless directed externally).

I looked at Cluster/Role, ClusterTool and AeronCluster APIs and nothing seemed helpful. I also checked AppointedLeaderTest and it boils down to initially specify leader with ConsesusModule.Context.appointedLeaderId, but no way to change it afterwards dynamically?

How to do this?


Solution

  • It is not possible to run an Aeron cluster as you are suggesting. (Aeron 1.27.0)

    Aeron cluster is based on the RAFT consensus algorithm, it defines the election protocol and that dictates that the node which has the most advanced log at that point in time will become leader.

    Assigning the appointedLeaderId prevents nodes not specified from proposing themselves as candidates in an election.

    You may be able to achieve some of what you want by using dynamic membership.

    • You could start the cluster of 1. The node you want to be leader and wait for it to become leader.
    • Add nodes dynamically one-by-one until you have a cluster of the desired size.

    Or given a static cluster, a slightly more brute force approach would be to:

    1. Start a three node cluster.
    2. If you desired leader becomes leader then GO TO END.
    3. Restart the leader. GO TO 2.

    Note: the complexity/computational expense of either of these solutions would likely outweigh any benefit of being able to appoint a node as leader.