Skip to content

Commit

Permalink
Extract replication state before go routine for initQueue (#11161) (#…
Browse files Browse the repository at this point in the history
…12603)

Querying the state before launching the go routine avoids a possible
race condition with replication.

Co-authored-by: Clint <catsby@users.noreply.github.com>
  • Loading branch information
calvn and catsby committed Sep 22, 2021
1 parent 0de5cbb commit a1e06bc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion builtin/logical/database/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend,
ictx, cancel := context.WithCancel(initCtx)
b.cancelQueue = cancel
// Load queue and kickoff new periodic ticker
go b.initQueue(ictx, conf)
go b.initQueue(ictx, conf, conf.System.ReplicationState())
return b, nil
}

Expand Down
3 changes: 1 addition & 2 deletions builtin/logical/database/rotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,11 @@ func (b *databaseBackend) setStaticAccount(ctx context.Context, s logical.Storag
// not wait for success or failure of it's tasks before continuing. This is to
// avoid blocking the mount process while loading and evaluating existing roles,
// etc.
func (b *databaseBackend) initQueue(ctx context.Context, conf *logical.BackendConfig) {
func (b *databaseBackend) initQueue(ctx context.Context, conf *logical.BackendConfig, replicationState consts.ReplicationState) {
// Verify this mount is on the primary server, or is a local mount. If not, do
// not create a queue or launch a ticker. Both processing the WAL list and
// populating the queue are done sequentially and before launching a
// go-routine to run the periodic ticker.
replicationState := conf.System.ReplicationState()
if (conf.System.LocalMount() || !replicationState.HasState(consts.ReplicationPerformanceSecondary)) &&
!replicationState.HasState(consts.ReplicationDRSecondary) &&
!replicationState.HasState(consts.ReplicationPerformanceStandby) {
Expand Down

0 comments on commit a1e06bc

Please sign in to comment.