Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't start a learner node with no peers #7582

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,8 @@ func (n *node) InitAndStartNode() {
_, restart, err := n.PastLife()
x.Check(err)

if _, hasPeer := groups().MyPeer(); !restart && hasPeer {
_, hasPeer := groups().MyPeer()
if !restart && hasPeer {
// The node has other peers, it might have crashed after joining the cluster and before
// writing a snapshot. Check from leader, if it is part of the cluster. Consider this a
// restart if it is part of the cluster, else start a new node.
Expand All @@ -1742,6 +1743,10 @@ func (n *node) InitAndStartNode() {
}
}

if n.RaftContext.IsLearner && !hasPeer {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the case of restart, should we check again after making connections to nodes in ConfState? I don't know why it is required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we keep this here for now.

glog.Fatal("Cannot start a learner node without peer alpha nodes")
}

if restart {
glog.Infof("Restarting node for group: %d\n", n.gid)
sp, err := n.Store.Snapshot()
Expand All @@ -1754,6 +1759,7 @@ func (n *node) InitAndStartNode() {
// zero-member Raft group.
n.SetConfState(&sp.Metadata.ConfState)

// TODO: Making connections here seems unnecessary, evaluate.
members := groups().members(n.gid)
for _, id := range sp.Metadata.ConfState.Nodes {
m, ok := members[id]
Expand Down