Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
128939: sql: fix TestRandomSyntaxSchemaChangeDatabase flake r=fqazi a=fqazi

Previously, TestRandomSyntaxSchemaChangeDatabase could flake because of contention from multiple Go routines executing SQL against the same database. Some of these schema changes were long-running, making this test unreliable. To address this, this patch creates multiple databases, so that every two connections will share the same database.

Fixes: cockroachdb#128287

Release note: None

128961: roachtest: online restore with unsafe_incompatible_version r=stevendanna a=msbutler

Fixes cockroachdb#128884

Release note: none

Co-authored-by: Faizan Qazi <[email protected]>
Co-authored-by: Michael Butler <[email protected]>
  • Loading branch information
3 people committed Aug 14, 2024
3 parents aa21162 + 9e25799 + 3b43ad5 commit b4a9870
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/roachtest/tests/online_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@ func runRestore(
}

}
opts := ""
opts := "WITH unsafe_restore_incompatible_version"
if runOnline {
opts = "WITH EXPERIMENTAL DEFERRED COPY"
opts = "WITH EXPERIMENTAL DEFERRED COPY, unsafe_restore_incompatible_version"
}
if err := maybeAddSomeEmptyTables(ctx, rd); err != nil {
return errors.Wrapf(err, "failed to add some empty tables")
Expand Down
21 changes: 18 additions & 3 deletions pkg/sql/tests/rsg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"regexp"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -511,16 +512,30 @@ func TestRandomSyntaxSchemaChangeDatabase(t *testing.T) {
"drop_user_stmt",
"alter_user_stmt",
}

// Create multiple databases, so that in concurrent scenarios two connections
// will always share the same database.
numDatabases := max(*flagRSGGoRoutines/2, 1)
databases := make([]string, 0, numDatabases)
for dbIdx := 0; dbIdx < numDatabases; dbIdx++ {
databases = append(databases, fmt.Sprintf("ident_%d", dbIdx))
}
var nextDatabaseName atomic.Int64
testRandomSyntax(t, true, "ident", func(ctx context.Context, db *verifyFormatDB, r *rsg.RSG) error {
if err := db.exec(t, ctx, "SET CLUSTER SETTING sql.catalog.descriptor_lease_duration = '30s'"); err != nil {
return err
}
return db.exec(t, ctx, `CREATE DATABASE ident;`)
for _, dbName := range databases {
if err := db.exec(t, ctx, fmt.Sprintf(`CREATE DATABASE %s;`, dbName)); err != nil {
return err
}
}
return nil
}, func(ctx context.Context, db *verifyFormatDB, r *rsg.RSG) error {
n := r.Intn(len(roots))
s := r.Generate(roots[n], 30)
return db.exec(t, ctx, s)
// Select a database and use it in the generated statement.
dbName := databases[nextDatabaseName.Add(1)%int64(len(databases))]
return db.exec(t, ctx, strings.Replace(s, "ident", dbName, -1))
})
}

Expand Down

0 comments on commit b4a9870

Please sign in to comment.