Skip to content

Commit

Permalink
Support autopilot when raft is for HA only (#11260) (#11340)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnayak authored Apr 12, 2021
1 parent 01882ca commit 8a1a8be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
18 changes: 9 additions & 9 deletions vault/logical_system_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ func (b *SystemBackend) handleStorageRaftSnapshotRead() framework.OperationFunc

func (b *SystemBackend) handleStorageRaftAutopilotState() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
raftBackend, ok := b.Core.underlyingPhysical.(*raft.RaftBackend)
if !ok {
raftBackend := b.Core.getRaftBackend()
if raftBackend == nil {
return logical.ErrorResponse("raft storage is not in use"), logical.ErrInvalidRequest
}

Expand Down Expand Up @@ -431,12 +431,12 @@ func (b *SystemBackend) handleStorageRaftAutopilotState() framework.OperationFun

func (b *SystemBackend) handleStorageRaftAutopilotConfigRead() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
raftStorage, ok := b.Core.underlyingPhysical.(*raft.RaftBackend)
if !ok {
raftBackend := b.Core.getRaftBackend()
if raftBackend == nil {
return logical.ErrorResponse("raft storage is not in use"), logical.ErrInvalidRequest
}

config := raftStorage.AutopilotConfig()
config := raftBackend.AutopilotConfig()
if config == nil {
return nil, nil
}
Expand All @@ -456,8 +456,8 @@ func (b *SystemBackend) handleStorageRaftAutopilotConfigRead() framework.Operati

func (b *SystemBackend) handleStorageRaftAutopilotConfigUpdate() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
raftStorage, ok := b.Core.underlyingPhysical.(*raft.RaftBackend)
if !ok {
raftBackend := b.Core.getRaftBackend()
if raftBackend == nil {
return logical.ErrorResponse("raft storage is not in use"), logical.ErrInvalidRequest
}

Expand Down Expand Up @@ -506,7 +506,7 @@ func (b *SystemBackend) handleStorageRaftAutopilotConfigUpdate() framework.Opera
persist = true
}

effectiveConf := raftStorage.AutopilotConfig()
effectiveConf := raftBackend.AutopilotConfig()
effectiveConf.Merge(config)

if effectiveConf.CleanupDeadServers && effectiveConf.MinQuorum < 3 {
Expand All @@ -525,7 +525,7 @@ func (b *SystemBackend) handleStorageRaftAutopilotConfigUpdate() framework.Opera
}

// Set the effectiveConfig
raftStorage.SetAutopilotConfig(effectiveConf)
raftBackend.SetAutopilotConfig(effectiveConf)

return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion vault/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (c *Core) setupRaftActiveNode(ctx context.Context) error {
c.logger.Error("failed to load autopilot config from storage when setting up cluster; continuing since autopilot falls back to default config", "error", err)
}
disableAutopilot := c.disableAutopilot
if c.isRaftHAOnly() || c.IsDRSecondary() {
if c.IsDRSecondary() {
disableAutopilot = true
}
raftBackend.SetupAutopilot(c.activeContext, autopilotConfig, c.raftFollowerStates, disableAutopilot)
Expand Down
19 changes: 8 additions & 11 deletions vault/request_forwarding_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"sync/atomic"
"time"

"github.com/hashicorp/vault/sdk/helper/consts"

"github.com/hashicorp/vault/helper/forwarding"
"github.com/hashicorp/vault/physical/raft"
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/hashicorp/vault/vault/replication"
)

Expand Down Expand Up @@ -83,10 +84,8 @@ func (s *forwardedRequestRPCServer) Echo(ctx context.Context, in *EchoRequest) (
}

if raftBackend := s.core.getRaftBackend(); raftBackend != nil {
if !s.core.isRaftHAOnly() {
reply.RaftAppliedIndex = raftBackend.AppliedIndex()
reply.RaftNodeID = raftBackend.NodeID()
}
reply.RaftAppliedIndex = raftBackend.AppliedIndex()
reply.RaftNodeID = raftBackend.NodeID()
}

return reply, nil
Expand Down Expand Up @@ -114,12 +113,10 @@ func (c *forwardingClient) startHeartbeat() {
}

if raftBackend := c.core.getRaftBackend(); raftBackend != nil {
if !c.core.isRaftHAOnly() {
req.RaftAppliedIndex = raftBackend.AppliedIndex()
req.RaftNodeID = raftBackend.NodeID()
req.RaftTerm = raftBackend.Term()
req.RaftDesiredSuffrage = raftBackend.DesiredSuffrage()
}
req.RaftAppliedIndex = raftBackend.AppliedIndex()
req.RaftNodeID = raftBackend.NodeID()
req.RaftTerm = raftBackend.Term()
req.RaftDesiredSuffrage = raftBackend.DesiredSuffrage()
}

ctx, cancel := context.WithTimeout(c.echoContext, 2*time.Second)
Expand Down

0 comments on commit 8a1a8be

Please sign in to comment.