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

upgrade/upgrades: allow CreatedAtNanos to be set when validating migration #87462

Merged
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
6 changes: 6 additions & 0 deletions pkg/upgrade/upgrades/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ go_test(
"role_id_migration_test.go",
"role_options_migration_test.go",
"sampled_stmt_diagnostics_requests_test.go",
"schema_changes_external_test.go",
"schema_changes_helpers_test.go",
"system_privileges_test.go",
"update_invalid_column_ids_in_sequence_back_references_external_test.go",
"upgrade_sequence_to_be_referenced_by_ID_external_test.go",
Expand All @@ -94,6 +96,7 @@ go_test(
"//pkg/jobs/jobstest",
"//pkg/keys",
"//pkg/kv",
"//pkg/roachpb",
"//pkg/security/securityassets",
"//pkg/security/securitytest",
"//pkg/security/username",
Expand All @@ -116,16 +119,19 @@ go_test(
"//pkg/sql/sem/tree",
"//pkg/sql/tests",
"//pkg/sql/types",
"//pkg/testutils",
"//pkg/testutils/serverutils",
"//pkg/testutils/skip",
"//pkg/testutils/sqlutils",
"//pkg/testutils/testcluster",
"//pkg/upgrade",
"//pkg/util",
"//pkg/util/ctxgroup",
"//pkg/util/hlc",
"//pkg/util/leaktest",
"//pkg/util/log",
"//pkg/util/protoutil",
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"@com_github_cockroachdb_errors//:errors",
"@com_github_stretchr_testify//assert",
Expand Down
12 changes: 11 additions & 1 deletion pkg/upgrade/upgrades/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"
Expand Down Expand Up @@ -45,14 +46,20 @@ type Schema struct {
// Upgrade runs cluster upgrade by changing the 'version' cluster setting.
func Upgrade(
t *testing.T, sqlDB *gosql.DB, key clusterversion.Key, done chan struct{}, expectError bool,
) {
UpgradeToVersion(t, sqlDB, clusterversion.ByKey(key), done, expectError)
}

func UpgradeToVersion(
t *testing.T, sqlDB *gosql.DB, v roachpb.Version, done chan struct{}, expectError bool,
) {
defer func() {
if done != nil {
done <- struct{}{}
}
}()
_, err := sqlDB.Exec(`SET CLUSTER SETTING version = $1`,
clusterversion.ByKey(key).String())
v.String())
if expectError {
assert.Error(t, err)
return
Expand Down Expand Up @@ -147,3 +154,6 @@ func GetTable(
require.NoError(t, err)
return table
}

// WaitForJobStatement is exported so that it can be detected by a testing knob.
const WaitForJobStatement = waitForJobStatement
8 changes: 7 additions & 1 deletion pkg/upgrade/upgrades/schema_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ type operation struct {
schemaExistsFn func(catalog.TableDescriptor, catalog.TableDescriptor, string) (bool, error)
}

// waitForJobStatement is the statement used to wait for an ongoing job to
// complete.
const waitForJobStatement = "SHOW JOBS WHEN COMPLETE VALUES ($1)"

// migrateTable is run during an upgrade to a new version and changes an existing
// table's schema based on schemaChangeQuery. The schema-change is ignored if the
// table already has the required changes.
Expand Down Expand Up @@ -92,7 +96,7 @@ func migrateTable(
for _, mutation := range mutations {
log.Infof(ctx, "waiting for the mutation job %v to complete", mutation.JobID)
if _, err := d.InternalExecutor.Exec(ctx, "migration-mutations-wait",
nil, "SHOW JOB WHEN COMPLETE $1", mutation.JobID); err != nil {
nil, waitForJobStatement, mutation.JobID); err != nil {
return err
}
}
Expand Down Expand Up @@ -242,6 +246,8 @@ func hasIndex(storedTable, expectedTable catalog.TableDescriptor, indexName stri
expectedCopy.StoreColumnNames = []string{}
storedCopy.StoreColumnIDs = []descpb.ColumnID{0, 0, 0}
expectedCopy.StoreColumnIDs = []descpb.ColumnID{0, 0, 0}
storedCopy.CreatedAtNanos = 0
expectedCopy.CreatedAtNanos = 0

if err = ensureProtoMessagesAreEqual(&expectedCopy, &storedCopy); err != nil {
return false, err
Expand Down
Loading