mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-28 04:10:44 -04:00
* Implement raft-wal * go mod tidy * add metrics, fix a panic * fix the panic for real this time * PR feedback * refactor tests to use a helper and reduce duplication * add a test to verify we don't use raft-wal if raft.db exists * add config to enable the verifier * add tests for parsing verification intervals * run the verifier in the background * wire up the verifier * go mod tidy * refactor config parsing * remove unused function * trying to get the verifier working * wire up some more verifier bits * sorted out an error, added a new test, lots of debug logging that needs to come out * fix a bug and remove all the debugging statements * make sure we close raft-wal stablestore too * run verifier tests for both boltdb and raft-wal * PR feedback * Vault 20270 docker test raft wal (#24463) * adding a migration test from boltdb to raftwal and back adding a migration test using snapshot restore * feedback * Update physical/raft/raft.go Co-authored-by: Paul Banks <pbanks@hashicorp.com> * PR feedback * change verifier function * make this shorter * add changelog * Fix Close behavior * make supporting empty logs more explicit * add some godocs --------- Co-authored-by: hamid ghaf <hamid@hashicorp.com> Co-authored-by: Hamid Ghaf <83242695+hghaf099@users.noreply.github.com> Co-authored-by: Paul Banks <pbanks@hashicorp.com>
93 lines
2.1 KiB
Go
93 lines
2.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package raft
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/go-hclog"
|
|
"github.com/hashicorp/go-uuid"
|
|
)
|
|
|
|
func GetRaft(t testing.TB, bootstrap bool, noStoreState bool) (*RaftBackend, string) {
|
|
return getRaftInternal(t, bootstrap, defaultRaftConfig(t, bootstrap, noStoreState), nil)
|
|
}
|
|
|
|
func GetRaftWithConfig(t testing.TB, bootstrap bool, noStoreState bool, conf map[string]string) (*RaftBackend, string) {
|
|
defaultConf := defaultRaftConfig(t, bootstrap, noStoreState)
|
|
conf["path"] = defaultConf["path"]
|
|
conf["doNotStoreLatestState"] = defaultConf["doNotStoreLatestState"]
|
|
return getRaftInternal(t, bootstrap, conf, nil)
|
|
}
|
|
|
|
func GetRaftWithLogOutput(t testing.TB, bootstrap bool, noStoreState bool, logOutput io.Writer) (*RaftBackend, string) {
|
|
return getRaftInternal(t, bootstrap, defaultRaftConfig(t, bootstrap, noStoreState), logOutput)
|
|
}
|
|
|
|
func defaultRaftConfig(t testing.TB, bootstrap bool, noStoreState bool) map[string]string {
|
|
raftDir := t.TempDir()
|
|
t.Logf("raft dir: %s", raftDir)
|
|
|
|
conf := map[string]string{
|
|
"path": raftDir,
|
|
"trailing_logs": "100",
|
|
}
|
|
|
|
if noStoreState {
|
|
conf["doNotStoreLatestState"] = ""
|
|
}
|
|
|
|
return conf
|
|
}
|
|
|
|
func getRaftInternal(t testing.TB, bootstrap bool, conf map[string]string, logOutput io.Writer) (*RaftBackend, string) {
|
|
id, err := uuid.GenerateUUID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
logger := hclog.New(&hclog.LoggerOptions{
|
|
Name: fmt.Sprintf("raft-%s", id),
|
|
Level: hclog.Trace,
|
|
Output: logOutput,
|
|
})
|
|
|
|
conf["node_id"] = id
|
|
|
|
backendRaw, err := NewRaftBackend(conf, logger)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
backend := backendRaw.(*RaftBackend)
|
|
|
|
if bootstrap {
|
|
err = backend.Bootstrap([]Peer{
|
|
{
|
|
ID: backend.NodeID(),
|
|
Address: backend.NodeID(),
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = backend.SetupCluster(context.Background(), SetupOpts{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
for {
|
|
if backend.raft.AppliedIndex() >= 2 {
|
|
break
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
backend.DisableAutopilot()
|
|
return backend, conf["path"]
|
|
}
|