Skip to content
Permalink
Browse files

update zero's leader information in state periodically

  • Loading branch information
Janardhan Reddy
Janardhan Reddy committed Apr 16, 2018
1 parent 7be1cd2 commit b8c090884d0e8ecc3eac7cb18aef631abdf0b662
Showing with 18 additions and 1 deletion.
  1. +18 −1 dgraph/cmd/zero/raft.go
@@ -476,6 +476,22 @@ func (n *node) initAndStartNode(wal *raftwal.Wal) error {
return err
}

func (n *node) updateZeroMembershipPeriodically(closer *y.Closer) {
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()

for {
select {
case <-ticker.C:
n.server.updateZeroLeader()

case <-closer.HasBeenClosed():
closer.Done()
return
}
}
}

func (n *node) snapshotPeriodically(closer *y.Closer) {
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
@@ -521,10 +537,11 @@ func (n *node) Run() {
rcBytes, err := n.RaftContext.Marshal()
x.Check(err)

closer := y.NewCloser(2)
closer := y.NewCloser(3)
// snapshot can cause select loop to block while deleting entries, so run
// it in goroutine
go n.snapshotPeriodically(closer)
go n.updateZeroMembershipPeriodically(closer)
// We only stop runReadIndexLoop after the for loop below has finished interacting with it.
// That way we know sending to readStateCh will not deadlock.
defer closer.SignalAndWait()

0 comments on commit b8c0908

Please sign in to comment.
You can’t perform that action at this time.