Skip to content

Commit

Permalink
sql: First round of cleanup of schemachange/random-load
Browse files Browse the repository at this point in the history
This issue addresses several issues uncovered in running the randomized
schema changer. Specifically:

- Makes several errors pgcodes, so that they can be properly added to
  the expected errors list in the randomized schema changer.
- Detects cases where the region column (crdb_region) is used multiple
  times in an index definition.
- Allows for column type changes, which must have the experimental flag
  enable_experimental_alter_column_type_general flag set.

It also disables the testing of setColumnType (tracked with cockroachdb#66662) as
well as making a column nullable/non-nullable due to a timing hole
(tracked with cockroachdb#66663).

Release note: None.
  • Loading branch information
ajstorm committed Jul 14, 2021
1 parent 018479a commit 4137aed
Show file tree
Hide file tree
Showing 7 changed files with 795 additions and 12 deletions.
1 change: 1 addition & 0 deletions pkg/cmd/roachtest/schemachange_random_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func runSchemaChangeRandomLoad(ctx context.Context, t *test, c *cluster, maxOps,
// saveArtifacts saves important test artifacts in the artifacts directory.
func saveArtifacts(ctx context.Context, c *cluster, storeDirectory string) {
db := c.Conn(ctx, 1)
defer db.Close()

// Save a backup file called schemachange to the store directory.
_, err := db.Exec("BACKUP DATABASE schemachange to 'nodelocal://1/schemachange'")
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvclient/kvcoord/testdata/savepoints
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ injected error

rollback x
----
(*telemetrykeys.withTelemetry) unimplemented: cannot rollback to savepoint after error
(*pgerror.withCandidateCode) unimplemented: cannot rollback to savepoint after error

subtest end

Expand Down
10 changes: 5 additions & 5 deletions pkg/sql/catalog/tabledesc/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,13 @@ func (desc *wrapper) ValidateSelf(vea catalog.ValidationErrorAccumulator) {
if alterPKMutation == m.MutationID {
vea.Report(unimplemented.NewWithIssue(
45615,
"cannot perform other schema changes in the same transaction as a primary key change",
))
"cannot perform other schema changes in the same transaction as a primary key change"),
)
} else {
vea.Report(unimplemented.NewWithIssue(
45615,
"cannot perform a schema change operation while a primary key change is in progress",
))
"cannot perform a schema change operation while a primary key change is in progress"),
)
}
return
}
Expand Down Expand Up @@ -948,7 +948,7 @@ func (desc *wrapper) validateTableIndexes(columnNames map[string]descpb.ColumnID
index.Name, name, colID, index.ColumnIDs[i])
}
if validateIndexDup.Contains(colID) {
return fmt.Errorf("index %q contains duplicate column %q", index.Name, name)
return pgerror.Newf(pgcode.FeatureNotSupported, "index %q contains duplicate column %q", index.GetName(), name)
}
validateIndexDup.Add(colID)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/errorutil/unimplemented/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/build",
"//pkg/sql/pgwire/pgcode",
"//pkg/sql/pgwire/pgerror",
"@com_github_cockroachdb_errors//:errors",
],
)
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/errorutil/unimplemented/unimplemented.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"fmt"

"github.com/cockroachdb/cockroach/pkg/build"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/errors"
)

Expand Down Expand Up @@ -96,5 +98,8 @@ func unimplementedInternal(
// perform telemetry.
err = errors.WithTelemetry(err, detail)
}

// Wrap with the corresponding PG error for unimplemented.
err = pgerror.WithCandidateCode(err, pgcode.FeatureNotSupported)
return err
}
Loading

0 comments on commit 4137aed

Please sign in to comment.