File tree 3 files changed +12
-4
lines changed
3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ func (e *Election) AddNotified(id string) {
18
18
e .notified = append (e .notified , id )
19
19
}
20
20
21
+ // NotifiedCount gets the number of items in the notified list
22
+ func (e * Election ) NotifiedCount () int {
23
+ return len (e .notified )
24
+ }
25
+
21
26
// GetHighest will return the highest value in the notified list
22
27
func (e * Election ) GetHighest () string {
23
28
max := ""
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ type Notify struct {
6
6
visited []string
7
7
}
8
8
9
- // NewElected creates a new instance of an Notify message
10
- func NewElected (id string ) Notify {
9
+ // NewNotify creates a new instance of an Notify message
10
+ func NewNotify (id string ) Notify {
11
11
e := Notify {}
12
12
e .visited = make ([]string , 0 )
13
13
e .Master = id
Original file line number Diff line number Diff line change @@ -52,17 +52,20 @@ func (r *Process) electionResponder() {
52
52
// add name to alive list and send to neighbor
53
53
if m .Exists (r .ID ) {
54
54
r .SetMaster (m .GetHighest ())
55
- q := message .NewElected (m .GetHighest ())
55
+ q := message .NewNotify (m .GetHighest ())
56
56
q .AddVisited (r .ID )
57
57
r .getNeighbor ().notifyQueue <- q
58
58
} else {
59
- r .Emitter .Write (r .ID , r .getNeighbor ().ID , "ELECT " )
59
+ r .Emitter .Write (r .ID , r .getNeighbor ().ID , "START_NEW_ELECTION " )
60
60
m .AddNotified (r .ID )
61
61
r .getNeighbor ().electionQueue <- m
62
62
}
63
63
case m := <- r .notifyQueue :
64
64
// set master to consensus and send to neighbor
65
65
if ! m .Visited (r .ID ) {
66
+ if r .ID == m .Master {
67
+ r .Emitter .Write (r .ID , "" , "ELECTED" )
68
+ }
66
69
r .SetMaster (m .Master )
67
70
m .AddVisited (r .ID )
68
71
r .Emitter .Write (r .ID , r .getNeighbor ().ID , "ELECT" )
You can’t perform that action at this time.
0 commit comments