From b3af58d758829372b3e62ff1ef376b70d82aa099 Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Fri, 19 Mar 2021 15:41:42 -0400 Subject: [PATCH] Expose snapshot_interval tunable instead of setting it in prod code for the sake of a test. (#11160) --- physical/raft/raft.go | 20 +++++++++++++------ .../raft/raft_autopilot_test.go | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/physical/raft/raft.go b/physical/raft/raft.go index 73a08dedc..5d207ad07 100644 --- a/physical/raft/raft.go +++ b/physical/raft/raft.go @@ -5,6 +5,11 @@ import ( "crypto/tls" "errors" "fmt" + "github.com/hashicorp/vault/sdk/helper/consts" + "github.com/hashicorp/vault/sdk/helper/jsonutil" + "github.com/hashicorp/vault/sdk/helper/tlsutil" + "github.com/hashicorp/vault/sdk/logical" + "github.com/hashicorp/vault/sdk/physical" "io" "io/ioutil" "os" @@ -24,11 +29,6 @@ import ( autopilot "github.com/hashicorp/raft-autopilot" snapshot "github.com/hashicorp/raft-snapshot" raftboltdb "github.com/hashicorp/vault/physical/raft/logstore" - "github.com/hashicorp/vault/sdk/helper/consts" - "github.com/hashicorp/vault/sdk/helper/jsonutil" - "github.com/hashicorp/vault/sdk/helper/tlsutil" - "github.com/hashicorp/vault/sdk/logical" - "github.com/hashicorp/vault/sdk/physical" "github.com/hashicorp/vault/vault/cluster" "github.com/hashicorp/vault/vault/seal" ) @@ -615,6 +615,15 @@ func (b *RaftBackend) applyConfigSettings(config *raft.Config) error { } config.TrailingLogs = uint64(trailingLogs) } + snapshotIntervalRaw, ok := b.conf["snapshot_interval"] + if ok { + var err error + snapshotInterval, err := time.ParseDuration(snapshotIntervalRaw) + if err != nil { + return err + } + config.SnapshotInterval = snapshotInterval + } config.NoSnapshotRestoreOnStart = true config.MaxAppendEntries = 64 @@ -683,7 +692,6 @@ func (b *RaftBackend) SetupCluster(ctx context.Context, opts SetupOpts) error { // Setup the raft config raftConfig := raft.DefaultConfig() - raftConfig.SnapshotInterval = 5 * time.Second if err := b.applyConfigSettings(raftConfig); err != nil { return err } diff --git a/vault/external_tests/raft/raft_autopilot_test.go b/vault/external_tests/raft/raft_autopilot_test.go index 6488aca82..b07e6f01b 100644 --- a/vault/external_tests/raft/raft_autopilot_test.go +++ b/vault/external_tests/raft/raft_autopilot_test.go @@ -225,6 +225,7 @@ func TestRaft_Autopilot_Stabilization_Delay(t *testing.T) { "snapshot_threshold": "50", "trailing_logs": "100", "autopilot_reconcile_interval": "1s", + "snapshot_interval": "5s", } if coreIdx == 2 { config["snapshot_delay"] = timeToHealthyCore2.String() @@ -276,7 +277,6 @@ func TestRaft_Autopilot_Stabilization_Delay(t *testing.T) { { LeaderAPIAddr: client.Address(), TLSConfig: cluster.Cores[0].TLSConfig, - Retry: true, }, }, false) require.NoError(t, err)