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

backup: split request spans to be range sized #114268

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
77 changes: 56 additions & 21 deletions pkg/ccl/backupccl/backup_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ var (
settings.WithName("bulkio.backup.split_keys_on_timestamps.enabled"),
)

preSplitExports = settings.RegisterBoolSetting(
settings.ApplicationLevel,
"bulkio.backup.presplit_request_spans.enabled",
"split the spans that will be requests before requesting them",
util.ConstantWithMetamorphicTestBool("backup-presplit-spans", true),
)

sendExportRequestWithVerboseTracing = settings.RegisterBoolSetting(
settings.ApplicationLevel,
"bulkio.backup.export_request_verbose_tracing",
Expand Down Expand Up @@ -284,13 +291,12 @@ func (bp *backupDataProcessor) ConsumerClosed() {
}

type spanAndTime struct {
// spanIdx is a unique identifier of this object.
spanIdx int
span roachpb.Span
firstKeyTS hlc.Timestamp
start, end hlc.Timestamp
attempts int
lastTried time.Time
span roachpb.Span
firstKeyTS hlc.Timestamp
start, end hlc.Timestamp
attempts int
lastTried time.Time
finishesSpec bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we add a comment above this new field, its not immediately obvious how it influences progress reporting

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll get this in a followup instead of eating a ci for a comment.

}

type exportedSpan struct {
Expand All @@ -312,21 +318,50 @@ func runBackupProcessor(
clusterSettings := flowCtx.Cfg.Settings

totalSpans := len(spec.Spans) + len(spec.IntroducedSpans)
todo := make(chan spanAndTime, totalSpans)
var spanIdx int
for _, s := range spec.IntroducedSpans {
todo <- spanAndTime{
spanIdx: spanIdx, span: s, firstKeyTS: hlc.Timestamp{}, start: hlc.Timestamp{},
end: spec.BackupStartTime,
requestSpans := make([]spanAndTime, 0, totalSpans)
rangeSizedSpans := preSplitExports.Get(&flowCtx.EvalCtx.Settings.SV)

splitSpans := func(spans []roachpb.Span, start, end hlc.Timestamp) error {
for _, fullSpan := range spans {
remainingSpan := fullSpan

if rangeSizedSpans {
rdi, err := flowCtx.Cfg.ExecutorConfig.(*sql.ExecutorConfig).RangeDescIteratorFactory.NewIterator(ctx, fullSpan)
if err != nil {
return err
}
for ; rdi.Valid(); rdi.Next() {
rangeDesc := rdi.CurRangeDescriptor()
rangeSpan := roachpb.Span{Key: rangeDesc.StartKey.AsRawKey(), EndKey: rangeDesc.EndKey.AsRawKey()}
subspan := remainingSpan.Intersect(rangeSpan)
if !subspan.Valid() {
return errors.AssertionFailedf("%s not in %s of %s", rangeSpan, remainingSpan, fullSpan)
}
requestSpans = append(requestSpans, spanAndTime{span: subspan, start: start, end: end})
remainingSpan.Key = subspan.EndKey
}
}

if remainingSpan.Valid() {
requestSpans = append(requestSpans, spanAndTime{span: remainingSpan, start: start, end: end})
}
requestSpans[len(requestSpans)-1].finishesSpec = true
}
spanIdx++
return nil
}
for _, s := range spec.Spans {
todo <- spanAndTime{
spanIdx: spanIdx, span: s, firstKeyTS: hlc.Timestamp{}, start: spec.BackupStartTime,
end: spec.BackupEndTime,
}
spanIdx++

if err := splitSpans(spec.IntroducedSpans, hlc.Timestamp{}, spec.BackupStartTime); err != nil {
return err
}
if err := splitSpans(spec.Spans, spec.BackupStartTime, spec.BackupEndTime); err != nil {
return err
}

log.Infof(ctx, "backup processor is assigned %d spans covering %d ranges", totalSpans, len(requestSpans))
dt marked this conversation as resolved.
Show resolved Hide resolved

todo := make(chan spanAndTime, len(requestSpans))
for i := range requestSpans {
todo <- requestSpans[i]
}

destURI := spec.DefaultURI
Expand Down Expand Up @@ -575,7 +610,7 @@ func runBackupProcessor(
}

var completedSpans int32
if resp.ResumeSpan == nil {
if span.finishesSpec && resp.ResumeSpan == nil {
completedSpans = 1
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11194,7 +11194,7 @@ func TestRestoreMemoryMonitoringWithShadowing(t *testing.T) {
sqlDB.Exec(t, "CREATE DATABASE data2")
sqlDB.Exec(t, "RESTORE data.bank FROM latest IN 'userfile:///backup' WITH OPTIONS (into_db='data2')")
files := sqlDB.QueryStr(t, "SHOW BACKUP FILES FROM latest IN 'userfile:///backup'")
require.Equal(t, 11, len(files)) // 1 file for full + 10 for 10 incrementals
require.GreaterOrEqual(t, len(files), 11) // 1 file for full + 10 for 10 incrementals

// Assert that the restore processor is processing the same span multiple
// times, and the count is based on what's expected from the memory budget.
Expand Down