Skip to content

Commit 5d4bcd5

Browse files
authored
Merge 29dffc3 into blathers/backport-release-25.1-148761
2 parents 6760e97 + 29dffc3 commit 5d4bcd5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pkg/workload/schemachange/operation_generator.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,10 @@ func (og *operationGenerator) createTableAs(ctx context.Context, tx pgx.Tx) (*op
14961496
if opStmt.expectedExecErrors.empty() {
14971497
opStmt.potentialExecErrors.merge(getValidGenerationErrors())
14981498
}
1499+
// Limit any CTAS statements to a maximum time of 1 minute.
1500+
opStmt.statementTimeout = time.Minute
1501+
opStmt.potentialExecErrors.add(pgcode.QueryCanceled)
1502+
og.potentialCommitErrors.add(pgcode.QueryCanceled)
14991503

15001504
opStmt.sql = fmt.Sprintf(`CREATE TABLE %s AS %s FETCH FIRST %d ROWS ONLY`,
15011505
destTableName, selectStatement.String(), MaxRowsToConsume)
@@ -3094,6 +3098,8 @@ type opStmt struct {
30943098
potentialExecErrors errorCodeSet
30953099
// queryResultCallback handles the results of the query execution.
30963100
queryResultCallback opStmtQueryResultCallback
3101+
// statementTimeout if this statement has a timeout.
3102+
statementTimeout time.Duration
30973103
}
30983104

30993105
// String implements Stringer
@@ -3210,6 +3216,16 @@ func (og *operationGenerator) WrapWithErrorState(err error, op *opStmt) error {
32103216
func (s *opStmt) executeStmt(ctx context.Context, tx pgx.Tx, og *operationGenerator) error {
32113217
var err error
32123218
var rows pgx.Rows
3219+
// Apply any timeout for this statement
3220+
if s.statementTimeout > 0 {
3221+
_, err = tx.Exec(ctx, fmt.Sprintf("SET LOCAL statement_timeout='%s'", s.statementTimeout.String()))
3222+
if err != nil {
3223+
return errors.Mark(
3224+
og.WrapWithErrorState(errors.Wrap(err, "***UNEXPECTED ERROR; Unable to set statement timeout."), s),
3225+
errRunInTxnFatalSentinel,
3226+
)
3227+
}
3228+
}
32133229
// Statement doesn't produce any result set that needs to be validated.
32143230
if s.queryResultCallback == nil {
32153231
_, err = tx.Exec(ctx, s.sql)
@@ -3283,6 +3299,16 @@ func (s *opStmt) executeStmt(ctx context.Context, tx pgx.Tx, og *operationGenera
32833299
return err
32843300
}
32853301
}
3302+
// Reset any timeout for this statement
3303+
if s.statementTimeout > 0 {
3304+
_, err = tx.Exec(ctx, "SET LOCAL statement_timeout=0")
3305+
if err != nil {
3306+
return errors.Mark(
3307+
og.WrapWithErrorState(errors.Wrap(err, "***UNEXPECTED ERROR; Unable to reset statement timeout."), s),
3308+
errRunInTxnFatalSentinel,
3309+
)
3310+
}
3311+
}
32863312
return nil
32873313
}
32883314

0 commit comments

Comments
 (0)