• Aucun résultat trouvé

Two Particular Cases

Leader Election Algorithms

4.5 Two Particular Cases

• If the messageELECTION(1,idi)is such that id=maxidi, then it has made a full turn on the ring, and consequently maxidi is the greatest identity. In this case, pi sends the messageELECTED(maxidi,idi)(line6), which is propagated on the ring to inform all the processes (lines16–17).

• If messageELECTION(1,id)is such that id=maxidi,pi copies id in proxy_fori, and forwards the messageELECTION(2,id)on its outgoing channel.

When a processpi receives a messageELECTION(2,id), it forwards it (as pre-viously) on its outgoing channel if it is no longer a competitor (lines9–10). If it is a competitor,pi checks if proxy_fori>max(id,maxidi), i.e., if the identity of the process it has to compete for (namely, proxy_fori) is greater than both maxidi

(the identity of the process on behalf of whichpi was previously competing) and the identity id it has just received (line11). If it is the case, pi updates maxidi

and starts a new round (line12). Otherwise, proxy_fori is not the highest identity.

Consequently, aspi should compete for an identity that cannot be elected, it stops competing (line13).

4.4.3 Discussion: Message Complexity and FIFO Channels

Message Complexity During each round, except the last one, each process sends two messages: a messageELECTION(1,)and a messageELECTION(2,). More-over, there are onlyELECTION(1,)messages during the last round. As we have seen, there are at most log2n+1 rounds. It follows that the number of messages

ELECTION(1,)andELECTION(2,)sent by the algorithm is at most 2nlogn+n.

Type of Channels Each process receives alternately a messageELECTION(1,) followed by a messageELECTION(2,). As the channels are FIFO, it follows that the numbers 1 and 2 used to tag the messages are useless: A messageELECTION() needs to carry only a process identifier, and consequently, there are onlyndifferent messagesELECTION().

4.5 Two Particular Cases

Leader Election in an Arbitrary Network To elect a leader in a connected arbi-trary network, one can use network traversal algorithms such as those described in Chap.1.

Each process launches a network traversal with feedback, and all the messages related to the network traversal launched by a processpiare tagged with its identity idi. Moreover, each process continues participating only in the network traversal it has seen that has been launched with the greatest identity. It follows that a single network traversal will terminate, namely the one launched by the process with the greatest identity.

(1) rdirandom(1, n);broadcastRANDOM(rdi);

(2) wait(a messageRANDOM(rdx)from each processpx);

(3) electedix=1n rdx)modn+1.

Fig. 4.10 Index-based randomized election (code forpi)

When the Indexes Are the Identities When the identity of a process is its index, and both this fact andnare known by all processes, the leader election problem is trivial. It is sufficient to statically select an index and define the corresponding process as the leader. While this works, it has a drawback, namely, the same process is always elected.

There is a simple way to solve this issue, as soon as the processes can use random numbers. Letrandom(1, n)be a function that returns a random number in{1, . . . , n} each time it is called.

The algorithm described in Fig.4.10is a very simple randomized election al-gorithm. Each process first obtains a random number and sends it to all. Then, it waits until it has received all random numbers. When this occurs, the processes can compute the same process identity, and consistently elect the corresponding process (line3). The costs of the algorithm areO(1)time units andO(n2)messages.

The probability that a given processpx is elected can be computed from the specific probability law associated with the functionrandom().

4.6 Summary

This chapter was devoted to election algorithms on a ring. After a simple proof that no such algorithm exists in anonymous ring networks, the chapter presented three algorithms for non-anonymous rings. Non-anonymous means here that (a) each pro-cesspi has an identity idi, (b) no two processes have the same identity, (c) identities can be compared, (d) initially, a process knows only its identity, and (e) no process knowsn(total number of processes).

Interestingly, this chapter has presented twoO(nlogn)elections algorithms that are optimal. The first, due to Hirschberg and Sinclair, is suited to bidirectional rings, while the second, due to Dolev, Klawe, and Rodeh, is suited to both unidirectional rings and bidirectional rings (this is because a bidirectional ring can always be con-sidered as if it was unidirectional). This algorithm shows that, contrary to what one could think, the fact that a ring is unidirectional or bidirectional has no impact on its optimal message complexity when considering aO()point of view.

4.7 Bibliographic Notes

• The impossibility of solving the leader election problem in anonymous rings is due to D. Angluin [19].

4.8 Exercises and Problems 91

• The general problem of what can be computed in anonymous networks is ad-dressed in [22,392,393].

• The distributed election problem and its first solution are due to G. Le Lann [232].

• TheO(n2)election algorithm presented in Sect.4.2is due to E.J.H. Chang and R. Roberts [83].

• TheO(nlogn)election algorithm for bidirectional rings presented in Sect.4.3is due to D.S. Hirschberg and J.B. Sinclair [185].

• TheO(nlogn)election algorithm for unidirectional rings presented in Sect.4.4 is due to D. Dolev, M. Klawe, and M. Rodeh [117]. Simultaneously and indepen-dently, a similar algorithm was presented by G.L. Peterson [295]. Another leader election algorithm for rings is presented in [134].

• Leader election algorithms in complete networks are studied in [208]. Numerous leader election algorithms suited to various network topologies (e.g., trees) are presented by N. Santoro in [335].

• Several authors have shown thatΩ(nlogn)is a lower bound on the number of messages in both ring networks and complete networks (e.g., [24,56,288]).

• The best election algorithm on unidirectional ring networks known so far is due to L. Higham and T. Przytycka [184]. Its message complexity is 1.271nlogn+ O(n). However, it is not yet known what is the smallest constant c such that an election can be solved on unidirectional rings with message complexityc× nlogn+O(n)(it is only known thatc≥0.69 [56]).

Higham and Przytycka’s algorithm is based on rounds and assumes that all processes start with the same initial round number. An extension of this algorithm is presented in [20], which allows the processes to start with arbitrary round num-bers. This extension, which is motivated by fault-tolerance with respect to initial values, guarantees that the message complexity isO(nlogn)when the processes start with the same round number, and may increase up toO(n2)when each pro-cess starts with an arbitrary round number. This fault-tolerance property is called graceful degradation with respect to initial values.

• Leader election in dynamic networks and mobile ad hoc networks is addressed in [197,244].

4.8 Exercises and Problems

1. Extend the proof of Theorem2so that it works for any anonymous regular net-work.

2. Considering the variant of Chang and Robert’s election algorithm described in Fig.4.3, and assuming thatkprocesses send anELECTION()message at line1, what is the maximal number of ELECTION()messages sent (at lines1 and2) during an execution of the algorithm?

Answer:nkk(k21).

3. Show that the worst case for the time complexity of Hirschberg and Sinclair’s election algorithm is whennis 1 more than a power of 2. Show that, in this case, the time complexity is 6n−6.

Solution in [185].

Chapter 5

Outline

Documents relatifs