The
Chang and Roberts algorithm
is a
ring-based coordinator election algorithm, employed in
distributed computing
A distributed system is a system whose components are located on different networked computers, which communicate and coordinate their actions by passing messages to one another from any system. Distributed computing is a field of computer sci ...
.
The algorithm
The algorithm assumes that each process has a Unique Identification (UID) and that the processes can arrange themselves in a
unidirectional ring with a communication channel going from each process to the clockwise neighbour. The two part algorithm can be described as follows:
# Initially each process in the ring is marked as ''non-participant''.
# A process that notices a lack of leader starts an election. It creates an ''election message'' containing its UID. It then sends this message clockwise to its neighbour.
# Every time a process sends or forwards an ''election message'', the process also marks itself as a participant.
# When a process receives an ''election message'' it compares the UID in the message with its own UID.
## If the UID in the election message is larger, the process unconditionally forwards the ''election message'' in a clockwise direction.
## If the UID in the election message is smaller, and the process is not yet a participant, the process replaces the UID in the message with its own UID, sends the updated ''election message'' in a clockwise direction.
## If the UID in the election message is smaller, and the process is already a ''participant'' (i.e., the process has already sent out an election message with a UID at least as large as its own UID), the process discards the election message.
## If the UID in the incoming election message is the same as the UID of the process, that process starts acting as the leader.
When a process starts acting as the leader, it begins the second stage of the algorithm.
# The leader process marks itself as ''non-participant'' and sends an ''elected message'' to its neighbour announcing its election and UID.
# When a process receives an ''elected message'', it marks itself as ''non-participant'', records the elected UID, and forwards the ''elected message'' unchanged.
# When the ''elected message'' reaches the newly elected leader, the leader discards that message, and the election is over.
Assuming there are no failures this algorithm will finish.
The algorithm works for any number of processes N, and does not require any process to know how many processes are in the ring.
Properties
The algorithm respects
safety
Safety is the state of being "safe", the condition of being protected from harm or other danger. Safety can also refer to the control of recognized hazards in order to achieve an acceptable level of risk.
Meanings
There are two slightly di ...
: a process will receive an elected message with its own UID only if his UID is greater than others', and only when all processes agree on the same UID. The algorithm also respects
liveness Properties of an execution of a computer program —particularly for concurrent and distributed systems— have long been formulated by giving ''safety properties'' ("bad things don't happen") and ''liveness properties'' ("good things do happen").
...
. "Participant" and "not participant" states are used so that when multiple processes start an election at roughly the same time, only a single winner will be announced.
When there's a single process starting the election, the algorithm requires 3N-1 sequential messages, in the worst case. Worst case is when the process starting the election is the immediate following to the one with greatest UID: it takes N-1 messages for the election message to reach it, then N messages for it to get back its own UID, then other N messages to send everyone in the ring the elected message.
This algorithm is not very fault tolerant. Fault tolerance can be increased If every process knows the whole topology, by introducing ACK messages and skipping faulty nodes on sending messages.
See also
*
Distributed computing
A distributed system is a system whose components are located on different networked computers, which communicate and coordinate their actions by passing messages to one another from any system. Distributed computing is a field of computer sci ...
*
Leader election
In distributed computing, leader election is the process of designating a single process as the organizer of some task distributed among several computers (nodes). Before the task has begun, all network nodes are either unaware which node will ser ...
*
Bully algorithm
*
HS algorithm
References
{{reflist
Distributed algorithms