Skip to content

Commit

Permalink
backupccl: copy spans before SubtractSpans calls
Browse files Browse the repository at this point in the history
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 cockroachdb#122672
Informs cockroachdb#122734
Informs cockroachdb#122754
Informs cockroachdb#122764

Release note: none
  • Loading branch information
msbutler committed Apr 22, 2024
1 parent e006881 commit b037095
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 b037095

Please sign in to comment.