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

upgrades: fix desc ID sequence definition to match expectation #93610

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
1 change: 1 addition & 0 deletions pkg/cmd/roachtest/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ go_library(
"@com_github_kr_pretty//:pretty",
"@com_github_lib_pq//:pq",
"@com_github_montanaflynn_stats//:stats",
"@com_github_pmezard_go_difflib//difflib",
"@com_github_prometheus_client_golang//api",
"@com_github_prometheus_client_golang//api/prometheus/v1:prometheus",
"@com_github_prometheus_common//model",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/pmezard/go-difflib/difflib"
)

func registerValidateSystemSchemaAfterVersionUpgrade(r registry.Registry) {
Expand Down Expand Up @@ -85,8 +86,18 @@ func registerValidateSystemSchemaAfterVersionUpgrade(r registry.Registry) {
validateEquivalenceStep := func(str1, str2 *string) versionStep {
return func(ctx context.Context, t test.Test, u *versionUpgradeTest) {
if *str1 != *str2 {
t.Fatal("After upgrading, `USE system; SHOW CREATE ALL TABLES;` " +
"does not match expected output after version upgrade.\n")
diff, diffErr := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
A: difflib.SplitLines(*str1),
B: difflib.SplitLines(*str2),
Context: 5,
})
if diffErr != nil {
diff = diffErr.Error()
t.Errorf("failed to produce diff: %v", diffErr)
}
t.Fatalf("After upgrading, `USE system; SHOW CREATE ALL TABLES;` "+
"does not match expected output after version upgrade."+
"\nDiff:\n%s", diff)
}
t.L().Printf("validating succeeded:\n%v", *str1)
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/upgrade/upgrades/desc_id_sequence_for_system_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
"github.com/cockroachdb/cockroach/pkg/upgrade"
)

Expand All @@ -27,14 +26,19 @@ func descIDSequenceForSystemTenant(
if !d.Codec.ForSystemTenant() {
return nil
}
mut := tabledesc.NewBuilder(systemschema.DescIDSequence.TableDesc()).BuildCreatedMutableTable()
return d.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
oldEntry, err := txn.GetForUpdate(ctx, keys.LegacyDescIDGenerator)
if err != nil {
return err
}
mut.SequenceOpts.Start = oldEntry.ValueInt()
_, _, err = CreateSystemTableInTxn(ctx, d.Settings, txn, keys.SystemSQLCodec, mut)
return err
id, created, err := CreateSystemTableInTxn(
ctx, d.Settings, txn, keys.SystemSQLCodec, systemschema.DescIDSequence,
)
if err != nil || !created {
return err
}
// Install the appropriate value for the sequence. Note that we use the
// existence of the sequence above to make this transaction idempotent.
return txn.Put(ctx, d.Codec.SequenceKey(uint32(id)), oldEntry.ValueInt())
})
}