Skip to content

Commit aaa0273

Browse files
author
Aaron Lehmann
committed
raft: ForceNewCluster flag should only apply at startup
ForceNewCluster tells raft to use the existing state to create a new cluster with a single member. This means that when first reading the WAL/snapshot, the other existing managers are removed. However, it doesn't make sense to do this more than once. For example, if other managers are added to the cluster, and one of them takes over as the leader, and sends the initial leader a snapshot, that snapshot should be accepted without modifications. Change the ForceNewCluster flag to only apply on startup. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
1 parent a30b34d commit aaa0273

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

manager/state/raft/raft.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ type Node struct {
104104
// shutting down the node.
105105
waitProp sync.WaitGroup
106106

107-
// forceNewCluster is a special flag used to recover from disaster
108-
// scenario by pointing to an existing or backed up data directory.
109-
forceNewCluster bool
110-
111107
confState raftpb.ConfState
112108
appliedIndex uint64
113109
snapshotIndex uint64
@@ -192,7 +188,6 @@ func NewNode(ctx context.Context, opts NewNodeOptions) *Node {
192188
MaxInflightMsgs: cfg.MaxInflightMsgs,
193189
Logger: cfg.Logger,
194190
},
195-
forceNewCluster: opts.ForceNewCluster,
196191
stopCh: make(chan struct{}),
197192
doneCh: make(chan struct{}),
198193
removeRaftCh: make(chan struct{}),
@@ -362,7 +357,7 @@ func (n *Node) Run(ctx context.Context) error {
362357
// saveToStorage.
363358
if !raft.IsEmptySnap(rd.Snapshot) {
364359
// Load the snapshot data into the store
365-
if err := n.restoreFromSnapshot(rd.Snapshot.Data, n.forceNewCluster); err != nil {
360+
if err := n.restoreFromSnapshot(rd.Snapshot.Data, false); err != nil {
366361
n.Config.Logger.Error(err)
367362
}
368363
n.appliedIndex = rd.Snapshot.Metadata.Index

0 commit comments

Comments
 (0)