Skip to content

Commit

Permalink
Merge pull request #91522 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…22.2-91163

release-22.2: workload/schemachange: fixes to improve stability of the test
  • Loading branch information
fqazi authored Nov 9, 2022
2 parents 5622864 + 009656c commit f69cb17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
43 changes: 14 additions & 29 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func init() {
var opWeights = []int{
addColumn: 1,
addConstraint: 0, // TODO(spaskob): unimplemented
addForeignKeyConstraint: 1,
addForeignKeyConstraint: 0, // Disabled and tracked with #91195
addRegion: 1,
addUniqueConstraint: 0,
alterTableLocality: 1,
Expand Down Expand Up @@ -2992,41 +2992,23 @@ func (og *operationGenerator) randParentColumnForFkRelation(
var typName string
var nullable string

for {
nestedTxn, err := tx.Begin(ctx)
if err != nil {
return nil, nil, err
}
err = nestedTxn.QueryRow(ctx, fmt.Sprintf(`
nestedTxn, err := tx.Begin(ctx)
if err != nil {
return nil, nil, err
}
err = nestedTxn.QueryRow(ctx, fmt.Sprintf(`
SELECT table_schema, table_name, column_name, crdb_sql_type, is_nullable FROM (
%s
)`, subQuery.String())).Scan(&tableSchema, &tableName, &columnName, &typName, &nullable)
if err == nil {
err := nestedTxn.Commit(ctx)
if err != nil {
return nil, nil, err
}
break
}
pgErr := (*pgconn.PgError)(nil)
if !errors.As(err, &pgErr) {
return nil, nil, err
}
// Intermittent undefined table errors are valid for the query above, since
// we are not leasing out the tables, when picking our random table.
if code := pgcode.MakeCode(pgErr.Code); code == pgcode.UndefinedTable ||
code == pgcode.UndefinedSchema {
err := nestedTxn.Rollback(ctx)
if err != nil {
return nil, nil, err
}
continue
}
if err != nil {
if rbErr := nestedTxn.Rollback(ctx); rbErr != nil {
err = errors.CombineErrors(err, rbErr)
}
return nil, nil, err
}
if err = nestedTxn.Commit(ctx); err != nil {
return nil, nil, err
}

columnToReturn := column{
name: columnName,
Expand All @@ -3037,7 +3019,6 @@ func (og *operationGenerator) randParentColumnForFkRelation(
ExplicitSchema: true,
}, tree.Name(tableName))

var err error
columnToReturn.typ, err = og.typeFromTypeName(ctx, tx, typName)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -3566,6 +3547,10 @@ func (og *operationGenerator) selectStmt(ctx context.Context, tx pgx.Tx) (stmt *
// TODO(fqazi): Temporarily allow out of memory errors on select queries. Not
// sure where we are hitting these, need to investigate further.
stmt.potentialExecErrors.add(pgcode.OutOfMemory)
// Disk errors can happen since there are limits on spill, and cross
// joins which are deep cannot do much of the FETCH FIRST X ROWS ONLY
// limit
stmt.potentialExecErrors.add(pgcode.DiskFull)
return stmt, nil
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/workload/schemachange/watch_dog.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package schemachange

import (
"context"
gosql "database/sql"
"fmt"
"time"

Expand All @@ -31,9 +32,9 @@ type schemaChangeWatchDog struct {
// cmdChannel used to communicate from thread executing commands on the session.
cmdChannel chan chan struct{}
// activeQuery last active query observed on the monitored connection.
activeQuery string
activeQuery gosql.NullString
// txnID last active transaction ID observed on the target connection.
txnID string
txnID gosql.NullString
// numRetries number of transaction retries observed.
numRetries int
}
Expand Down Expand Up @@ -137,8 +138,8 @@ func (w *schemaChangeWatchDog) Start(ctx context.Context, tx pgx.Tx) error {
// reset prepares the watch dog for re-use.
func (w *schemaChangeWatchDog) reset() {
w.sessionID = ""
w.activeQuery = ""
w.txnID = ""
w.activeQuery = gosql.NullString{}
w.txnID = gosql.NullString{}
}

// Stop stops monitoring the connection and waits for the watch dog thread to
Expand Down

0 comments on commit f69cb17

Please sign in to comment.