Skip to content

Commit

Permalink
sql: ensure TLV is consistent with SLV
Browse files Browse the repository at this point in the history
In cockroachdb#94774, we didn't intend to change the TLV and it
is still supposed to be equal to the SLV. Changing the
way we set it however has caused TLV and SLV to be different
if a test uses two binaries, and only one of them was built
with `crdb_test` due to how we add `1e6` to versions in test
binaries.

Closes cockroachdb#95648

Epic: none
Release note: None
  • Loading branch information
healthy-pod committed Jan 26, 2023
1 parent 4858095 commit dec3327
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
20 changes: 10 additions & 10 deletions pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func TestTenantUpgrade(t *testing.T) {
cleanupPGUrl()
}
}
expectedInitialTenantVersion, _, _ := v0v1v2()
mkTenant := func(t *testing.T, id uint64) (tenantDB *gosql.DB, cleanup func()) {
settings := cluster.MakeTestingClusterSettingsWithVersions(
clusterversion.TestingBinaryVersion,
Expand All @@ -91,7 +90,7 @@ func TestTenantUpgrade(t *testing.T) {
)
// Initialize the version to the minimum it could be.
require.NoError(t, clusterversion.Initialize(ctx,
expectedInitialTenantVersion, &settings.SV))
clusterversion.TestingBinaryMinSupportedVersion, &settings.SV))
tenantArgs := base.TestTenantArgs{
TenantID: roachpb.MustMakeTenantID(id),
TestingKnobs: base.TestingKnobs{},
Expand All @@ -110,7 +109,7 @@ func TestTenantUpgrade(t *testing.T) {

// Ensure that the tenant works.
initialTenantRunner.CheckQueryResults(t, "SHOW CLUSTER SETTING version",
[][]string{{expectedInitialTenantVersion.String()}})
[][]string{{clusterversion.TestingBinaryMinSupportedVersion.String()}})
initialTenantRunner.Exec(t, "CREATE TABLE t (i INT PRIMARY KEY)")
initialTenantRunner.Exec(t, "INSERT INTO t VALUES (1), (2)")

Expand Down Expand Up @@ -170,14 +169,13 @@ func TestTenantUpgrade(t *testing.T) {
"SHOW CLUSTER SETTING version",
[][]string{{clusterversion.TestingBinaryVersion.String()}})
})

}

// Returns three versions :
// - v0 corresponds to the bootstrapped version of the tenant,
// - v1, v2 correspond to adjacent releases.
// Returns two versions v0, v1, v2 which correspond to adjacent releases. v0 will
// equal the TestingBinaryMinSupportedVersion to avoid rot in tests using this
// (as we retire old versions).
func v0v1v2() (roachpb.Version, roachpb.Version, roachpb.Version) {
v0 := clusterversion.ByKey(clusterversion.V22_2)
v0 := clusterversion.TestingBinaryMinSupportedVersion
v1 := clusterversion.TestingBinaryVersion
v2 := clusterversion.TestingBinaryVersion
if v1.Internal > 2 {
Expand Down Expand Up @@ -285,8 +283,10 @@ func TestTenantUpgradeFailure(t *testing.T) {
},
Settings: settings,
}
return &tenantInfo{tenantArgs: &tenantArgs,
v2onMigrationStopper: v2onMigrationStopper}
return &tenantInfo{
tenantArgs: &tenantArgs,
v2onMigrationStopper: v2onMigrationStopper,
}
}

t.Run("upgrade tenant have it crash then resume", func(t *testing.T) {
Expand Down
7 changes: 2 additions & 5 deletions pkg/sql/tenant_creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,15 @@ func (p *planner) createTenantInternal(
tid = roachpb.MustMakeTenantID(tenantID)

// Initialize the tenant's keyspace.
var tenantVersion clusterversion.ClusterVersion
tenantActiveVersion := p.EvalContext().Settings.Version.ActiveVersion(ctx)
codec := keys.MakeSQLCodec(roachpb.MustMakeTenantID(tenantID))
var kvs []roachpb.KeyValue
var splits []roachpb.RKey
const minVersion = clusterversion.V22_2
curVersion := clusterversion.V23_1
if p.EvalContext().Settings.Version.IsActive(ctx, curVersion) {
// The cluster is running the latest version.
// Use this version to create the tenant and bootstrap it using the host
// cluster's bootstrapping logic.
tenantVersion.Version = clusterversion.ByKey(curVersion)
schema := bootstrap.MakeMetadataSchema(
codec,
initialTenantZoneConfig, /* defaultZoneConfig */
Expand All @@ -141,7 +139,6 @@ func (p *planner) createTenantInternal(
// Use the previous major version to create the tenant and bootstrap it
// just like the previous major version binary would, using hardcoded
// initial values.
tenantVersion.Version = clusterversion.ByKey(minVersion)
kvs, splits, err = bootstrap.InitialValuesForTenantV222(
codec,
initialTenantZoneConfig, /* defaultZoneConfig */
Expand All @@ -160,7 +157,7 @@ func (p *planner) createTenantInternal(
// using code which may be too new. The expectation is that the tenant
// clusters will be updated to a version only after the system tenant has
// been upgraded.
tenantSettingKV, err := generateTenantClusterSettingKV(codec, tenantVersion)
tenantSettingKV, err := generateTenantClusterSettingKV(codec, tenantActiveVersion)
if err != nil {
return tid, err
}
Expand Down

0 comments on commit dec3327

Please sign in to comment.