diff --git a/pkg/ccl/backupccl/backup_job.go b/pkg/ccl/backupccl/backup_job.go index bbf8af881590..e836f3f94756 100644 --- a/pkg/ccl/backupccl/backup_job.go +++ b/pkg/ccl/backupccl/backup_job.go @@ -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 @@ -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) diff --git a/pkg/ccl/backupccl/backup_test.go b/pkg/ccl/backupccl/backup_test.go index 66e4765f9d54..d690c7466793 100644 --- a/pkg/ccl/backupccl/backup_test.go +++ b/pkg/ccl/backupccl/backup_test.go @@ -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'`) @@ -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"}})