mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 20:17:59 +00:00
physical/raft: Add a function that gets the offline, stale configuration (#11821)
* Add a function that gets the offline, stale configuration * Fix comment
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
|||||||
"github.com/hashicorp/go-uuid"
|
"github.com/hashicorp/go-uuid"
|
||||||
"github.com/hashicorp/raft"
|
"github.com/hashicorp/raft"
|
||||||
autopilot "github.com/hashicorp/raft-autopilot"
|
autopilot "github.com/hashicorp/raft-autopilot"
|
||||||
"github.com/hashicorp/raft-boltdb/v2"
|
raftboltdb "github.com/hashicorp/raft-boltdb/v2"
|
||||||
snapshot "github.com/hashicorp/raft-snapshot"
|
snapshot "github.com/hashicorp/raft-snapshot"
|
||||||
"github.com/hashicorp/vault/helper/metricsutil"
|
"github.com/hashicorp/vault/helper/metricsutil"
|
||||||
"github.com/hashicorp/vault/sdk/helper/consts"
|
"github.com/hashicorp/vault/sdk/helper/consts"
|
||||||
@@ -982,6 +982,39 @@ func (b *RaftBackend) RemovePeer(ctx context.Context, peerID string) error {
|
|||||||
return b.autopilot.RemoveServer(raft.ServerID(peerID))
|
return b.autopilot.RemoveServer(raft.ServerID(peerID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetConfigurationOffline is used to read the stale, last known raft
|
||||||
|
// configuration to this node. It accesses the last state written into the
|
||||||
|
// FSM. When a server is online use GetConfiguration instead.
|
||||||
|
func (b *RaftBackend) GetConfigurationOffline() (*RaftConfigurationResponse, error) {
|
||||||
|
b.l.RLock()
|
||||||
|
defer b.l.RUnlock()
|
||||||
|
|
||||||
|
if b.raft != nil {
|
||||||
|
return nil, errors.New("raft storage is initialized, used GetConfiguration instead")
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.fsm == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
state, configuration := b.fsm.LatestState()
|
||||||
|
config := &RaftConfigurationResponse{
|
||||||
|
Index: state.Index,
|
||||||
|
}
|
||||||
|
for _, server := range configuration.Servers {
|
||||||
|
entry := &RaftServer{
|
||||||
|
NodeID: server.Id,
|
||||||
|
Address: server.Address,
|
||||||
|
// Since we are offline no node is the leader.
|
||||||
|
Leader: false,
|
||||||
|
Voter: raft.ServerSuffrage(server.Suffrage) == raft.Voter,
|
||||||
|
}
|
||||||
|
config.Servers = append(config.Servers, entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *RaftBackend) GetConfiguration(ctx context.Context) (*RaftConfigurationResponse, error) {
|
func (b *RaftBackend) GetConfiguration(ctx context.Context) (*RaftConfigurationResponse, error) {
|
||||||
b.l.RLock()
|
b.l.RLock()
|
||||||
defer b.l.RUnlock()
|
defer b.l.RUnlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user