Skip to content

Commit

Permalink
schemachange/mixed-versions: handle possible syntax error for BIT(0) …
Browse files Browse the repository at this point in the history
…column usage

A recent fix enabled support for BIT(0) columns (see issue cockroachdb#132944),
which has since been backported. However, since this backport hasn’t
been released yet, running against an older down-level client may still
trigger a syntax error. This change adds a temporary check to handle
such errors until the backports for cockroachdb#132944 are publicly released.

This adjustment will be backported to older branches, with slight
variations per release:
- release-24.3: Reuse the same fix as in master.
- release-24.2: Use isClusterVersionLessThan with clusterversion.V24.2.
- release-24.1: Use isClusterVersionLessThan with clusterversion.V24.1.
- release-23.2: Use isClusterVersionLessThan with clusterversion.V23.2.

Epic: None
Release note: None
Closes: cockroachdb#133339, cockroachdb#133790, cockroachdb#131162
  • Loading branch information
spilchen committed Nov 7, 2024
1 parent 027dce3 commit 142130d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,18 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
if err != nil {
return nil, err
}
mixedVersion, err := isMixedVersionState(ctx, tx)
if err != nil {
return nil, err
}
hasUnsupportedBit0Type := func() bool {
for _, def := range stmt.Defs {
if col, ok := def.(*tree.ColumnTableDef); ok && isUnsupportedBit0Type(col.Type.SQLString(), mixedVersion) {
return true
}
}
return false
}()

tableExists, err := og.tableExists(ctx, tx, tableName)
if err != nil {
Expand Down Expand Up @@ -1310,6 +1322,7 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
{code: pgcode.UndefinedObject, condition: refCursorNotSupported},
{code: pgcode.FeatureNotSupported, condition: hasUnsupportedIdxQueries},
{code: pgcode.InvalidTableDefinition, condition: hasUnsupportedIdxQueries},
{code: pgcode.InvalidParameterValue, condition: hasUnsupportedBit0Type},
})
// Descriptor ID generator may be temporarily unavailable, so
// allow uncategorized errors temporarily.
Expand Down Expand Up @@ -3566,7 +3579,15 @@ func (og *operationGenerator) randType(
}
return typName, typ, nil
}
mixedVersion, err := isMixedVersionState(ctx, tx)
if err != nil {
return nil, nil, err
}

typ := randgen.RandSortingType(og.params.rng)
for isUnsupportedBit0Type(typ.SQLString(), mixedVersion) {
typ = randgen.RandSortingType(og.params.rng)
}
typeName := tree.MakeUnqualifiedTypeName(typ.SQLString())
return &typeName, typ, nil
}
Expand Down Expand Up @@ -3854,3 +3875,19 @@ func maybeExpectPotentialDescIDGenerationError(ctx context.Context, tx pgx.Tx) (
tx, descIDGenerationVersion)
return descIDGenerationErrorPossible, err
}

// isMixedVersionState works similarly to isClusterVersionLessThan, but without
// specifying a version. It returns true if the cluster version is not the
// latest, indicating a mixed-version test.
func isMixedVersionState(ctx context.Context, tx pgx.Tx) (bool, error) {
return isClusterVersionLessThan(ctx, tx, clusterversion.ByKey(clusterversion.V23_2))
}

func isUnsupportedBit0Type(typName string, mixedVersion bool) bool {
// TODO(spilchen): In mixed-version testing, declaring a BIT(0) column can cause a
// syntax error. Support for this type was recently added and backported, but the
// backport release is still pending. We need to regenerate the type until
// something other than BIT(0) is generated. This can be removed once 23.1.29 is
// publicly released.
return mixedVersion && strings.HasPrefix(typName, "BIT(0)")
}

0 comments on commit 142130d

Please sign in to comment.