Unverified Commit 43b09f27 authored by Brian Kassouf's avatar Brian Kassouf Committed by GitHub
Browse files

physical/raft: Add a function that gets the offline, stale configuration (#11821)

* Add a function that gets the offline, stale configuration

* Fix comment
parent 6cc8b0e6
No related merge requests found
Showing with 34 additions and 1 deletion
+34 -1
......@@ -21,7 +21,7 @@ import (
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/raft"
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"
"github.com/hashicorp/vault/helper/metricsutil"
"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))
}
// 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) {
b.l.RLock()
defer b.l.RUnlock()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment