Skip to content

Commit

Permalink
backupccl: enable running BACKUP in a tenant
Browse files Browse the repository at this point in the history
The eliminates the last dependency on gossip or unsupported kv features
in the BACKUP planning and job. However the actual export of data, using
ExportRequest, will still fail and cause the backup to fail as the prior
commit disallows ExportRequests from contacting external storage for tenants.

A follow-up change will be required to do those uploads in the processor instead.

Release note: none.
  • Loading branch information
dt committed Dec 2, 2020
1 parent 7885a4e commit 35b36da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
27 changes: 17 additions & 10 deletions pkg/ccl/backupccl/backup_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,22 @@ func backup(
var lastCheckpoint time.Time

var ranges []roachpb.RangeDescriptor
if err := db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
var err error
// TODO(benesch): limit the range descriptors we fetch to the ranges that
// are actually relevant in the backup to speed up small backups on large
// clusters.
ranges, err = allRangeDescriptors(ctx, txn)
return err
}); err != nil {
return RowCount{}, err

// TODO(dt): we should really get a RangeDescriptor iterator and do this the
// right way, just iterate the spans we need, in a tenant or not. For now
// though tenants aren't allowed to just go read all ranges so we'll skip this
// and let distsender just split our ExportRequest for us.
if execCtx.ExecCfg().Codec.ForSystemTenant() {
if err := db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
var err error
// TODO(benesch): limit the range descriptors we fetch to the ranges that
// are actually relevant in the backup to speed up small backups on large
// clusters.
ranges, err = allRangeDescriptors(ctx, txn)
return err
}); err != nil {
return RowCount{}, err
}
}

var completedSpans, completedIntroducedSpans []roachpb.Span
Expand Down Expand Up @@ -499,7 +506,7 @@ func (b *backupResumer) Resume(

numClusterNodes, err := clusterNodeCount(p.ExecCfg().Gossip)
if err != nil {
if !build.IsRelease() {
if !build.IsRelease() && p.ExecCfg().Codec.ForSystemTenant() {
return err
}
log.Warningf(ctx, "unable to determine cluster node count: %v", err)
Expand Down
7 changes: 6 additions & 1 deletion pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6124,6 +6124,11 @@ func TestBackupRestoreTenant(t *testing.T) {
systemDB.Exec(t, `BACKUP TENANT 11 TO 'nodelocal://1/t11'`)
systemDB.Exec(t, `BACKUP TENANT 20 TO 'nodelocal://1/t20'`)

t.Run("inside-tenant", func(t *testing.T) {
skip.WithIssue(t, 57317)
tenant10.Exec(t, `BACKUP DATABASE foo TO 'userfile://defaultdb.myfililes/test'`)
})

t.Run("non-existent", func(t *testing.T) {
systemDB.ExpectErr(t, "tenant 123 does not exist", `BACKUP TENANT 123 TO 'nodelocal://1/t1'`)
systemDB.ExpectErr(t, "tenant 21 does not exist", `BACKUP TENANT 21 TO 'nodelocal://1/t20'`)
Expand Down Expand Up @@ -7087,7 +7092,7 @@ schema_name`
sqlDBRestore.CheckQueryResults(t, checkSchemasQuery,
[][]string{{"pg_temp_0_0"}, {"pg_temp_0_1"}, {"pg_temp_0_2"}, {"pg_temp_0_3"}})

checkTempTablesQuery := `SELECT schema_name,
checkTempTablesQuery := `SELECT schema_name,
table_name FROM [SHOW TABLES] ORDER BY schema_name, table_name`
sqlDBRestore.CheckQueryResults(t, checkTempTablesQuery, [][]string{{"pg_temp_0_0", "t"},
{"pg_temp_0_1", "t"}, {"pg_temp_0_2", "t"}, {"pg_temp_0_3", "t"}})
Expand Down

0 comments on commit 35b36da

Please sign in to comment.