mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
backport of commit da5d0ca498 (#20994)
Co-authored-by: Nick Cabatoff <ncabatoff@hashicorp.com>
This commit is contained in:
committed by
GitHub
parent
55a2abd1b1
commit
ec2ec123db
3
changelog/20986.txt
Normal file
3
changelog/20986.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
storage/raft: Fix race where new follower joining can get pruned by dead server cleanup.
|
||||||
|
```
|
||||||
@@ -215,13 +215,15 @@ func NewFollowerStates() *FollowerStates {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the peer information in the follower states. Note that this function runs on the active node.
|
// Update the peer information in the follower states. Note that this function
|
||||||
func (s *FollowerStates) Update(req *EchoRequestUpdate) {
|
// runs on the active node. Returns true if a new entry was added, as opposed
|
||||||
|
// to modifying one already present.
|
||||||
|
func (s *FollowerStates) Update(req *EchoRequestUpdate) bool {
|
||||||
s.l.Lock()
|
s.l.Lock()
|
||||||
defer s.l.Unlock()
|
defer s.l.Unlock()
|
||||||
|
|
||||||
state, ok := s.followers[req.NodeID]
|
state, present := s.followers[req.NodeID]
|
||||||
if !ok {
|
if !present {
|
||||||
state = &FollowerState{
|
state = &FollowerState{
|
||||||
IsDead: atomic.NewBool(false),
|
IsDead: atomic.NewBool(false),
|
||||||
}
|
}
|
||||||
@@ -236,6 +238,8 @@ func (s *FollowerStates) Update(req *EchoRequestUpdate) {
|
|||||||
state.Version = req.SDKVersion
|
state.Version = req.SDKVersion
|
||||||
state.UpgradeVersion = req.UpgradeVersion
|
state.UpgradeVersion = req.UpgradeVersion
|
||||||
state.RedundancyZone = req.RedundancyZone
|
state.RedundancyZone = req.RedundancyZone
|
||||||
|
|
||||||
|
return !present
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear wipes all the information regarding peers in the follower states.
|
// Clear wipes all the information regarding peers in the follower states.
|
||||||
|
|||||||
@@ -248,9 +248,8 @@ func (b *SystemBackend) handleRaftRemovePeerUpdate() framework.OperationFunc {
|
|||||||
if err := raftBackend.RemovePeer(ctx, serverID); err != nil {
|
if err := raftBackend.RemovePeer(ctx, serverID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if b.Core.raftFollowerStates != nil {
|
|
||||||
b.Core.raftFollowerStates.Delete(serverID)
|
b.Core.raftFollowerStates.Delete(serverID)
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -351,16 +350,6 @@ func (b *SystemBackend) handleRaftBootstrapAnswerWrite() framework.OperationFunc
|
|||||||
return nil, errors.New("could not decode raft TLS configuration")
|
return nil, errors.New("could not decode raft TLS configuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch nonVoter {
|
|
||||||
case true:
|
|
||||||
err = raftBackend.AddNonVotingPeer(ctx, serverID, clusterAddr)
|
|
||||||
default:
|
|
||||||
err = raftBackend.AddPeer(ctx, serverID, clusterAddr)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var desiredSuffrage string
|
var desiredSuffrage string
|
||||||
switch nonVoter {
|
switch nonVoter {
|
||||||
case true:
|
case true:
|
||||||
@@ -369,11 +358,22 @@ func (b *SystemBackend) handleRaftBootstrapAnswerWrite() framework.OperationFunc
|
|||||||
desiredSuffrage = "voter"
|
desiredSuffrage = "voter"
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Core.raftFollowerStates != nil {
|
added := b.Core.raftFollowerStates.Update(&raft.EchoRequestUpdate{
|
||||||
b.Core.raftFollowerStates.Update(&raft.EchoRequestUpdate{
|
NodeID: serverID,
|
||||||
NodeID: serverID,
|
DesiredSuffrage: desiredSuffrage,
|
||||||
DesiredSuffrage: desiredSuffrage,
|
})
|
||||||
})
|
|
||||||
|
switch nonVoter {
|
||||||
|
case true:
|
||||||
|
err = raftBackend.AddNonVotingPeer(ctx, serverID, clusterAddr)
|
||||||
|
default:
|
||||||
|
err = raftBackend.AddPeer(ctx, serverID, clusterAddr)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
if added {
|
||||||
|
b.Core.raftFollowerStates.Delete(serverID)
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
peers, err := raftBackend.Peers(ctx)
|
peers, err := raftBackend.Peers(ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user