Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"math"
"math/rand"
"strconv"
"strings"
"sync/atomic"
"time"
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/run_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading