From 0ff9059967aa3fc0f2be0fd46926f9a7f1de5573 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Fri, 9 Jun 2023 14:35:41 -0700 Subject: [PATCH] OSS changes for fixing bug in update-primary (#21119) --- helper/testhelpers/teststorage/teststorage.go | 16 ++++++++++++++++ sdk/physical/latency.go | 3 +++ vault/testing.go | 3 +++ .../system/replication/replication-dr.mdx | 7 ------- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/helper/testhelpers/teststorage/teststorage.go b/helper/testhelpers/teststorage/teststorage.go index a452086488..f065e187d2 100644 --- a/helper/testhelpers/teststorage/teststorage.go +++ b/helper/testhelpers/teststorage/teststorage.go @@ -6,6 +6,7 @@ package teststorage import ( "fmt" "io/ioutil" + "math/rand" "os" "time" @@ -36,6 +37,17 @@ func MakeInmemBackend(t testing.T, logger hclog.Logger) *vault.PhysicalBackendBu } } +func MakeLatentInmemBackend(t testing.T, logger hclog.Logger) *vault.PhysicalBackendBundle { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + jitter := r.Intn(20) + latency := time.Duration(r.Intn(15)) * time.Millisecond + + pbb := MakeInmemBackend(t, logger) + latencyInjector := physical.NewTransactionalLatencyInjector(pbb.Backend, latency, jitter, logger) + pbb.Backend = latencyInjector + return pbb +} + func MakeInmemNonTransactionalBackend(t testing.T, logger hclog.Logger) *vault.PhysicalBackendBundle { inm, err := inmem.NewInmem(nil, logger) if err != nil { @@ -185,6 +197,10 @@ func InmemBackendSetup(conf *vault.CoreConfig, opts *vault.TestClusterOptions) { opts.PhysicalFactory = SharedPhysicalFactory(MakeInmemBackend) } +func InmemLatentBackendSetup(conf *vault.CoreConfig, opts *vault.TestClusterOptions) { + opts.PhysicalFactory = SharedPhysicalFactory(MakeLatentInmemBackend) +} + func InmemNonTransactionalBackendSetup(conf *vault.CoreConfig, opts *vault.TestClusterOptions) { opts.PhysicalFactory = SharedPhysicalFactory(MakeInmemNonTransactionalBackend) } diff --git a/sdk/physical/latency.go b/sdk/physical/latency.go index 82c4052d02..f4cced5270 100644 --- a/sdk/physical/latency.go +++ b/sdk/physical/latency.go @@ -59,6 +59,9 @@ func NewLatencyInjector(b Backend, latency time.Duration, jitter int, logger log } // NewTransactionalLatencyInjector creates a new transactional LatencyInjector +// jitter is the random percent that latency will vary between. +// For example, if you specify latency = 50ms and jitter = 20, then for any +// given operation, the latency will be 50ms +- 10ms (20% of 50), or between 40 and 60ms. func NewTransactionalLatencyInjector(b Backend, latency time.Duration, jitter int, logger log.Logger) *TransactionalLatencyInjector { return &TransactionalLatencyInjector{ LatencyInjector: NewLatencyInjector(b, latency, jitter, logger), diff --git a/vault/testing.go b/vault/testing.go index cca2138c44..375d7f749c 100644 --- a/vault/testing.go +++ b/vault/testing.go @@ -1217,6 +1217,9 @@ type TestClusterOptions struct { // if populated, the callback is called for every request RequestResponseCallback func(logical.Backend, *logical.Request, *logical.Response) + + // ABCDLoggerNames names the loggers according to our ABCD convention when generating 4 clusters + ABCDLoggerNames bool } type TestPluginConfig struct { diff --git a/website/content/api-docs/system/replication/replication-dr.mdx b/website/content/api-docs/system/replication/replication-dr.mdx index bab383d352..cb37e17ded 100644 --- a/website/content/api-docs/system/replication/replication-dr.mdx +++ b/website/content/api-docs/system/replication/replication-dr.mdx @@ -471,13 +471,6 @@ docs](#generate-disaster-recovery-operation-token) for more information. PEM-format files that the secondary can use when unwrapping the token from the primary. If this and ca_file are not given, defaults to system CA roots. -- `update_primary_addrs` `array: []` – List of cluster addresses for potential - primary clusters. These addresses will be pinged in sequence, and if any of them - respond successfully, these will be recorded as the new primary addresses. This is - a lighter weight version of specifying a token and should result in less disruption - of replication. Note that it's invalid to specify this and `token` in the same API call. - They are mutually exclusive. - ### Sample Payload ```json