Skip to content

Commit

Permalink
Use new field nextRaftId to give unique IDs to new nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmr committed Jun 4, 2020
1 parent e326b9e commit fb8429b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dgraph/cmd/zero/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Server struct {

NumReplicas int
state *pb.MembershipState
nextRaftId uint64

nextLeaseId uint64
nextTxnTs uint64
Expand Down Expand Up @@ -83,6 +84,7 @@ func (s *Server) Init() {
Groups: make(map[uint32]*pb.Group),
Zeros: make(map[uint64]*pb.Member),
}
s.nextRaftId = 1
s.nextLeaseId = 1
s.nextTxnTs = 1
s.nextGroup = 1
Expand Down Expand Up @@ -217,7 +219,10 @@ func (s *Server) hasLeader(gid uint32) bool {
func (s *Server) SetMembershipState(state *pb.MembershipState) {
s.Lock()
defer s.Unlock()

s.state = state
s.nextRaftId = x.Max(s.nextRaftId, s.state.MaxRaftId + 1)

if state.Zeros == nil {
state.Zeros = make(map[uint64]*pb.Member)
}
Expand Down Expand Up @@ -491,7 +496,8 @@ func (s *Server) Connect(ctx context.Context,
}
}
if m.Id == 0 {
m.Id = s.state.MaxRaftId + 1
m.Id = s.nextRaftId
s.nextRaftId += 1
proposal.MaxRaftId = m.Id
}

Expand Down

0 comments on commit fb8429b

Please sign in to comment.