Skip to content

Commit 7823a18

Browse files
committed
Expose snapshot_interval tunable instead of setting it in prod code for the sake of a test. (#11160)
1 parent 59dac19 commit 7823a18

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

physical/raft/raft.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import (
55
"crypto/tls"
66
"errors"
77
"fmt"
8+
"github.com/hashicorp/vault/sdk/helper/consts"
9+
"github.com/hashicorp/vault/sdk/helper/jsonutil"
10+
"github.com/hashicorp/vault/sdk/helper/tlsutil"
11+
"github.com/hashicorp/vault/sdk/logical"
12+
"github.com/hashicorp/vault/sdk/physical"
813
"io"
914
"io/ioutil"
1015
"os"
@@ -24,11 +29,6 @@ import (
2429
autopilot "github.com/hashicorp/raft-autopilot"
2530
snapshot "github.com/hashicorp/raft-snapshot"
2631
raftboltdb "github.com/hashicorp/vault/physical/raft/logstore"
27-
"github.com/hashicorp/vault/sdk/helper/consts"
28-
"github.com/hashicorp/vault/sdk/helper/jsonutil"
29-
"github.com/hashicorp/vault/sdk/helper/tlsutil"
30-
"github.com/hashicorp/vault/sdk/logical"
31-
"github.com/hashicorp/vault/sdk/physical"
3232
"github.com/hashicorp/vault/vault/cluster"
3333
"github.com/hashicorp/vault/vault/seal"
3434
)
@@ -613,6 +613,15 @@ func (b *RaftBackend) applyConfigSettings(config *raft.Config) error {
613613
}
614614
config.TrailingLogs = uint64(trailingLogs)
615615
}
616+
snapshotIntervalRaw, ok := b.conf["snapshot_interval"]
617+
if ok {
618+
var err error
619+
snapshotInterval, err := time.ParseDuration(snapshotIntervalRaw)
620+
if err != nil {
621+
return err
622+
}
623+
config.SnapshotInterval = snapshotInterval
624+
}
616625

617626
config.NoSnapshotRestoreOnStart = true
618627
config.MaxAppendEntries = 64
@@ -681,7 +690,6 @@ func (b *RaftBackend) SetupCluster(ctx context.Context, opts SetupOpts) error {
681690

682691
// Setup the raft config
683692
raftConfig := raft.DefaultConfig()
684-
raftConfig.SnapshotInterval = 5 * time.Second
685693
if err := b.applyConfigSettings(raftConfig); err != nil {
686694
return err
687695
}

vault/external_tests/raft/raft_autopilot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func TestRaft_Autopilot_Stabilization_Delay(t *testing.T) {
225225
"snapshot_threshold": "50",
226226
"trailing_logs": "100",
227227
"autopilot_reconcile_interval": "1s",
228+
"snapshot_interval": "5s",
228229
}
229230
if coreIdx == 2 {
230231
config["snapshot_delay"] = timeToHealthyCore2.String()
@@ -276,7 +277,6 @@ func TestRaft_Autopilot_Stabilization_Delay(t *testing.T) {
276277
{
277278
LeaderAPIAddr: client.Address(),
278279
TLSConfig: cluster.Cores[0].TLSConfig,
279-
Retry: true,
280280
},
281281
}, false)
282282
require.NoError(t, err)

0 commit comments

Comments
 (0)