Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: fix bug whereby backfiller would drop spans on txn restart #54755

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/sql/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,10 @@ func (sc *SchemaChanger) distBackfill(

for len(todoSpans) > 0 {
log.VEventf(ctx, 2, "backfill: process %+v spans", todoSpans)
// Make sure not to update todoSpans inside the transaction closure as it
// may not commit. Instead write the updated value for todoSpans to this
// variable and assign to todoSpans after committing.
var updatedTodoSpans []roachpb.Span
if err := sc.db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
// Report schema change progress. We define progress at this point
// as the the fraction of fully-backfilled ranges of the primary index of
Expand Down Expand Up @@ -984,7 +988,7 @@ func (sc *SchemaChanger) distBackfill(
}
metaFn := func(_ context.Context, meta *execinfrapb.ProducerMetadata) error {
if meta.BulkProcessorProgress != nil {
todoSpans = roachpb.SubtractSpans(todoSpans,
updatedTodoSpans = roachpb.SubtractSpans(todoSpans,
meta.BulkProcessorProgress.CompletedSpans)
}
return nil
Expand Down Expand Up @@ -1021,6 +1025,8 @@ func (sc *SchemaChanger) distBackfill(
}); err != nil {
return err
}
todoSpans = updatedTodoSpans

if !inMemoryStatusEnabled {
var resumeSpans []roachpb.Span
// There is a worker node of older version that will communicate
Expand All @@ -1037,7 +1043,6 @@ func (sc *SchemaChanger) distBackfill(
}
// A \intersect B = A - (A - B)
todoSpans = roachpb.SubtractSpans(todoSpans, roachpb.SubtractSpans(todoSpans, resumeSpans))

}
// Record what is left to do for the job.
// TODO(spaskob): Execute this at a regular cadence.
Expand Down