Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
132168:  workload/schemachanger: fix failure in foreign key operation generation r=fqazi a=fqazi

Certain errors were supposed to be ignored when validating foreign keys,
when column types are not comparable. These are meant to be ignored and
when foreign keys refer to the table itself we were also using the wrong
column information when running queries. To address this, the error
detection for foreign key validation has been updated and the correct
column information is passed. This could lead to intermittent failures
in the workload.

Fixes: cockroachdb#131365

Release note: None

Co-authored-by: Faizan Qazi <[email protected]>
  • Loading branch information
craig[bot] and fqazi committed Oct 8, 2024
2 parents d9d2abb + 0661446 commit 8e43568
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pkg/workload/schemachange/error_screening.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,9 @@ SELECT count(*) FROM %s
if err != nil {
rbkErr := joinTx.Rollback(ctx)
// UndefinedFunction errors mean that the column type is not comparable.
if pgErr := new(pgconn.PgError); errors.As(err, &pgErr) && pgcode.MakeCode(pgErr.Code) == pgcode.UndefinedFunction {
if pgErr := new(pgconn.PgError); errors.As(err, &pgErr) &&
((pgcode.MakeCode(pgErr.Code) == pgcode.UndefinedFunction) ||
(pgcode.MakeCode(pgErr.Code) == pgcode.UndefinedColumn)) {
return false, rbkErr
}
return false, errors.WithSecondaryError(err, rbkErr)
Expand Down Expand Up @@ -1196,7 +1198,7 @@ func (og *operationGenerator) violatesFkConstraintsHelper(
for name, idx := range columnNameToIndexMap {
columnsToValues[name] = rowToInsert[idx]
}
parentValueInSameInsert, err = og.generateColumn(ctx, tx, colsInfo[parentColInfo.ordinal], columnsToValues)
parentValueInSameInsert, err = og.generateColumn(ctx, tx, *parentColInfo, columnsToValues)
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (og *operationGenerator) randOp(
if errors.Is(err, ErrSchemaChangesDisallowedDueToPkSwap) {
continue
}
return nil, err
return nil, errors.Wrapf(err, "failed generating operation: %s", op)
}

// Screen for schema change after write in the same transaction.
Expand Down

0 comments on commit 8e43568

Please sign in to comment.