Skip to content
Snippets Groups Projects
Unverified Commit 5563bd27 authored by Pawan Rawal's avatar Pawan Rawal
Browse files

Update membership state if we can't find a leader while retrieving snapshot....

Update membership state if we can't find a leader while retrieving snapshot. Also make Leader() method only return a leader and not any server.
parent a259f9a1
No related branches found
No related tags found
No related merge requests found
...@@ -416,6 +416,12 @@ func (n *node) applyAllMarks(ctx context.Context) { ...@@ -416,6 +416,12 @@ func (n *node) applyAllMarks(ctx context.Context) {
func (n *node) retrieveSnapshot() error { func (n *node) retrieveSnapshot() error {
pool := groups().Leader(groups().groupId()) pool := groups().Leader(groups().groupId())
if pool == nil { if pool == nil {
// retrieveSnapshot is blocking at initial start and leader election for a group might
// not have happened when it is called. If we can't find a leader, get latest state from
// Zero.
if err := UpdateMembershipState(context.Background()); err != nil {
return fmt.Errorf("Error while trying to update membership state: %+v", err)
}
return fmt.Errorf("Unable to reach leader in group %d", n.gid) return fmt.Errorf("Unable to reach leader in group %d", n.gid)
} }
...@@ -623,6 +629,9 @@ func (n *node) joinPeers() error { ...@@ -623,6 +629,9 @@ func (n *node) joinPeers() error {
// Get leader information for MY group. // Get leader information for MY group.
pl := groups().Leader(n.gid) pl := groups().Leader(n.gid)
if pl == nil { if pl == nil {
if err := UpdateMembershipState(context.Background()); err != nil {
return fmt.Errorf("Error while trying to update membership state: %+v", err)
}
return x.Errorf("Unable to reach leader or any other server in group %d", n.gid) return x.Errorf("Unable to reach leader or any other server in group %d", n.gid)
} }
......
...@@ -106,7 +106,7 @@ func StartRaftNodes(walStore *badger.ManagedDB, bindall bool) { ...@@ -106,7 +106,7 @@ func StartRaftNodes(walStore *badger.ManagedDB, bindall bool) {
if connState.GetMember() == nil || connState.GetState() == nil { if connState.GetMember() == nil || connState.GetState() == nil {
x.Fatalf("Unable to join cluster via dgraphzero") x.Fatalf("Unable to join cluster via dgraphzero")
} }
x.Printf("Connected to group zero. Connection state: %+v\n", connState) x.Printf("Connected to group zero. Assigned group: %+v\n", connState.GetMember().GetGroupId())
Config.RaftId = connState.GetMember().GetId() Config.RaftId = connState.GetMember().GetId()
gr.applyState(connState.GetState()) gr.applyState(connState.GetState())
...@@ -418,9 +418,7 @@ func (g *groupi) Leader(gid uint32) *conn.Pool { ...@@ -418,9 +418,7 @@ func (g *groupi) Leader(gid uint32) *conn.Pool {
} }
} }
} }
// Unable to find a healthy connection to leader. Get connection to any other server in the return nil
// group.
return g.AnyServer(gid)
} }
func (g *groupi) KnownGroups() (gids []uint32) { func (g *groupi) KnownGroups() (gids []uint32) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment