Skip to content

Commit 0da8e86

Browse files
committed
Adding master notification
1 parent 5012414 commit 0da8e86

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Diff for: server/ring/message/election.go

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ func (e *Election) AddNotified(id string) {
1818
e.notified = append(e.notified, id)
1919
}
2020

21+
// NotifiedCount gets the number of items in the notified list
22+
func (e *Election) NotifiedCount() int {
23+
return len(e.notified)
24+
}
25+
2126
// GetHighest will return the highest value in the notified list
2227
func (e *Election) GetHighest() string {
2328
max := ""

Diff for: server/ring/message/notify.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ type Notify struct {
66
visited []string
77
}
88

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 {
1111
e := Notify{}
1212
e.visited = make([]string, 0)
1313
e.Master = id

Diff for: server/ring/process.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@ func (r *Process) electionResponder() {
5252
// add name to alive list and send to neighbor
5353
if m.Exists(r.ID) {
5454
r.SetMaster(m.GetHighest())
55-
q := message.NewElected(m.GetHighest())
55+
q := message.NewNotify(m.GetHighest())
5656
q.AddVisited(r.ID)
5757
r.getNeighbor().notifyQueue <- q
5858
} else {
59-
r.Emitter.Write(r.ID, r.getNeighbor().ID, "ELECT")
59+
r.Emitter.Write(r.ID, r.getNeighbor().ID, "START_NEW_ELECTION")
6060
m.AddNotified(r.ID)
6161
r.getNeighbor().electionQueue <- m
6262
}
6363
case m := <-r.notifyQueue:
6464
// set master to consensus and send to neighbor
6565
if !m.Visited(r.ID) {
66+
if r.ID == m.Master {
67+
r.Emitter.Write(r.ID, "", "ELECTED")
68+
}
6669
r.SetMaster(m.Master)
6770
m.AddVisited(r.ID)
6871
r.Emitter.Write(r.ID, r.getNeighbor().ID, "ELECT")

0 commit comments

Comments
 (0)