You are on page 1of 22

Election Algorithms and Distributed Processing

Section 6.5

Election algorithms introduction Traditional election algorithms
Bully algorithm ing algorithm

!ireless election algorithms

"eed #or a $oordinator

%any algorithms used in distributed systems re&uire a coordinator
'or e(am)le* see the centrali+ed mutual e(clusion algorithm.

,n general* all )rocesses in the distributed system are e&ually suitable #or the role Election algorithms are designed to choose a coordinator.

Election Algorithms
Any )rocess can ser-e as coordinator Any )rocess can .call an election/ 0initiate the algorithm to choose a ne1 coordinator2.
There is no harm 0other than e(tra message tra##ic2 in ha-ing multi)le concurrent elections.

Elections may be needed 1hen the system is initiali+ed* or i# the coordinator crashes or retires.

E-ery )rocess3site has a uni&ue ,D4 e.g.
the net1or5 address a )rocess number

E-ery )rocess in the system should 5no1 the -alues in the set o# ,D numbers* although not 1hich )rocessors are u) or do1n. The )rocess 1ith the highest ,D number 1ill be the ne1 coordinator. Process grou)s 0as 1ith ,S,S tool5it or %P,2 satis#y these re&uirements.

!hen the election algorithm terminates a single )rocess has been selected and e-ery )rocess 5no1s its identity. 'ormali+e6 e-ery )rocess )i has a -ariable ei to hold the coordinator7s )rocess number.
i* ei 8 unde#ined or ei 8 P* 1here P is the non9crashed )rocess 1ith highest id All )rocesses 0that ha-e not crashed2 e-entually set ei 8 P.

The Bully Algorithm 9 O-er-ie1

Process p calls an election 1hen it notices that the coordinator is no longer res)onding. :igh9numbered )rocesses .bully/ lo19 numbered )rocesses out o# the election* until only one )rocess remains. !hen a crashed )rocess reboots* it holds an election. ,# it is no1 the highest9 numbered li-e )rocess* it 1ill 1in.

'igure 69;? < ; election @ election election ? = > 6 @ ? > OA = 5 < ; OA 6 5

Process p sends an election message to all higher-numbered )rocesses in the system. ,# no )rocess res)onds* then p becomes the coordinator. ,# a higher9le-el )rocess 0q2 res)onds* it sends p a message that terminates p7s role in the algorithm

The )rocess q no1 calls an election 0i# it has not already done so2. e)eat until no higher9le-el )rocess res)onds. The last )rocess to call an election .1ins/ the election. The 1inner sends a message to other )rocesses announcing itsel# as the ne1 coordinator.
< ; @ = > 5 6 @ ? 'igure 69;? OA ;

< ; @ ?

5 election 6 election = >



5 6

coordinator =


,# > comes bac5 on line* it 1ill call an election

< ; election @

5 6 @ = > < ; @ = >

< ; OA OA ? >

5 6

< ; @ ?

5 election 6 election = >

election election ?


5 6

< OA ; @ coordinator

5 6

? 'igure 69;?


!or5s best i# communication in the system has bounded latency so )rocesses can determine that a )rocess has #ailed by 5no1ing the u))er bound 0BB2 on message transmission time 0T2 and message )rocessing time 0%2.
BB 8 ; C T D %

:o1e-er* i# a )rocess calls an election 1hen the coordinator is still acti-e* the coordinator 1ill 1in the election.

ing Algorithm 9 O-er-ie1

The ring algorithm assumes that the )rocesses are arranged in a logical ring and each )rocess is 5no1s the order o# the ring o# )rocesses. Processes are able to .s5i)/ #aulty systems6 instead o# sending to )rocess E* send to E D <. 'aulty systems are those that don7t res)ond in a #i(ed amount o# time.

ing Algorithm

P thin5s the coordinator has crashed4 builds an EFE$T,O" message 1hich contains its o1n ,D number. Sends to #irst li-e successor Each )rocess adds its o1n number and #or1ards to ne(t. OA to ha-e t1o elections at once.

ing Algorithm 9 Details

!hen the message returns to p* it sees its o1n )rocess ,D in the list and 5no1s that the circuit is com)lete. P circulates a $OO D,"ATO message 1ith the ne1 high number. :ere* both ; and 5 elect 66 G5*6*?*<*;*=*@H G;*=*@*5*6*?*<H

Elections in !ireless En-ironments

Traditional algorithms aren7t a))ro)riate.
$an7t assume reliable message )assing or stable net1or5 con#iguration

This discussion #ocuses on ad hoc wireless networks but ignores node mobility.
"odes connect directly* no common access )oint* connection is short term O#ten used in multi)layer gaming* on9the9#ly #ile trans#ers* etc.

!ireless algorithms try to #ind the best node to be coordinator4 traditional algorithms are satis#ied 1ith any node. Any node 0the source2 can initiate an election by sending an EFE$T,O" message to its neighbors nodes 1ithin range. !hen a node recei-es its #irst EFE$T,O" message the sender becomes its parent node.

'igure 69;;.

"ode a is the source. %essages ha-e a uni&ue ,D to manage )ossible concurrent elections

'igure 6.;;

'igure 69;;. Election algorithm in a 1ireless net1or5* 1ith node a as the source. 0a2 ,nitial net1or5. 0b20e2 The build9tree )hase
!hen a node recei-es its #irst election message* it designates the source I as its )arent* and #or1ards the message to all neighbors e(ce)t I. !hen recei-es an election message #rom a non9 )arent* it Eust ac5no1ledges the message

'igure 69;;. 0e2 The build9tree )hase. 0#2 e)orting o# best node to source.

,# 7s neighbors ha-e )arents* is a lea#4 other1ise it 1aits #or its children to #or1ard the message to their neighbors. !hen has collected ac5s #rom all its neighbors* it ac5no1ledges the message #rom I. Ac5no1ledgements #lo1 bac5 u) the tree to the original source.

!ireless Elections
At each stage the .most eligible/ or .best/ node 1ill be )assed along #rom child to )arent. Once the source node has recei-ed all the re)lies* it is in a )osition to choose the ne1 coordinator. !hen the selection is made* it is broadcast to all nodes in the net1or5.

!ireless Elections
,# more than one election is called 0multi)le source nodes2* a node should )artici)ate in only one. Election messages are tagged 1ith a )rocess id. ,# a node has chosen a )arent but gets an election message #rom a higher numbered node* it dro)s out o# the current election and ado)ts the high numbered node as its )arent. This ensures only one election ma5es a choice.

$ha)ter 6 9 Summary
.Synchroni+ation is J doing the right thing at the right time./ Synchroni+ation in distributed systems is related to communication. $om)licated by lac5 o# global cloc5* shared memory. Fogical cloc5s su))ort global e-ent order. Distributed mute(6 im)ortant class o# synchroni+ation algorithms. Feader election algorithms are sometimes needed.