From e87f01845cc84237704d4b5475172b0100ec8a7b Mon Sep 17 00:00:00 2001 From: Clint Date: Fri, 14 Feb 2020 14:25:53 -0600 Subject: [PATCH] Guard against using Raft as a seperate HA Storage (#8239) * Guard against using Raft as a seperate HA Storage * Document that Raft cannot be used as a seperate ha_storage backend at this time * remove duplicate imports from updating with master --- command/server.go | 6 ++++++ physical/raft/raft.go | 7 +++++++ website/pages/docs/configuration/storage/raft.mdx | 8 +++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/command/server.go b/command/server.go index 2c191c8948..cab8ca8c92 100644 --- a/command/server.go +++ b/command/server.go @@ -1132,6 +1132,12 @@ func (c *ServerCommand) Run(args []string) int { // Initialize the separate HA storage backend, if it exists var ok bool if config.HAStorage != nil { + // TODO: Remove when Raft can server as the ha_storage backend. + // See https://github.com/hashicorp/vault/issues/8206 + if config.HAStorage.Type == "raft" { + c.UI.Error("Raft cannot be used as seperate HA storage at this time") + return 1 + } factory, exists := c.PhysicalBackends[config.HAStorage.Type] if !exists { c.UI.Error(fmt.Sprintf("Unknown HA storage type %s", config.HAStorage.Type)) diff --git a/physical/raft/raft.go b/physical/raft/raft.go index 88ab76a52e..3ffb81a9e6 100644 --- a/physical/raft/raft.go +++ b/physical/raft/raft.go @@ -1018,6 +1018,13 @@ func (l *RaftLock) Lock(stopCh <-chan struct{}) (<-chan struct{}, error) { // Cache the notifyCh locally leaderNotifyCh := l.b.raftNotifyCh + // TODO: Remove when Raft can server as the ha_storage backend. The internal + // raft pointer should not be nil here, but the nil check is a guard against + // https://github.com/hashicorp/vault/issues/8206 + if l.b.raft == nil { + return nil, errors.New("attempted to grab a lock on a nil raft backend") + } + // Check to see if we are already leader. if l.b.raft.State() == raft.Leader { err := l.b.applyLog(context.Background(), &LogData{ diff --git a/website/pages/docs/configuration/storage/raft.mdx b/website/pages/docs/configuration/storage/raft.mdx index c8af8c5975..c733f1972b 100644 --- a/website/pages/docs/configuration/storage/raft.mdx +++ b/website/pages/docs/configuration/storage/raft.mdx @@ -35,7 +35,13 @@ storage "raft" { cluster_addr = "http://127.0.0.1:8201" ``` -**Note:** When using the Raft storage backend, it is required to provide `cluster_addr` to indicate the address and port to be used for communication between the nodes in the Raft cluster. +~> **Note:** When using the Raft storage backend, it is required to provide +`cluster_addr` to indicate the address and port to be used for communication +between the nodes in the Raft cluster. + +~> **Note:** Raft cannot be used as the configured `ha_storage` backend at this +time. To use Raft for HA coordination users must also use Raft for storage and +set `ha_enabled = true`. ## `raft` Parameters