Skip to content

Commit

Permalink
Merge #26452
Browse files Browse the repository at this point in the history
26452: importccl: make spans overlap during IMPORT with transform r=mjibson a=mjibson

Force the backup descriptor spans to overlap correctly. This prevents
various extra ranges from being created during RESTORE of data created
with IMPORT with transform. The IMPORT commands will need to be re-run
to generate correct spans in the descriptors.

Fixes #26375

Release note: None

Co-authored-by: Matt Jibson <[email protected]>
  • Loading branch information
craig[bot] and maddyblue committed Jun 7, 2018
2 parents 80ab908 + 9d28c33 commit d972ce1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
17 changes: 17 additions & 0 deletions pkg/ccl/importccl/import_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,23 @@ func doDistributedCSVTransform(
})
}

// The returned spans are from the SSTs themselves, and so don't perfectly
// overlap. Sort the files so we can fix the spans to be correctly
// overlapping. This is needed because RESTORE splits at both the start
// and end of each SST, and so there are tiny ranges (like {NULL-/0/0} at
// the start) that get created. During non-transform IMPORT this isn't a
// problem because it only splits on the end key. Replicate that behavior
// here by copying the end key from each span to the start key of the next.
sort.Slice(backupDesc.Files, func(i, j int) bool {
return backupDesc.Files[i].Span.Key.Compare(backupDesc.Files[j].Span.Key) < 0
})
tableSpan := tableDesc.TableSpan()
backupDesc.Files[0].Span.Key = tableSpan.Key
for i := 1; i < len(backupDesc.Files); i++ {
backupDesc.Files[i].Span.Key = backupDesc.Files[i-1].Span.EndKey
}
backupDesc.Files[len(backupDesc.Files)-1].Span.EndKey = tableSpan.EndKey

dest, err := storageccl.ExportStorageConfFromURI(transformOnly)
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions pkg/ccl/importccl/import_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@ func TestImportCSVStmt(t *testing.T) {
t.Fatal("expected > 1 SST files")
}
}

// Verify spans don't have trailing '/0'.
ranges := sqlDB.QueryStr(t, `SHOW testing_ranges FROM TABLE t`)
for _, r := range ranges {
const end = `/0`
if strings.HasSuffix(r[0], end) || strings.HasSuffix(r[1], end) {
t.Errorf("bad span: %s - %s", r[0], r[1])
}
}
})
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/ccl/importccl/sst_writer_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ func (sp *sstWriter) Run(ctx context.Context, wg *sync.WaitGroup) {
if chunk > 0 {
name = fmt.Sprintf("%d-%s", chunk, name)
}
end := span.End
if sst.more {
end = sst.span.EndKey
}

if sp.spec.Destination == "" {
end := span.End
if sst.more {
end = sst.span.EndKey
}
if err := sp.db.AdminSplit(ctx, end, end); err != nil {
return err
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func (sp *sstWriter) Run(ctx context.Context, wg *sync.WaitGroup) {
),
sqlbase.DatumToEncDatum(
sqlbase.ColumnType{SemanticType: sqlbase.ColumnType_BYTES},
tree.NewDBytes(tree.DBytes(sst.span.EndKey)),
tree.NewDBytes(tree.DBytes(end)),
),
}
cs, err := sp.out.EmitRow(ctx, row)
Expand Down

0 comments on commit d972ce1

Please sign in to comment.