Skip to content

Commit

Permalink
sql: fix small race in distIndexBackfiller
Browse files Browse the repository at this point in the history
This fixes a small race condition in
distIndexBackfiller. updateJobDetails calls SetResumeSpansInJob which
mutates the ResumeSpanList in the job details.  Normally, this is only
called from the periodic updater.  However, when the testing knob
AlwasyUpdateIndexBackfillDetails is set, we also update it on every
ProducerMetadata message we get back

Release note: None
  • Loading branch information
stevendanna committed Feb 2, 2022
1 parent 0e5eb08 commit 4969711
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/sql/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,16 @@ func (sc *SchemaChanger) distIndexBackfill(
})
}

// updateJobMu ensures only one goroutine is calling
// updateJobDetails at a time to avoid a data race in
// SetResumeSpansInJob. This mutex should be uncontended when
// sc.testingKnobs.AlwaysUpdateIndexBackfillDetails is false.
var updateJobMu syncutil.Mutex
updateJobDetails = func() error {
updatedTodoSpans := getTodoSpansForUpdate()
return sc.db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
updateJobMu.Lock()
defer updateJobMu.Unlock()
// No processor has returned completed spans yet.
if updatedTodoSpans == nil {
return nil
Expand Down

0 comments on commit 4969711

Please sign in to comment.