Skip to content

Commit

Permalink
spanconfig: squash benign data race
Browse files Browse the repository at this point in the history
Fixes #75849.

Release note: None
  • Loading branch information
irfansharif committed Feb 12, 2022
1 parent a8acd95 commit f82ce57
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/migration/migrations/migrate_span_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/server"
"github.com/cockroachdb/cockroach/pkg/spanconfig"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
Expand All @@ -33,7 +32,6 @@ import (
// span config reconciliation attempt, blocking until it occurs.
func TestEnsureSpanConfigReconciliation(t *testing.T) {
defer leaktest.AfterTest(t)()
skip.WithIssue(t, 75849, "flaky test")
defer log.Scope(t).Close(t)

ctx := context.Background()
Expand Down Expand Up @@ -99,6 +97,8 @@ func TestEnsureSpanConfigReconciliation(t *testing.T) {
}
}

// TestEnsureSpanConfigReconciliationMultiNode verifies that the span config
// reconciliation migration works in a multi-node setting.
func TestEnsureSpanConfigReconciliationMultiNode(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
Expand Down
1 change: 1 addition & 0 deletions pkg/spanconfig/spanconfigjob/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//pkg/util/hlc",
"//pkg/util/log",
"//pkg/util/retry",
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"@com_github_cockroachdb_errors//:errors",
],
Expand Down
24 changes: 18 additions & 6 deletions pkg/spanconfig/spanconfigjob/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/errors"
)
Expand Down Expand Up @@ -91,18 +92,25 @@ func (r *resumer) Resume(ctx context.Context, execCtxI interface{}) (jobErr erro
// timestamp.

settingValues := &execCtx.ExecCfg().Settings.SV
persistCheckpoints := util.Every(reconciliationJobCheckpointInterval.Get(settingValues))
persistCheckpointsMu := struct {
syncutil.Mutex
util.EveryN
}{}
persistCheckpointsMu.EveryN = util.Every(reconciliationJobCheckpointInterval.Get(settingValues))

reconciliationJobCheckpointInterval.SetOnChange(settingValues, func(ctx context.Context) {
persistCheckpoints = util.Every(reconciliationJobCheckpointInterval.Get(settingValues))
persistCheckpointsMu.Lock()
defer persistCheckpointsMu.Unlock()
persistCheckpointsMu.EveryN = util.Every(reconciliationJobCheckpointInterval.Get(settingValues))
})

shouldPersistCheckpoint := true
checkpointingDisabled := false
shouldSkipRetry := false
var onCheckpointInterceptor func() error

if knobs := execCtx.ExecCfg().SpanConfigTestingKnobs; knobs != nil {
if knobs.JobDisablePersistingCheckpoints {
shouldPersistCheckpoint = false
checkpointingDisabled = true
}
shouldSkipRetry = knobs.JobDisableInternalRetry
onCheckpointInterceptor = knobs.JobOnCheckpointInterceptor
Expand All @@ -125,10 +133,14 @@ func (r *resumer) Resume(ctx context.Context, execCtxI interface{}) (jobErr erro
}
}

if !shouldPersistCheckpoint {
if checkpointingDisabled {
return nil
}
if !persistCheckpoints.ShouldProcess(timeutil.Now()) {

persistCheckpointsMu.Lock()
shouldPersistCheckpoint := persistCheckpointsMu.ShouldProcess(timeutil.Now())
persistCheckpointsMu.Unlock()
if !shouldPersistCheckpoint {
return nil
}

Expand Down

0 comments on commit f82ce57

Please sign in to comment.