Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Mar 7, 2022
1 parent a7bb06d commit a4c38fa
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion manager/state/raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func (n *Node) Run(ctx context.Context) error {
}
}

for _, msg := range rd.Messages {
for _, msg := range n.processMessages(rd.Messages) {
// Send raft messages to peers
if err := n.transport.Send(msg); err != nil {
log.G(ctx).WithError(err).Error("failed to send message to member")
Expand Down Expand Up @@ -741,6 +741,18 @@ func (n *Node) Run(ctx context.Context) error {
}
}

// When there is a `raftpb.EntryConfChange` after creating the snapshot,
// then the confState included in the snapshot is out of date. so We need
// to update the confState before sending a snapshot to a follower.
func (n *Node) processMessages(ms []raftpb.Message) []raftpb.Message {
for i := 0; i < len(ms); i++ {
if ms[i].Type == raftpb.MsgSnap {
ms[i].Snapshot.Metadata.ConfState = n.confState
}
}
return ms
}

func (n *Node) restoreFromSnapshot(ctx context.Context, data []byte) error {
snapCluster, err := n.clusterSnapshot(data)
if err != nil {
Expand Down

0 comments on commit a4c38fa

Please sign in to comment.