Skip to content

Commit

Permalink
update state without proposal when leader changes in zero (#2319)
Browse files Browse the repository at this point in the history
* update state without proposal when leader changes in zero
* copy key during predicate move
  • Loading branch information
Janardhan Reddy committed Apr 12, 2018
1 parent 6a24586 commit 3673f50
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 3 additions & 2 deletions dgraph/cmd/zero/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,9 @@ func (n *node) applyConfChange(e raftpb.Entry) {

func (n *node) triggerLeaderChange() {
n.server.triggerLeaderChange()
m := &intern.Member{Id: n.Id, Addr: n.RaftContext.Addr, Leader: n.AmLeader()}
go n.proposeAndWait(context.Background(), &intern.ZeroProposal{Member: m})
// We update leader information on each node without proposal. This
// function is called on all nodes on leader change.
n.server.updateZeroLeader()
}

func (n *node) initAndStartNode(wal *raftwal.Wal) error {
Expand Down
13 changes: 13 additions & 0 deletions dgraph/cmd/zero/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ func (s *Server) storeZero(m *intern.Member) {
s.state.Zeros[m.Id] = m
}

func (s *Server) updateZeroLeader() {
s.Lock()
defer s.Unlock()
leader := s.Node.Raft().Status().Lead
for _, m := range s.state.Zeros {
if m.Id == leader {
m.Leader = true
} else {
m.Leader = false
}
}
}

func (s *Server) removeZero(nodeId uint64) {
s.Lock()
defer s.Unlock()
Expand Down
5 changes: 4 additions & 1 deletion worker/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ func (g *groupi) applyState(state *intern.MembershipState) {
x.AssertTrue(state != nil)
g.Lock()
defer g.Unlock()
if g.state != nil && g.state.Counter >= state.Counter {
// We don't update state if we get any old state. Counter stores the raftindex of
// last update. For leader changes at zero since we don't propose, state can get
// updated at same counter value. So ignore only if counter is less.
if g.state != nil && g.state.Counter > state.Counter {
return
}

Expand Down
5 changes: 4 additions & 1 deletion worker/predicate_move.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ func movePredicateHelper(ctx context.Context, predicate string, gid uint32) erro
}
prevKey = prevKey[:len(key)]
copy(prevKey, key)
l, err := posting.ReadPostingList(prevKey, it)

nkey := make([]byte, len(key))
copy(nkey, key)
l, err := posting.ReadPostingList(nkey, it)
if err != nil {
return err
}
Expand Down

0 comments on commit 3673f50

Please sign in to comment.