Skip to content

Commit

Permalink
roachtest/version-upgrade: re-enable schema changer workload
Browse files Browse the repository at this point in the history
Previously, the schema changer workload was disabled inside
the version upgrade test because of intermittent job errors.
This patch re-enables this workload again for the version
upgrade test. It also updates the test to handle mixed version
declarative schema changer support.

Fixes: #100709

Release note: None
  • Loading branch information
fqazi committed Apr 5, 2023
1 parent ef357d1 commit 472d75f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
4 changes: 0 additions & 4 deletions pkg/cmd/roachtest/tests/versionupgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ func runVersionUpgrade(ctx context.Context, t test.Test, c cluster.Cluster) {
mvt.InMixedVersion(
"test schema change step",
func(ctx context.Context, l *logger.Logger, rng *rand.Rand, h *mixedversion.Helper) error {
if c.IsLocal() {
l.Printf("skipping step in bors builds while failures are handled -- #99115")
return nil
}
l.Printf("running schema workload step")
runCmd := roachtestutil.NewCommand("./workload run schemachange").Flag("verbose", 1).Flag("max-ops", 10).Flag("concurrency", 2).Arg("{pgurl:1-%d}", len(c.All()))
randomNode := h.RandomNode(rng, c.All())
Expand Down
65 changes: 62 additions & 3 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ var opDeclarative = []bool{
createEnum: false,
createSchema: false,
dropColumn: true,
dropColumnDefault: true,
dropColumnDefault: false,
dropColumnNotNull: true,
dropColumnStored: true,
dropColumnStored: false,
dropConstraint: true,
dropIndex: true,
dropSequence: true,
Expand All @@ -326,6 +326,31 @@ var opDeclarative = []bool{
validate: false,
}

var opDeclarativeVersion = []clusterversion.Key{
addColumn: clusterversion.V22_2,
addForeignKeyConstraint: clusterversion.V23_1,
addUniqueConstraint: clusterversion.V23_1,
createIndex: clusterversion.V23_1,
dropColumn: clusterversion.V22_2,
dropColumnNotNull: clusterversion.V23_1,
dropConstraint: clusterversion.V23_1,
dropIndex: clusterversion.V23_1,
dropSequence: clusterversion.BinaryMinSupportedVersionKey,
dropTable: clusterversion.BinaryMinSupportedVersionKey,
dropView: clusterversion.BinaryMinSupportedVersionKey,
dropSchema: clusterversion.BinaryMinSupportedVersionKey,
}

func init() {
// Assert that an active version is set for all declarative statements.
for op := range opDeclarative {
if opDeclarative[op] &&
opDeclarativeVersion[op] < clusterversion.BinaryMinSupportedVersionKey {
panic(errors.AssertionFailedf("declarative op %v doesn't have an active version", op))
}
}
}

// adjustOpWeightsForActiveVersion adjusts the weights for the active cockroach
// version, allowing us to disable certain operations in mixed version scenarios.
func adjustOpWeightsForCockroachVersion(
Expand All @@ -350,6 +375,28 @@ func adjustOpWeightsForCockroachVersion(
return tx.Rollback(ctx)
}

// getSupportedDeclarativeOp generates declarative operations until,
// a fully supported one is found. This is required for mixed version testing
// support, where statements may be partially supproted.
func (og *operationGenerator) getSupportedDeclarativeOp(
ctx context.Context, tx pgx.Tx,
) (opType, error) {
for {
op := opType(og.params.declarativeOps.Int())
if !clusterversion.TestingBinaryMinSupportedVersion.Equal(
clusterversion.ByKey(opDeclarativeVersion[op])) {
notSupported, err := isClusterVersionLessThan(ctx, tx, clusterversion.ByKey(opDeclarativeVersion[op]))
if err != nil {
return op, err
}
if notSupported {
continue
}
}
return op, nil
}
}

// randOp attempts to produce a random schema change operation. It returns a
// triple `(randOp, log, error)`. On success `randOp` is the random schema
// change constructed. Constructing a random schema change may require a few
Expand All @@ -362,7 +409,10 @@ func (og *operationGenerator) randOp(
var op opType
// The declarative schema changer has a more limited deck of operations.
if useDeclarativeSchemaChanger {
op = opType(og.params.declarativeOps.Int())
op, err = og.getSupportedDeclarativeOp(ctx, tx)
if err != nil {
return nil, err
}
} else {
op = opType(og.params.ops.Int())
}
Expand Down Expand Up @@ -3516,6 +3566,15 @@ func (og *operationGenerator) createSchema(ctx context.Context, tx pgx.Tx) (*opS
// TODO(jayshrivastava): Support authorization
stmt := randgen.MakeSchemaName(ifNotExists, schemaName, tree.MakeRoleSpecWithRoleName(username.RootUserName().Normalized()))
opStmt.sql = tree.Serialize(stmt)
// Descriptor ID generator may be temporarily unavailable, so
// allow uncategorized errors temporarily.
potentialDescIDGeneratorError, err := maybeExpectPotentialDescIDGenerationError(ctx, tx)
if err != nil {
return nil, err
}
codesWithConditions{
{code: pgcode.Uncategorized, condition: potentialDescIDGeneratorError},
}.add(opStmt.potentialExecErrors)
return opStmt, nil
}

Expand Down

0 comments on commit 472d75f

Please sign in to comment.