Skip to content

Commit

Permalink
Merge #91186
Browse files Browse the repository at this point in the history
91186: sql: let `extendedEvalContext.QueueJob()` use txn from planner r=ZhouXing19 a=ZhouXing19

This commit is part of the effort to reduce usages of `eval.Context.txn`.

We now let `*kv.Txn` be passed in as a parameter to `extendedEvalContext.QueueJob()`.

Informs: #91004

Release note: None

Co-authored-by: Jane Xing <zhouxing@uchicago.edu>
  • Loading branch information
craig[bot] and ZhouXing19 committed Nov 7, 2022
2 parents f783b08 + d954eac commit 11618b1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
26 changes: 10 additions & 16 deletions pkg/jobs/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2355,14 +2355,11 @@ func TestJobInTxn(t *testing.T) {
}
fn := func(ctx context.Context, _ []sql.PlanNode, _ chan<- tree.Datums) error {
var err error
job, err = execCtx.ExtendedEvalContext().QueueJob(
ctx,
jobs.Record{
Description: st.String(),
Details: jobspb.BackupDetails{},
Progress: jobspb.BackupProgress{},
},
)
job, err = execCtx.ExtendedEvalContext().QueueJob(ctx, execCtx.Txn(), jobs.Record{
Description: st.String(),
Details: jobspb.BackupDetails{},
Progress: jobspb.BackupProgress{},
})
return err
}
return fn, nil, nil, false, nil
Expand Down Expand Up @@ -2397,14 +2394,11 @@ func TestJobInTxn(t *testing.T) {
}
fn := func(ctx context.Context, _ []sql.PlanNode, _ chan<- tree.Datums) error {
var err error
job, err = execCtx.ExtendedEvalContext().QueueJob(
ctx,
jobs.Record{
Description: "RESTORE",
Details: jobspb.RestoreDetails{},
Progress: jobspb.RestoreProgress{},
},
)
job, err = execCtx.ExtendedEvalContext().QueueJob(ctx, execCtx.Txn(), jobs.Record{
Description: "RESTORE",
Details: jobspb.RestoreDetails{},
Progress: jobspb.RestoreProgress{},
})
return err
}
return fn, nil, nil, false, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/drop_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (p *planner) createDropSchemaJob(
typeIDs = append(typeIDs, t.ID)
}

_, err := p.extendedEvalCtx.QueueJob(ctx, jobs.Record{
_, err := p.extendedEvalCtx.QueueJob(ctx, p.Txn(), jobs.Record{
Description: jobDesc,
Username: p.User(),
DescriptorIDs: schemas,
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ func (evalCtx *extendedEvalContext) copy() *extendedEvalContext {
// QueueJob creates a new job from record and queues it for execution after
// the transaction commits.
func (evalCtx *extendedEvalContext) QueueJob(
ctx context.Context, record jobs.Record,
ctx context.Context, txn *kv.Txn, record jobs.Record,
) (*jobs.Job, error) {
jobID := evalCtx.ExecCfg.JobRegistry.MakeJobID()
job, err := evalCtx.ExecCfg.JobRegistry.CreateJobWithTxn(
ctx,
record,
jobID,
evalCtx.Txn,
txn,
)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (p *planner) createDropDatabaseJob(
Progress: jobspb.SchemaChangeProgress{},
NonCancelable: true,
}
newJob, err := p.extendedEvalCtx.QueueJob(ctx, jobRecord)
newJob, err := p.extendedEvalCtx.QueueJob(ctx, p.Txn(), jobRecord)
if err != nil {
return err
}
Expand All @@ -93,7 +93,7 @@ func (p *planner) createNonDropDatabaseChangeJob(
Progress: jobspb.SchemaChangeProgress{},
NonCancelable: true,
}
newJob, err := p.extendedEvalCtx.QueueJob(ctx, jobRecord)
newJob, err := p.extendedEvalCtx.QueueJob(ctx, p.Txn(), jobRecord)
if err != nil {
return err
}
Expand Down

0 comments on commit 11618b1

Please sign in to comment.