Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-22.2: workload/mixed-version/schemachanger: re-enable mixed version workload #88536

Merged
merged 4 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions pkg/cmd/roachtest/tests/mixed_version_schemachange.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func registerSchemaChangeMixedVersions(r registry.Registry) {
// This tests the work done for 20.1 that made schema changes jobs and in
// addition prevented making any new schema changes on a mixed cluster in
// order to prevent bugs during upgrades.
Cluster: r.MakeClusterSpec(4),
Cluster: r.MakeClusterSpec(4),
NativeLibs: registry.LibGEOS,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
maxOps := 100
concurrency := 5
Expand Down Expand Up @@ -56,12 +57,6 @@ func runSchemaChangeWorkloadStep(loadNode, maxOps, concurrency int) versionStep
t.L().Printf("Workload step run: %d", numFeatureRuns)
runCmd := []string{
"./workload run schemachange --verbose=1",
// The workload is still in development and occasionally discovers schema
// change errors so for now we don't fail on them but only on panics, server
// crashes, deadlocks, etc.
// TODO(spaskob): remove when https://github.com/cockroachdb/cockroach/issues/47430
// is closed.
"--tolerate-errors=true",
fmt.Sprintf("--max-ops %d", maxOps),
fmt.Sprintf("--concurrency %d", concurrency),
fmt.Sprintf("{pgurl:1-%d}", u.c.Spec().NodeCount),
Expand Down
78 changes: 74 additions & 4 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,13 +931,22 @@ func (og *operationGenerator) createIndex(ctx context.Context, tx pgx.Tx) (*opSt
return nil, err
}

// Only generate invisible indexes when they are supported.
invisibleIndexesIsNotSupported, err := isClusterVersionLessThan(
ctx,
tx,
clusterversion.ByKey(clusterversion.Start22_2))
if err != nil {
return nil, err
}

def := &tree.CreateIndex{
Name: tree.Name(indexName),
Table: *tableName,
Unique: og.randIntn(4) == 0, // 25% UNIQUE
Inverted: og.randIntn(10) == 0, // 10% INVERTED
IfNotExists: og.randIntn(2) == 0, // 50% IF NOT EXISTS
NotVisible: og.randIntn(20) == 0, // 5% NOT VISIBLE
Unique: og.randIntn(4) == 0, // 25% UNIQUE
Inverted: og.randIntn(10) == 0, // 10% INVERTED
IfNotExists: og.randIntn(2) == 0, // 50% IF NOT EXISTS
NotVisible: og.randIntn(20) == 0 && !invisibleIndexesIsNotSupported, // 5% NOT VISIBLE
}

regionColumn := ""
Expand Down Expand Up @@ -1180,6 +1189,49 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
stmt := randgen.RandCreateTableWithColumnIndexNumberGenerator(og.params.rng, "table", tableIdx, databaseHasMultiRegion, og.newUniqueSeqNum)
stmt.Table = *tableName
stmt.IfNotExists = og.randIntn(2) == 0
trigramIsNotSupported, err := isClusterVersionLessThan(
ctx,
tx,
clusterversion.ByKey(clusterversion.TrigramInvertedIndexes))
if err != nil {
return nil, err
}
hasTrigramIdxUnsupported := func() bool {
if !trigramIsNotSupported {
return false
}
// Check if any of the indexes have trigrams involved.
for _, def := range stmt.Defs {
if idx, ok := def.(*tree.IndexTableDef); ok && idx.Inverted {
lastColumn := idx.Columns[len(idx.Columns)-1]
switch lastColumn.OpClass {
case "gin_trgm_ops", "gist_trgm_ops":
return true
}
}
}
return false
}()

invisibleIndexesIsNotSupported, err := isClusterVersionLessThan(
ctx,
tx,
clusterversion.ByKey(clusterversion.Start22_2))
if err != nil {
return nil, err
}
hasInvisibleIndexesUnsupported := func() bool {
if !invisibleIndexesIsNotSupported {
return false
}
// Check if any of the indexes have trigrams involved.
for _, def := range stmt.Defs {
if idx, ok := def.(*tree.IndexTableDef); ok && idx.NotVisible {
return true
}
}
return false
}()

tableExists, err := og.tableExists(ctx, tx, tableName)
if err != nil {
Expand All @@ -1194,6 +1246,12 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
{code: pgcode.DuplicateRelation, condition: tableExists && !stmt.IfNotExists},
{code: pgcode.UndefinedSchema, condition: !schemaExists},
}.add(opStmt.expectedExecErrors)
// Compatibility errors aren't guaranteed since the cluster version update is not
// fully transaction aware.
codesWithConditions{
{code: pgcode.FeatureNotSupported, condition: hasTrigramIdxUnsupported},
{code: pgcode.Syntax, condition: hasInvisibleIndexesUnsupported},
}.add(opStmt.potentialExecErrors)
opStmt.sql = tree.Serialize(stmt)
return opStmt, nil
}
Expand Down Expand Up @@ -2350,6 +2408,18 @@ func (og *operationGenerator) insertRow(ctx context.Context, tx pgx.Tx) (stmt *o
if err != nil {
return nil, err
}
// If we aren't on 22.2 then disable the insert plugin, since 21.X
// can have schema instrospection queries fail due to an optimizer bug.
skipInserts, err := isClusterVersionLessThan(ctx, tx, clusterversion.ByKey(clusterversion.Start22_2))
if err != nil {
return nil, err
}
// If inserts are to be skipped, we will intentionally, target the insert towards
// a non-existent table, so that they become no-ops.
if skipInserts {
tableExists = false
tableName.SchemaName = "InvalidObjectName"
}
if !tableExists {
return makeOpStmtForSingleError(OpStmtDML,
fmt.Sprintf(
Expand Down