From b94d02e109a9204aef6bff89fed9785568245a0f Mon Sep 17 00:00:00 2001 From: Rafi Shamim Date: Fri, 3 Oct 2025 15:07:32 -0400 Subject: [PATCH] sql: display notice with job ID when waiting for a job This will allow users to easily see the job ID in case they'd like to look at more details about the job in other introspection interfaces. Release note: None --- pkg/sql/conn_executor.go | 14 ++++++++++++++ pkg/sql/run_control_test.go | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/sql/conn_executor.go b/pkg/sql/conn_executor.go index e6365e2821dd..d3817d307062 100644 --- a/pkg/sql/conn_executor.go +++ b/pkg/sql/conn_executor.go @@ -11,6 +11,7 @@ import ( "io" "math" "math/rand" + "strconv" "strings" "sync/atomic" "time" @@ -4237,6 +4238,19 @@ func (ex *connExecutor) waitForTxnJobs() error { } } if !queryTimedout.Load() && len(ex.extraTxnState.jobs.created) > 0 { + + noticeMsg := strings.Builder{} + noticeMsg.WriteString("waiting for job(s) to complete: ") + for i, jobID := range ex.extraTxnState.jobs.created { + if i > 0 { + noticeMsg.WriteString(", ") + } + noticeMsg.WriteString(strconv.Itoa(int(jobID))) + } + if err := ex.planner.SendClientNotice(ex.Ctx(), pgnotice.Newf(noticeMsg.String()), true /* immediateFlush */); err != nil { + return err + } + if err := ex.server.cfg.JobRegistry.WaitForJobs(jobWaitCtx, ex.extraTxnState.jobs.created); err != nil { if errors.Is(err, context.Canceled) && queryTimedout.Load() { diff --git a/pkg/sql/run_control_test.go b/pkg/sql/run_control_test.go index b99249f45c01..3321c90da2e2 100644 --- a/pkg/sql/run_control_test.go +++ b/pkg/sql/run_control_test.go @@ -1153,10 +1153,11 @@ func TestStatementTimeoutForSchemaChangeCommit(t *testing.T) { if implicitTxn { _, err := conn.DB.ExecContext(ctx, "ALTER TABLE t1 ADD COLUMN j INT DEFAULT 32") require.ErrorContains(t, err, sqlerrors.QueryTimeoutError.Error()) - require.Equal(t, 1, len(actualNotices)) + require.Equal(t, 2, len(actualNotices)) + require.Regexp(t, "waiting for job\\(s\\) to complete: \\d+", actualNotices[0]) require.Regexp(t, "The statement has timed out, but the following background jobs have been created and will continue running: \\d+", - actualNotices[0]) + actualNotices[1]) } else { txn := conn.Begin(t) _, err := txn.Exec("SET LOCAL autocommit_before_ddl=off")