Expose snapshot_interval tunable instead of setting it in prod code for the sake of a test. (#11160)

This commit is contained in:
Nick Cabatoff 2021-03-19 15:41:42 -04:00 committed by GitHub
parent 985fa230ce
commit b3af58d758
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -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
}

View File

@ -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)