Skip to content

Commit

Permalink
Merge #122819
Browse files Browse the repository at this point in the history
122819: backupccl: copy spans before SubtractSpans calls r=dt a=msbutler

Previously, backup assumed arguments to roachpb.SubtractSpans could be used, but the first arg is modified in place. This patch adds a wrapper to roachpb.SubtractSpans to copy the input spans before use.

Informs #122672
Informs #122734
Informs #122754
Informs #122764

Release note: none

Co-authored-by: Michael Butler <[email protected]>
  • Loading branch information
craig[bot] and msbutler committed Apr 22, 2024
2 parents 1aabfdd + b037095 commit d679773
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/ccl/backupccl/backup_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ func backup(
}

// Subtract out any completed spans.
spans := roachpb.SubtractSpans(backupManifest.Spans, completedSpans)
introducedSpans := roachpb.SubtractSpans(backupManifest.IntroducedSpans, completedIntroducedSpans)
spans := roachpb.SubtractSpansWithCopy(backupManifest.Spans, completedSpans)
introducedSpans := roachpb.SubtractSpansWithCopy(backupManifest.IntroducedSpans, completedIntroducedSpans)

pkIDs := make(map[uint64]bool)
for i := range backupManifest.Descriptors {
Expand Down Expand Up @@ -1649,7 +1649,7 @@ func createBackupManifest(
}
}

newSpans = roachpb.SubtractSpans(spans, prevBackups[len(prevBackups)-1].Spans)
newSpans = roachpb.SubtractSpansWithCopy(spans, prevBackups[len(prevBackups)-1].Spans)
}

// if CompleteDbs is lost by a 1.x node, FormatDescriptorTrackingVersion
Expand Down
10 changes: 10 additions & 0 deletions pkg/roachpb/merge_spans.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ func MergeSpans(spans *[]Span) ([]Span, bool) {
return r, distinct
}

// SubtractSpansWithCopy is the same thing as Subtract spans, but copies the
// todo span first so it can be used after this function call.
func SubtractSpansWithCopy(todo, done Spans) Spans {
newTodo := make(Spans, 0, len(todo))
for i := range todo {
newTodo = append(newTodo, todo[i].Clone())
}
return SubtractSpans(newTodo, done)
}

// SubtractSpans subtracts the subspans covered by a set of non-overlapping
// spans from another set of non-overlapping spans.
//
Expand Down

0 comments on commit d679773

Please sign in to comment.