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

backupccl: fix bug where restore would try to start rolled-back jobs #56021

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Changes from all commits
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
8 changes: 7 additions & 1 deletion pkg/ccl/backupccl/restore_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,11 @@ func (r *restoreResumer) publishTables(ctx context.Context) error {

newSchemaChangeJobs := make([]*jobs.StartableJob, 0)
err := r.execCfg.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
// createdSchemaChangeJobs is scoped inside this callback so that the
// callback remains idempotent. It needs to be idempotent since the
// transaction that we're in could be retried. In particular, we want to
// avoid reading any writes to external state (e.g. newSchemaChangeJobs).
createdSchemaChangeJobs := make([]*jobs.StartableJob, 0)
// Write the new TableDescriptors and flip state over to public so they can be
// accessed.
b := txn.NewBatch()
Expand All @@ -1104,7 +1109,7 @@ func (r *restoreResumer) publishTables(ctx context.Context) error {
if err != nil {
return err
}
newSchemaChangeJobs = append(newSchemaChangeJobs, newJobs...)
createdSchemaChangeJobs = append(createdSchemaChangeJobs, newJobs...)
existingDescVal, err := sqlbase.ConditionalGetTableDescFromTxn(ctx, txn, tbl)
if err != nil {
return errors.Wrapf(err, "validating table descriptor has not changed, expected: %v", tbl)
Expand All @@ -1115,6 +1120,7 @@ func (r *restoreResumer) publishTables(ctx context.Context) error {
existingDescVal,
)
newTables = append(newTables, &tableDesc)
newSchemaChangeJobs = createdSchemaChangeJobs
}

if err := txn.Run(ctx, b); err != nil {
Expand Down