Skip to content
Permalink
Browse files

update state without proposal when leader changes in zero (#2319)

* update state without proposal when leader changes in zero
* copy key during predicate move
  • Loading branch information...
janardhan1993 committed Apr 12, 2018
1 parent 6a24586 commit 3673f504a3dfb0355aa61a7bcfc1cb62555c70ab
Showing with 24 additions and 4 deletions.
  1. +3 −2 dgraph/cmd/zero/raft.go
  2. +13 −0 dgraph/cmd/zero/zero.go
  3. +4 −1 worker/groups.go
  4. +4 −1 worker/predicate_move.go
@@ -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 {
@@ -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()
@@ -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
}

@@ -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
}

0 comments on commit 3673f50

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