diff --git a/pkg/ccl/backupccl/insert_missing_public_schema_namespace_entry_restore_test.go b/pkg/ccl/backupccl/insert_missing_public_schema_namespace_entry_restore_test.go index 7206c1e5815d..51e55c41cdc0 100644 --- a/pkg/ccl/backupccl/insert_missing_public_schema_namespace_entry_restore_test.go +++ b/pkg/ccl/backupccl/insert_missing_public_schema_namespace_entry_restore_test.go @@ -37,7 +37,7 @@ func TestInsertMissingPublicSchemaNamespaceEntry(t *testing.T) { ExternalIODir: dir, Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(clusterversion.InsertPublicSchemaNamespaceEntryOnRestore - 1), }, }, diff --git a/pkg/ccl/backupccl/restore_old_versions_test.go b/pkg/ccl/backupccl/restore_old_versions_test.go index f9d20a2b9d37..e1dda6d1cbe2 100644 --- a/pkg/ccl/backupccl/restore_old_versions_test.go +++ b/pkg/ccl/backupccl/restore_old_versions_test.go @@ -865,7 +865,7 @@ func restorePublicSchemaMixedVersion(exportDir string) func(t *testing.T) { Knobs: base.TestingKnobs{ JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(), Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(clusterversion.PublicSchemasWithDescriptors - 1), }, }, @@ -920,7 +920,7 @@ func restoreSyntheticPublicSchemaNamespaceEntry(exportDir string) func(t *testin Knobs: base.TestingKnobs{ JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(), Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(clusterversion.PublicSchemasWithDescriptors - 1), }, }, @@ -951,7 +951,7 @@ func restoreSyntheticPublicSchemaNamespaceEntryCleanupOnFail(exportDir string) f Knobs: base.TestingKnobs{ JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(), Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(clusterversion.PublicSchemasWithDescriptors - 1), }, }, diff --git a/pkg/ccl/importccl/import_stmt_test.go b/pkg/ccl/importccl/import_stmt_test.go index 6c502b67c408..b3060b156f73 100644 --- a/pkg/ccl/importccl/import_stmt_test.go +++ b/pkg/ccl/importccl/import_stmt_test.go @@ -7381,7 +7381,7 @@ func TestImportMixedVersion(t *testing.T) { Knobs: base.TestingKnobs{ JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(), Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(clusterversion.PublicSchemasWithDescriptors - 1), }, }, diff --git a/pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go b/pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go index a3dc2f3b8804..4022f6ae39e4 100644 --- a/pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go +++ b/pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go @@ -58,7 +58,7 @@ func TestTenantUpgrade(t *testing.T) { Settings: settings, Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.TestingBinaryMinSupportedVersion, }, }, @@ -210,7 +210,7 @@ func TestTenantUpgradeFailure(t *testing.T) { Settings: settings, Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.TestingBinaryMinSupportedVersion, }, }, diff --git a/pkg/ccl/migrationccl/migrationsccl/seed_tenant_span_configs_external_test.go b/pkg/ccl/migrationccl/migrationsccl/seed_tenant_span_configs_external_test.go index 42e477bb598f..1138c8d8f08b 100644 --- a/pkg/ccl/migrationccl/migrationsccl/seed_tenant_span_configs_external_test.go +++ b/pkg/ccl/migrationccl/migrationsccl/seed_tenant_span_configs_external_test.go @@ -38,7 +38,7 @@ func TestPreSeedSpanConfigsWrittenWhenActive(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.PreSeedTenantSpanConfigs, ), @@ -90,7 +90,7 @@ func TestSeedTenantSpanConfigs(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.PreSeedTenantSpanConfigs - 1, ), @@ -159,7 +159,7 @@ func TestSeedTenantSpanConfigsWithExistingEntry(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.PreSeedTenantSpanConfigs, ), diff --git a/pkg/jobs/jobs_test.go b/pkg/jobs/jobs_test.go index ffbfd03c8ba0..138bfdc986bf 100644 --- a/pkg/jobs/jobs_test.go +++ b/pkg/jobs/jobs_test.go @@ -2471,7 +2471,7 @@ func TestStartableJobMixedVersion(t *testing.T) { Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ BinaryVersionOverride: clusterversion.TestingBinaryMinSupportedVersion, - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), }, }, }) diff --git a/pkg/kv/kvserver/client_migration_test.go b/pkg/kv/kvserver/client_migration_test.go index 74801038fe1b..2277613f7f68 100644 --- a/pkg/kv/kvserver/client_migration_test.go +++ b/pkg/kv/kvserver/client_migration_test.go @@ -251,7 +251,7 @@ func TestMigrateWaitsForApplication(t *testing.T) { Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ BinaryVersionOverride: startV, - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), }, Store: &kvserver.StoreTestingKnobs{ TestingApplyFilter: func(args kvserverbase.ApplyFilterArgs) (int, *roachpb.Error) { diff --git a/pkg/kv/kvserver/client_replica_test.go b/pkg/kv/kvserver/client_replica_test.go index 62fe25faeaf8..6daf41460cfc 100644 --- a/pkg/kv/kvserver/client_replica_test.go +++ b/pkg/kv/kvserver/client_replica_test.go @@ -4118,7 +4118,7 @@ func TestRangeMigration(t *testing.T) { Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ BinaryVersionOverride: startV, - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), }, }, }, diff --git a/pkg/migration/migrationmanager/manager_external_test.go b/pkg/migration/migrationmanager/manager_external_test.go index 1210896c0599..bba4caed870e 100644 --- a/pkg/migration/migrationmanager/manager_external_test.go +++ b/pkg/migration/migrationmanager/manager_external_test.go @@ -68,7 +68,7 @@ func TestAlreadyRunningJobsAreHandledProperly(t *testing.T) { Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ BinaryVersionOverride: startCV.Version, - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), }, MigrationManager: &migration.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { @@ -201,7 +201,7 @@ func TestMigrateUpdatesReplicaVersion(t *testing.T) { Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ BinaryVersionOverride: startCV.Version, - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), }, MigrationManager: &migration.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { @@ -319,7 +319,7 @@ func TestConcurrentMigrationAttempts(t *testing.T) { Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ BinaryVersionOverride: versions[0].Version, - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), }, MigrationManager: &migration.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { @@ -401,7 +401,7 @@ func TestPauseMigration(t *testing.T) { JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(), Server: &server.TestingKnobs{ BinaryVersionOverride: startCV.Version, - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), }, MigrationManager: &migration.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { @@ -521,7 +521,7 @@ func TestPrecondition(t *testing.T) { } knobs := base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: v0.Version, }, // Inject a migration which would run to upgrade the cluster. diff --git a/pkg/migration/migrations/alter_statement_diagnostics_requests_test.go b/pkg/migration/migrations/alter_statement_diagnostics_requests_test.go index efb8f43a8c68..7ab8b6ddadd3 100644 --- a/pkg/migration/migrations/alter_statement_diagnostics_requests_test.go +++ b/pkg/migration/migrations/alter_statement_diagnostics_requests_test.go @@ -39,7 +39,7 @@ func TestAlterSystemStmtDiagReqs(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(clusterversion.AlterSystemStmtDiagReqs - 1), }, }, diff --git a/pkg/migration/migrations/alter_table_protected_timestamp_records_test.go b/pkg/migration/migrations/alter_table_protected_timestamp_records_test.go index 5a04b20af8f1..ede427f0eda7 100644 --- a/pkg/migration/migrations/alter_table_protected_timestamp_records_test.go +++ b/pkg/migration/migrations/alter_table_protected_timestamp_records_test.go @@ -38,7 +38,7 @@ func TestAlterSystemProtectedTimestampRecordsTable(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.AlterSystemProtectedTimestampAddColumn - 1), }, diff --git a/pkg/migration/migrations/alter_table_statistics_avg_size_test.go b/pkg/migration/migrations/alter_table_statistics_avg_size_test.go index 89c88881a7b6..5f7aa888a3af 100644 --- a/pkg/migration/migrations/alter_table_statistics_avg_size_test.go +++ b/pkg/migration/migrations/alter_table_statistics_avg_size_test.go @@ -38,7 +38,7 @@ func TestAlterSystemTableStatisticsTable(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.AlterSystemTableStatisticsAddAvgSizeCol - 1), }, diff --git a/pkg/migration/migrations/builtins_test.go b/pkg/migration/migrations/builtins_test.go index ee17ab70f0eb..f37a67befa3c 100644 --- a/pkg/migration/migrations/builtins_test.go +++ b/pkg/migration/migrations/builtins_test.go @@ -31,7 +31,7 @@ func TestIsAtLeastVersionBuiltin(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(clusterversion.V21_2), }, }, diff --git a/pkg/migration/migrations/comment_on_index_migration_external_test.go b/pkg/migration/migrations/comment_on_index_migration_external_test.go index 889e46553dee..409118fa2c05 100644 --- a/pkg/migration/migrations/comment_on_index_migration_external_test.go +++ b/pkg/migration/migrations/comment_on_index_migration_external_test.go @@ -37,7 +37,7 @@ func TestEnsureIndexesExistForComments(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.DeleteCommentsWithDroppedIndexes - 1), }, diff --git a/pkg/migration/migrations/ensure_constraint_id_test.go b/pkg/migration/migrations/ensure_constraint_id_test.go index 591806f5bf8b..086cd274a414 100644 --- a/pkg/migration/migrations/ensure_constraint_id_test.go +++ b/pkg/migration/migrations/ensure_constraint_id_test.go @@ -41,7 +41,7 @@ func TestEnsureConstraintIDs(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( tabledesc.ConstraintIDsAddedToTableDescsVersion - 1), }, diff --git a/pkg/migration/migrations/ensure_no_draining_names_external_test.go b/pkg/migration/migrations/ensure_no_draining_names_external_test.go index 9d4d78f7a147..83adaa82fba0 100644 --- a/pkg/migration/migrations/ensure_no_draining_names_external_test.go +++ b/pkg/migration/migrations/ensure_no_draining_names_external_test.go @@ -41,7 +41,7 @@ func TestEnsureNoDrainingNames(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.AvoidDrainingNames - 1), }, diff --git a/pkg/migration/migrations/grant_option_migration_external_test.go b/pkg/migration/migrations/grant_option_migration_external_test.go index 5ab4153b4ea4..44d71421ec7d 100644 --- a/pkg/migration/migrations/grant_option_migration_external_test.go +++ b/pkg/migration/migrations/grant_option_migration_external_test.go @@ -169,7 +169,7 @@ func TestGrantOptionMigration(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(clusterversion.ValidateGrantOption - 1), // changed cluster version }, }, diff --git a/pkg/migration/migrations/migrate_span_configs_test.go b/pkg/migration/migrations/migrate_span_configs_test.go index 9d1b4368d3a0..a62a5c8a1a71 100644 --- a/pkg/migration/migrations/migrate_span_configs_test.go +++ b/pkg/migration/migrations/migrate_span_configs_test.go @@ -44,7 +44,7 @@ func TestEnsureSpanConfigReconciliation(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.EnsureSpanConfigReconciliation - 1, ), @@ -120,7 +120,7 @@ func TestEnsureSpanConfigReconciliationMultiNode(t *testing.T) { serverArgs[i] = base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.EnsureSpanConfigReconciliation - 1, ), @@ -133,7 +133,7 @@ func TestEnsureSpanConfigReconciliationMultiNode(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.EnsureSpanConfigReconciliation - 1, ), @@ -196,7 +196,7 @@ func TestEnsureSpanConfigSubscription(t *testing.T) { ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.EnsureSpanConfigSubscription - 1, ), diff --git a/pkg/migration/migrations/public_schema_migration_external_test.go b/pkg/migration/migrations/public_schema_migration_external_test.go index 2a58a8aaf532..c09d6aaa96e0 100644 --- a/pkg/migration/migrations/public_schema_migration_external_test.go +++ b/pkg/migration/migrations/public_schema_migration_external_test.go @@ -44,7 +44,7 @@ func publicSchemaMigrationTest(t *testing.T, ctx context.Context, numTables int) Settings: settings, Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(clusterversion.PublicSchemasWithDescriptors - 1), }, }, diff --git a/pkg/migration/migrations/raft_applied_index_term_external_test.go b/pkg/migration/migrations/raft_applied_index_term_external_test.go index 53340bcb7d70..fa84dd525fdd 100644 --- a/pkg/migration/migrations/raft_applied_index_term_external_test.go +++ b/pkg/migration/migrations/raft_applied_index_term_external_test.go @@ -124,7 +124,7 @@ func TestRaftAppliedIndexTermMigration(t *testing.T) { // Start at the version immediately preceding the migration. BinaryVersionOverride: bootstrapVersion, // We want to exercise manual control over the upgrade process. - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), } return args } @@ -234,7 +234,7 @@ func TestLatestClusterDoesNotNeedRaftAppliedIndexTermMigration(t *testing.T) { args.Knobs.Server = &server.TestingKnobs{ BinaryVersionOverride: binaryVersion, // We want to exercise manual control over the upgrade process. - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), } return args } diff --git a/pkg/migration/migrations/remove_invalid_database_privileges_external_test.go b/pkg/migration/migrations/remove_invalid_database_privileges_external_test.go index 20bb1a0529ec..c24c62a60a71 100644 --- a/pkg/migration/migrations/remove_invalid_database_privileges_external_test.go +++ b/pkg/migration/migrations/remove_invalid_database_privileges_external_test.go @@ -38,7 +38,7 @@ func TestConvertIncompatibleDatabasePrivilegesToDefaultPrivileges(t *testing.T) ServerArgs: base.TestServerArgs{ Knobs: base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey( clusterversion.RemoveIncompatibleDatabasePrivileges - 1), }, diff --git a/pkg/server/auto_upgrade.go b/pkg/server/auto_upgrade.go index d96a488be75f..c2fd65e4824b 100644 --- a/pkg/server/auto_upgrade.go +++ b/pkg/server/auto_upgrade.go @@ -12,7 +12,6 @@ package server import ( "context" - "sync/atomic" "time" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" @@ -36,16 +35,21 @@ func (s *Server) startAttemptUpgrade(ctx context.Context) { Closer: s.stopper.ShouldQuiesce(), } - for r := retry.StartWithCtx(ctx, retryOpts); r.Next(); { - // Check if auto upgrade is disabled for test purposes. - if k := s.cfg.TestingKnobs.Server; k != nil { - upgradeTestingKnobs := k.(*TestingKnobs) - if disable := atomic.LoadInt32(&upgradeTestingKnobs.DisableAutomaticVersionUpgrade); disable == 1 { - log.Infof(ctx, "auto upgrade disabled by testing") - continue + // Check if auto upgrade is disabled for test purposes. + if k := s.cfg.TestingKnobs.Server; k != nil { + upgradeTestingKnobs := k.(*TestingKnobs) + if disableCh := upgradeTestingKnobs.DisableAutomaticVersionUpgrade; disableCh != nil { + log.Infof(ctx, "auto upgrade disabled by testing") + select { + case <-disableCh: + log.Infof(ctx, "auto upgrade no longer disabled by testing") + case <-s.stopper.ShouldQuiesce(): + return } } + } + for r := retry.StartWithCtx(ctx, retryOpts); r.Next(); { // Check if we should upgrade cluster version, keep checking upgrade // status, or stop attempting upgrade. if quit, err := s.upgradeStatus(ctx); err != nil { diff --git a/pkg/server/migration_test.go b/pkg/server/migration_test.go index 68c465326545..f5f1b007bc5a 100644 --- a/pkg/server/migration_test.go +++ b/pkg/server/migration_test.go @@ -162,7 +162,7 @@ func TestBumpClusterVersion(t *testing.T) { BinaryVersionOverride: test.activeClusterVersion.Version, // We're bumping cluster versions manually ourselves. We // want avoid racing with the auto-upgrade process. - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), }, }, }) diff --git a/pkg/server/testing_knobs.go b/pkg/server/testing_knobs.go index d1b43648cbe3..ba5f3601a7ed 100644 --- a/pkg/server/testing_knobs.go +++ b/pkg/server/testing_knobs.go @@ -25,8 +25,8 @@ import ( // TestingKnobs groups testing knobs for the Server. type TestingKnobs struct { // DisableAutomaticVersionUpgrade, if set, temporarily disables the server's - // automatic version upgrade mechanism. - DisableAutomaticVersionUpgrade int32 // accessed atomically + // automatic version upgrade mechanism (until the channel is closed). + DisableAutomaticVersionUpgrade chan struct{} // DefaultZoneConfigOverride, if set, overrides the default zone config // defined in `pkg/config/zone.go`. DefaultZoneConfigOverride *zonepb.ZoneConfig diff --git a/pkg/server/version_cluster_test.go b/pkg/server/version_cluster_test.go index 3a822d207fa7..088f3261fdf5 100644 --- a/pkg/server/version_cluster_test.go +++ b/pkg/server/version_cluster_test.go @@ -16,7 +16,6 @@ import ( "fmt" "path/filepath" "strconv" - "sync/atomic" "testing" "github.com/cockroachdb/cockroach/pkg/base" @@ -182,7 +181,7 @@ func TestClusterVersionPersistedOnJoin(t *testing.T) { knobs := base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), }, } @@ -213,17 +212,16 @@ func TestClusterVersionUpgrade(t *testing.T) { var newVersion = clusterversion.TestingBinaryVersion var oldVersion = prev(newVersion) - knobs := base.TestingKnobs{ - Server: &server.TestingKnobs{ - BinaryVersionOverride: oldVersion, - DisableAutomaticVersionUpgrade: 1, - }, - } - + disableUpgradeCh := make(chan struct{}) rawTC := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{ ReplicationMode: base.ReplicationManual, // speeds up test ServerArgs: base.TestServerArgs{ - Knobs: knobs, + Knobs: base.TestingKnobs{ + Server: &server.TestingKnobs{ + BinaryVersionOverride: oldVersion, + DisableAutomaticVersionUpgrade: disableUpgradeCh, + }, + }, }, }) defer rawTC.Stopper().Stop(ctx) @@ -247,7 +245,7 @@ func TestClusterVersionUpgrade(t *testing.T) { if err := tc.setDowngrade(0, oldVersion.String()); err != nil { t.Fatalf("error setting CLUSTER SETTING cluster.preserve_downgrade_option: %s", err) } - atomic.StoreInt32(&knobs.Server.(*server.TestingKnobs).DisableAutomaticVersionUpgrade, 0) + close(disableUpgradeCh) // Check the cluster version is still oldVersion. curVersion := tc.getVersionFromSelect(0) @@ -415,7 +413,7 @@ func TestClusterVersionMixedVersionTooOld(t *testing.T) { // Start by running v0. knobs := base.TestingKnobs{ Server: &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: v0, }, // Inject a migration which would run to upgrade the cluster. diff --git a/pkg/sql/logictest/logic.go b/pkg/sql/logictest/logic.go index 278c7b52187e..5b5ff74b19e2 100644 --- a/pkg/sql/logictest/logic.go +++ b/pkg/sql/logictest/logic.go @@ -1490,7 +1490,7 @@ func (t *logicTest) newCluster(serverArgs TestServerArgs, opts []clusterOpt) { if params.ServerArgs.Knobs.Server == nil { params.ServerArgs.Knobs.Server = &server.TestingKnobs{} } - params.ServerArgs.Knobs.Server.(*server.TestingKnobs).DisableAutomaticVersionUpgrade = 1 + params.ServerArgs.Knobs.Server.(*server.TestingKnobs).DisableAutomaticVersionUpgrade = make(chan struct{}) } for _, opt := range opts { opt.apply(¶ms.ServerArgs) diff --git a/pkg/sql/unsplit_range_test.go b/pkg/sql/unsplit_range_test.go index 3200fae424a8..191e6a57402a 100644 --- a/pkg/sql/unsplit_range_test.go +++ b/pkg/sql/unsplit_range_test.go @@ -319,7 +319,7 @@ func TestUnsplitRanges(t *testing.T) { params, _ := tests.CreateTestServerParams() // Override binary version to be older. params.Knobs.Server = &server.TestingKnobs{ - DisableAutomaticVersionUpgrade: 1, + DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: clusterversion.ByKey(tc.binaryVersion), }