Skip to content

Commit 153bcb4

Browse files
craig[bot]railfqazi
committed
148749: ui: bump cluster-ui to 25.3.0-prerelease.0 r=dhartunian a=rail Release note: none Fixes: CC-32804 148761: workload/schemachanger: apply statement_timeout out to CTAS r=fqazi a=fqazi Previously, the schema changer workload never used statement_timeouts since schema changes are normally not predictable operations. However, since we added CREATE TABLE AS support, its possible to have multiple joins where a CREATE TABLE AS can take more then 5 minutes. This patch modifies the operation generator support adding statement timeouts for individual statements. Fixes: #148342 Release note: None Co-authored-by: Rail Aliiev <[email protected]> Co-authored-by: Faizan Qazi <[email protected]>
3 parents f26dd5b + 51599fb + 29dffc3 commit 153bcb4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pkg/ui/workspaces/cluster-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cockroachlabs/cluster-ui",
3-
"version": "25.2.0-prerelease.0",
3+
"version": "25.3.0-prerelease.0",
44
"description": "Cluster UI is a library of large features shared between CockroachDB and CockroachCloud",
55
"repository": {
66
"type": "git",

pkg/workload/schemachange/operation_generator.go

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

14971501
opStmt.sql = fmt.Sprintf(`CREATE TABLE %s AS %s FETCH FIRST %d ROWS ONLY`,
14981502
destTableName, selectStatement.String(), MaxRowsToConsume)
@@ -3172,6 +3176,8 @@ type opStmt struct {
31723176
potentialExecErrors errorCodeSet
31733177
// queryResultCallback handles the results of the query execution.
31743178
queryResultCallback opStmtQueryResultCallback
3179+
// statementTimeout if this statement has a timeout.
3180+
statementTimeout time.Duration
31753181
}
31763182

31773183
// String implements Stringer
@@ -3288,6 +3294,16 @@ func (og *operationGenerator) WrapWithErrorState(err error, op *opStmt) error {
32883294
func (s *opStmt) executeStmt(ctx context.Context, tx pgx.Tx, og *operationGenerator) error {
32893295
var err error
32903296
var rows pgx.Rows
3297+
// Apply any timeout for this statement
3298+
if s.statementTimeout > 0 {
3299+
_, err = tx.Exec(ctx, fmt.Sprintf("SET LOCAL statement_timeout='%s'", s.statementTimeout.String()))
3300+
if err != nil {
3301+
return errors.Mark(
3302+
og.WrapWithErrorState(errors.Wrap(err, "***UNEXPECTED ERROR; Unable to set statement timeout."), s),
3303+
errRunInTxnFatalSentinel,
3304+
)
3305+
}
3306+
}
32913307
// Statement doesn't produce any result set that needs to be validated.
32923308
if s.queryResultCallback == nil {
32933309
_, err = tx.Exec(ctx, s.sql)
@@ -3361,6 +3377,16 @@ func (s *opStmt) executeStmt(ctx context.Context, tx pgx.Tx, og *operationGenera
33613377
return err
33623378
}
33633379
}
3380+
// Reset any timeout for this statement
3381+
if s.statementTimeout > 0 {
3382+
_, err = tx.Exec(ctx, "SET LOCAL statement_timeout=0")
3383+
if err != nil {
3384+
return errors.Mark(
3385+
og.WrapWithErrorState(errors.Wrap(err, "***UNEXPECTED ERROR; Unable to reset statement timeout."), s),
3386+
errRunInTxnFatalSentinel,
3387+
)
3388+
}
3389+
}
33643390
return nil
33653391
}
33663392

0 commit comments

Comments
 (0)