Skip to content

Commit

Permalink
workload/schemachange: setColumnType operations will occasionally fail
Browse files Browse the repository at this point in the history
Previously this test would fail due to 0A000 and 2BP01
even though those failures are expected.
In this code changes we properly handle these errors.

Epic: CRDB-25314

Fixes: cockroachdb#66662
Release note: None
  • Loading branch information
Dedej-Bergin committed Oct 21, 2024
1 parent 7d5fd97 commit 92c79e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2515,25 +2515,33 @@ func (og *operationGenerator) setColumnType(ctx context.Context, tx pgx.Tx) (*op
return nil, err
}

colIsRefByComputed, err := og.colIsRefByComputed(ctx, tx, tableName, columnForTypeChange.name)
if err != nil {
return nil, err
}

stmt := makeOpStmt(OpStmtDDL)
if newType != nil {
// Ignoring the error here intentionally, as we want to carry on with
// the operation and not fail it prematurely.
kind, _ := schemachange.ClassifyConversion(context.Background(), columnForTypeChange.typ, newType)
stmt.expectedExecErrors.addAll(codesWithConditions{
{code: pgcode.CannotCoerce, condition: kind == schemachange.ColumnConversionImpossible},
{code: pgcode.FeatureNotSupported, condition: kind != schemachange.ColumnConversionTrivial},
})
stmt.potentialExecErrors.add(pgcode.FeatureNotSupported)
}

stmt.expectedExecErrors.addAll(codesWithConditions{
{code: pgcode.UndefinedObject, condition: newType == nil},
{code: pgcode.DependentObjectsStillExist, condition: columnHasDependencies},
{code: pgcode.DependentObjectsStillExist, condition: columnHasDependencies || colIsRefByComputed},
})

stmt.potentialExecErrors.add(pgcode.DependentObjectsStillExist)

stmt.sql = fmt.Sprintf(`%s ALTER TABLE %s ALTER COLUMN %s SET DATA TYPE %s`,
setSessionVariableString, tableName.String(), columnForTypeChange.name.String(), newTypeName.SQLString())
return stmt, nil

}

func (og *operationGenerator) alterTableAlterPrimaryKey(
Expand Down
2 changes: 1 addition & 1 deletion pkg/workload/schemachange/optype.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ var opWeights = []int{
alterTableAddColumn: 1,
alterTableAddConstraintForeignKey: 1,
alterTableAddConstraintUnique: 1,
alterTableAlterColumnType: 0, // Disabled and tracked with #66662.
alterTableAlterColumnType: 1,
alterTableAlterPrimaryKey: 1,
alterTableDropColumn: 1,
alterTableDropColumnDefault: 1,
Expand Down

0 comments on commit 92c79e1

Please sign in to comment.