From 32622e1b18030bd52529841ec1bb280a5683d5cb Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Tue, 17 May 2022 00:07:20 -0400 Subject: [PATCH] upgrade: rename migration We've got a whole new team we're going to call migrations. It was bound to get confusing. Release note: None --- .github/CODEOWNERS | 4 +- pkg/BUILD.bazel | 9 +- pkg/base/testing_knobs.go | 2 +- pkg/ccl/kvccl/kvtenantccl/BUILD.bazel | 4 +- .../kvccl/kvtenantccl/tenant_upgrade_test.go | 22 ++--- .../migrationccl/migrationsccl/BUILD.bazel | 30 ------ .../tenantcostserver/system_table.go | 4 +- pkg/ccl/upgradeccl/upgradessccl/BUILD.bazel | 59 ++++++++++++ .../upgradessccl}/main_test.go | 2 +- .../seed_span_counts_external_test.go | 6 +- .../seed_tenant_span_configs_external_test.go | 6 +- pkg/cli/clisqlclient/statement_diag.go | 2 +- pkg/cli/mt_start_sql.go | 2 +- pkg/clusterversion/clusterversion.go | 4 +- pkg/clusterversion/keyed_versions.go | 2 +- pkg/clusterversion/setting.go | 2 +- pkg/config/system_test.go | 14 +-- pkg/keys/constants.go | 8 +- pkg/keys/doc.go | 4 +- pkg/keys/sql.go | 15 +-- pkg/roachprod/vm/azure/doc.go | 2 +- pkg/server/BUILD.bazel | 10 +- pkg/server/admin.go | 2 +- pkg/server/migration.go | 4 +- pkg/server/migration_test.go | 2 +- pkg/server/node.go | 6 +- pkg/server/server.go | 2 +- pkg/server/server_sql.go | 36 +++---- pkg/server/server_test.go | 2 +- pkg/server/version_cluster_test.go | 24 ++--- pkg/sql/BUILD.bazel | 2 +- pkg/sql/create_test.go | 2 +- pkg/sql/exec_util.go | 20 ++-- pkg/sql/importer/import_table_creation.go | 2 +- pkg/sql/indexbackfiller_test.go | 2 +- pkg/sql/job_exec_context.go | 6 +- pkg/sql/job_exec_context_test_util.go | 4 +- pkg/sql/logictest/BUILD.bazel | 2 +- pkg/sql/logictest/logic.go | 8 +- pkg/sql/metric_util_test.go | 2 +- pkg/sql/mvcc_backfiller_test.go | 2 +- pkg/sql/opt_catalog.go | 2 +- pkg/sql/planhook.go | 4 +- pkg/sql/planner.go | 8 +- pkg/sql/rowexec/backfiller_test.go | 2 +- pkg/sql/schema_changer.go | 2 +- pkg/sql/sem/builtins/builtins.go | 6 +- .../compaction_scheduling.go | 2 +- pkg/startupmigrations/migrations.go | 6 +- pkg/startupmigrations/migrations_test.go | 2 +- pkg/{migration => upgrade}/BUILD.bazel | 10 +- pkg/{migration => upgrade}/helpers.go | 8 +- .../nodelivenesstest/BUILD.bazel | 2 +- .../nodelivenesstest/test_node_liveness.go | 2 +- .../system_upgrade.go} | 44 ++++----- .../tenant_upgrade.go} | 48 +++++----- pkg/{migration => upgrade}/testing_knobs.go | 10 +- .../migration.go => upgrade/upgrade.go} | 62 ++++++------ .../upgradecluster}/BUILD.bazel | 10 +- .../upgradecluster}/client_test.go | 10 +- .../upgradecluster}/cluster.go | 14 +-- .../upgradecluster}/helper_test.go | 4 +- .../upgradecluster}/main_test.go | 2 +- .../upgradecluster}/nodes.go | 4 +- .../upgradecluster}/nodes_test.go | 2 +- .../upgradecluster}/tenant_cluster.go | 14 +-- .../upgradejob}/BUILD.bazel | 8 +- .../upgradejob/upgrade_job.go} | 34 +++---- .../upgrademanager}/BUILD.bazel | 16 ++-- .../upgrademanager}/main_test.go | 2 +- .../upgrademanager}/manager.go | 82 ++++++++-------- .../upgrademanager}/manager_external_test.go | 94 +++++++++---------- .../upgrades}/BUILD.bazel | 12 +-- .../alter_statement_diagnostics_requests.go | 6 +- ...ter_statement_diagnostics_requests_test.go | 22 ++--- ...alter_table_protected_timestamp_records.go | 6 +- ..._table_protected_timestamp_records_test.go | 18 ++-- .../alter_table_statistics_avg_size.go | 6 +- .../alter_table_statistics_avg_size_test.go | 20 ++-- .../upgrades}/builtins_test.go | 4 +- .../upgrades}/comment_on_index_migration.go | 6 +- ...omment_on_index_migration_external_test.go | 4 +- .../upgrades}/descriptor_utils.go | 8 +- .../upgrades}/descriptor_utils_test.go | 8 +- .../upgrades}/ensure_constraint_id_test.go | 4 +- .../upgrades}/ensure_no_draining_names.go | 6 +- .../ensure_no_draining_names_external_test.go | 6 +- .../upgrades}/fix_cast_for_style_migration.go | 6 +- .../fix_cast_for_style_migration_test.go | 6 +- .../upgrades}/grant_option_migration.go | 6 +- .../grant_option_migration_external_test.go | 4 +- .../upgrades}/helpers_test.go | 6 +- ...t_missing_public_schema_namespace_entry.go | 6 +- .../upgrades}/main_test.go | 2 +- .../upgrades}/migrate_span_configs.go | 8 +- .../upgrades}/migrate_span_configs_test.go | 8 +- .../upgrades}/public_schema_migration.go | 12 +-- .../public_schema_migration_external_test.go | 12 +-- .../upgrades}/raft_applied_index_term.go | 16 ++-- .../raft_applied_index_term_external_test.go | 12 +-- .../remove_invalid_database_privileges.go | 8 +- ...valid_database_privileges_external_test.go | 4 +- .../upgrades}/schema_changes.go | 14 +-- .../upgrades}/seed_tenant_span_configs.go | 8 +- .../upgrades}/span_count_table.go | 8 +- .../upgrades}/tenant_settings.go | 6 +- .../upgrades}/testdata/separated_intents | 0 .../upgrades/upgrades.go} | 60 ++++++------ 108 files changed, 619 insertions(+), 588 deletions(-) delete mode 100644 pkg/ccl/migrationccl/migrationsccl/BUILD.bazel create mode 100644 pkg/ccl/upgradeccl/upgradessccl/BUILD.bazel rename pkg/ccl/{migrationccl/migrationsccl => upgradeccl/upgradessccl}/main_test.go (97%) rename pkg/ccl/{migrationccl/migrationsccl => upgradeccl/upgradessccl}/seed_span_counts_external_test.go (98%) rename pkg/ccl/{migrationccl/migrationsccl => upgradeccl/upgradessccl}/seed_tenant_span_configs_external_test.go (97%) rename pkg/{migration => upgrade}/BUILD.bazel (79%) rename pkg/{migration => upgrade}/helpers.go (85%) rename pkg/{migration => upgrade}/nodelivenesstest/BUILD.bazel (76%) rename pkg/{migration => upgrade}/nodelivenesstest/test_node_liveness.go (97%) rename pkg/{migration/system_migration.go => upgrade/system_upgrade.go} (85%) rename pkg/{migration/tenant_migration.go => upgrade/tenant_upgrade.go} (64%) rename pkg/{migration => upgrade}/testing_knobs.go (73%) rename pkg/{migration/migration.go => upgrade/upgrade.go} (54%) rename pkg/{migration/migrationcluster => upgrade/upgradecluster}/BUILD.bazel (84%) rename pkg/{migration/migrationcluster => upgrade/upgradecluster}/client_test.go (90%) rename pkg/{migration/migrationcluster => upgrade/upgradecluster}/cluster.go (93%) rename pkg/{migration/migrationcluster => upgrade/upgradecluster}/helper_test.go (98%) rename pkg/{migration/migrationmanager => upgrade/upgradecluster}/main_test.go (97%) rename pkg/{migration/migrationcluster => upgrade/upgradecluster}/nodes.go (98%) rename pkg/{migration/migrationcluster => upgrade/upgradecluster}/nodes_test.go (98%) rename pkg/{migration/migrationcluster => upgrade/upgradecluster}/tenant_cluster.go (94%) rename pkg/{migration/migrationjob => upgrade/upgradejob}/BUILD.bazel (74%) rename pkg/{migration/migrationjob/migration_job.go => upgrade/upgradejob/upgrade_job.go} (82%) rename pkg/{migration/migrationmanager => upgrade/upgrademanager}/BUILD.bazel (83%) rename pkg/{migration/migrationcluster => upgrade/upgrademanager}/main_test.go (97%) rename pkg/{migration/migrationmanager => upgrade/upgrademanager}/manager.go (84%) rename pkg/{migration/migrationmanager => upgrade/upgrademanager}/manager_external_test.go (86%) rename pkg/{migration/migrations => upgrade/upgrades}/BUILD.bazel (95%) rename pkg/{migration/migrations => upgrade/upgrades}/alter_statement_diagnostics_requests.go (93%) rename pkg/{migration/migrations => upgrade/upgrades}/alter_statement_diagnostics_requests_test.go (90%) rename pkg/{migration/migrations => upgrade/upgrades}/alter_table_protected_timestamp_records.go (87%) rename pkg/{migration/migrations => upgrade/upgrades}/alter_table_protected_timestamp_records_test.go (90%) rename pkg/{migration/migrations => upgrade/upgrades}/alter_table_statistics_avg_size.go (88%) rename pkg/{migration/migrations => upgrade/upgrades}/alter_table_statistics_avg_size_test.go (90%) rename pkg/{migration/migrations => upgrade/upgrades}/builtins_test.go (97%) rename pkg/{migration/migrations => upgrade/upgrades}/comment_on_index_migration.go (90%) rename pkg/{migration/migrations => upgrade/upgrades}/comment_on_index_migration_external_test.go (98%) rename pkg/{migration/migrations => upgrade/upgrades}/descriptor_utils.go (95%) rename pkg/{migration/migrations => upgrade/upgrades}/descriptor_utils_test.go (94%) rename pkg/{migration/migrations => upgrade/upgrades}/ensure_constraint_id_test.go (98%) rename pkg/{migration/migrations => upgrade/upgrades}/ensure_no_draining_names.go (92%) rename pkg/{migration/migrations => upgrade/upgrades}/ensure_no_draining_names_external_test.go (96%) rename pkg/{migration/migrations => upgrade/upgrades}/fix_cast_for_style_migration.go (79%) rename pkg/{migration/migrations => upgrade/upgrades}/fix_cast_for_style_migration_test.go (96%) rename pkg/{migration/migrations => upgrade/upgrades}/grant_option_migration.go (82%) rename pkg/{migration/migrations => upgrade/upgrades}/grant_option_migration_external_test.go (99%) rename pkg/{migration/migrations => upgrade/upgrades}/helpers_test.go (97%) rename pkg/{migration/migrations => upgrade/upgrades}/insert_missing_public_schema_namespace_entry.go (94%) rename pkg/{migration/migrations => upgrade/upgrades}/main_test.go (97%) rename pkg/{migration/migrations => upgrade/upgrades}/migrate_span_configs.go (90%) rename pkg/{migration/migrations => upgrade/upgrades}/migrate_span_configs_test.go (97%) rename pkg/{migration/migrations => upgrade/upgrades}/public_schema_migration.go (96%) rename pkg/{migration/migrations => upgrade/upgrades}/public_schema_migration_external_test.go (95%) rename pkg/{migration/migrations => upgrade/upgrades}/raft_applied_index_term.go (85%) rename pkg/{migration/migrations => upgrade/upgrades}/raft_applied_index_term_external_test.go (96%) rename pkg/{migration/migrations => upgrade/upgrades}/remove_invalid_database_privileges.go (79%) rename pkg/{migration/migrations => upgrade/upgrades}/remove_invalid_database_privileges_external_test.go (98%) rename pkg/{migration/migrations => upgrade/upgrades}/schema_changes.go (96%) rename pkg/{migration/migrations => upgrade/upgrades}/seed_tenant_span_configs.go (92%) rename pkg/{migration/migrations => upgrade/upgrades}/span_count_table.go (91%) rename pkg/{migration/migrations => upgrade/upgrades}/tenant_settings.go (84%) rename pkg/{migration/migrations => upgrade/upgrades}/testdata/separated_intents (100%) rename pkg/{migration/migrations/migrations.go => upgrade/upgrades/upgrades.go} (73%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index bad28bffdf93..8a0de4d5ed45 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -151,7 +151,7 @@ /pkg/ccl/cmdccl/stub-schema-registry/ @cockroachdb/cdc-prs /pkg/ccl/gssapiccl/ @cockroachdb/server-prs /pkg/ccl/kvccl/ @cockroachdb/kv-noreview -/pkg/ccl/migrationccl/ @cockroachdb/kv-prs-noreview +/pkg/ccl/upgradeccl/ @cockroachdb/kv-prs-noreview /pkg/ccl/logictestccl/ @cockroachdb/sql-queries-noreview /pkg/ccl/multiregionccl/ @cockroachdb/multiregion /pkg/ccl/multitenantccl/ @cockroachdb/unowned @@ -243,7 +243,7 @@ /pkg/keysbase/ @cockroachdb/kv-prs # Don't ping KV on updates to reserved descriptor IDs and such. /pkg/keys/constants.go @cockroachdb/kv-prs-noreview -/pkg/migration/ @cockroachdb/kv-prs-noreview @cockroachdb/sql-schema +/pkg/upgrade/ @cockroachdb/kv-prs-noreview @cockroachdb/sql-schema /pkg/multitenant @cockroachdb/unowned /pkg/release/ @cockroachdb/dev-inf /pkg/roachpb/.gitattributes @cockroachdb/dev-inf diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index e3cd9d9be391..8d49cd80c177 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -25,7 +25,6 @@ ALL_TESTS = [ "//pkg/ccl/kvccl/kvfollowerreadsccl:kvfollowerreadsccl_test", "//pkg/ccl/kvccl/kvtenantccl:kvtenantccl_test", "//pkg/ccl/logictestccl:logictestccl_test", - "//pkg/ccl/migrationccl/migrationsccl:migrationsccl_test", "//pkg/ccl/multiregionccl:multiregionccl_test", "//pkg/ccl/multitenantccl/tenantcostclient:tenantcostclient_test", "//pkg/ccl/multitenantccl/tenantcostserver/tenanttokenbucket:tenanttokenbucket_test", @@ -58,6 +57,8 @@ ALL_TESTS = [ "//pkg/ccl/telemetryccl:telemetryccl_test", "//pkg/ccl/testccl/sqlccl:sqlccl_test", "//pkg/ccl/testccl/workload/schemachange:schemachange_test", + "//pkg/ccl/upgradeccl/upgradessccl:upgradesccl_test", + "//pkg/ccl/upgradeccl/upgradessccl:upgradessccl_test", "//pkg/ccl/utilccl/sampledataccl:sampledataccl_test", "//pkg/ccl/utilccl:utilccl_test", "//pkg/ccl/workloadccl/allccl:allccl_test", @@ -177,9 +178,6 @@ ALL_TESTS = [ "//pkg/kv/kvserver/uncertainty:uncertainty_test", "//pkg/kv/kvserver:kvserver_test", "//pkg/kv:kv_test", - "//pkg/migration/migrationcluster:migrationcluster_test", - "//pkg/migration/migrationmanager:migrationmanager_test", - "//pkg/migration/migrations:migrations_test", "//pkg/roachpb:roachpb_test", "//pkg/roachpb:string_test", "//pkg/roachprod/cloud:cloud_test", @@ -434,6 +432,9 @@ ALL_TESTS = [ "//pkg/testutils:testutils_test", "//pkg/ts/testmodel:testmodel_test", "//pkg/ts:ts_test", + "//pkg/upgrade/upgradecluster:upgradecluster_test", + "//pkg/upgrade/upgrademanager:upgrademanager_test", + "//pkg/upgrade/upgrades:upgrades_test", "//pkg/util/admission:admission_test", "//pkg/util/binfetcher:binfetcher_test", "//pkg/util/bitarray:bitarray_test", diff --git a/pkg/base/testing_knobs.go b/pkg/base/testing_knobs.go index 22d37ea9b34e..6deeba297c5c 100644 --- a/pkg/base/testing_knobs.go +++ b/pkg/base/testing_knobs.go @@ -39,7 +39,7 @@ type TestingKnobs struct { BackupRestore ModuleTestingKnobs TTL ModuleTestingKnobs Streaming ModuleTestingKnobs - MigrationManager ModuleTestingKnobs + UpgradeManager ModuleTestingKnobs IndexUsageStatsKnobs ModuleTestingKnobs SQLStatsKnobs ModuleTestingKnobs SpanConfig ModuleTestingKnobs diff --git a/pkg/ccl/kvccl/kvtenantccl/BUILD.bazel b/pkg/ccl/kvccl/kvtenantccl/BUILD.bazel index 3b0f3e30a063..f4b18b04e280 100644 --- a/pkg/ccl/kvccl/kvtenantccl/BUILD.bazel +++ b/pkg/ccl/kvccl/kvtenantccl/BUILD.bazel @@ -61,8 +61,6 @@ go_test( "//pkg/kv/kvclient/kvtenant", "//pkg/kv/kvserver", "//pkg/kv/kvserver/kvserverbase", - "//pkg/migration", - "//pkg/migration/migrations", "//pkg/roachpb", "//pkg/rpc", "//pkg/security", @@ -77,6 +75,8 @@ go_test( "//pkg/testutils/serverutils", "//pkg/testutils/sqlutils", "//pkg/testutils/testcluster", + "//pkg/upgrade", + "//pkg/upgrade/upgrades", "//pkg/util", "//pkg/util/grpcutil", "//pkg/util/hlc", diff --git a/pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go b/pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go index e9c03105adf9..52d1fefd8a31 100644 --- a/pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go +++ b/pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go @@ -20,8 +20,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/config" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/migration" - "github.com/cockroachdb/cockroach/pkg/migration/migrations" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server" @@ -31,6 +29,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" + "github.com/cockroachdb/cockroach/pkg/upgrade" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/stop" @@ -254,29 +254,29 @@ func TestTenantUpgradeFailure(t *testing.T) { Existing: existing, TestingKnobs: base.TestingKnobs{ JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(), - MigrationManager: &migration.TestingKnobs{ + UpgradeManager: &upgrade.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { return []clusterversion.ClusterVersion{{Version: v1}, {Version: v2}} }, - RegistryOverride: func(cv clusterversion.ClusterVersion) (migration.Migration, bool) { + RegistryOverride: func(cv clusterversion.ClusterVersion) (upgrade.Upgrade, bool) { switch cv.Version { case v1: - return migration.NewTenantMigration("testing", clusterversion.ClusterVersion{ + return upgrade.NewTenantUpgrade("testing", clusterversion.ClusterVersion{ Version: v1, }, - migrations.NoPrecondition, + upgrades.NoPrecondition, func( - ctx context.Context, version clusterversion.ClusterVersion, deps migration.TenantDeps, _ *jobs.Job, + ctx context.Context, version clusterversion.ClusterVersion, deps upgrade.TenantDeps, _ *jobs.Job, ) error { return nil }), true case v2: - return migration.NewTenantMigration("testing next", clusterversion.ClusterVersion{ + return upgrade.NewTenantUpgrade("testing next", clusterversion.ClusterVersion{ Version: v2, }, - migrations.NoPrecondition, + upgrades.NoPrecondition, func( - ctx context.Context, version clusterversion.ClusterVersion, deps migration.TenantDeps, _ *jobs.Job, + ctx context.Context, version clusterversion.ClusterVersion, deps upgrade.TenantDeps, _ *jobs.Job, ) error { tenantStopperChannel <- struct{}{} return nil @@ -319,7 +319,7 @@ func TestTenantUpgradeFailure(t *testing.T) { clusterversion.TestingBinaryVersion.String()) // Ensure that the tenant still works. initialTenantRunner.CheckQueryResults(t, "SELECT * FROM t", [][]string{{"1"}, {"2"}}) - // Upgrade the tenant cluster, but the migration will fail on v1. + // Upgrade the tenant cluster, but the upgrade will fail on v1. initialTenantRunner.ExpectErr(t, ".*(database is closed|failed to connect|closed network connection)+", "SET CLUSTER SETTING version = $1", diff --git a/pkg/ccl/migrationccl/migrationsccl/BUILD.bazel b/pkg/ccl/migrationccl/migrationsccl/BUILD.bazel deleted file mode 100644 index b41080a825b9..000000000000 --- a/pkg/ccl/migrationccl/migrationsccl/BUILD.bazel +++ /dev/null @@ -1,30 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_test") - -go_test( - name = "migrationsccl_test", - srcs = [ - "main_test.go", - "seed_span_counts_external_test.go", - "seed_tenant_span_configs_external_test.go", - ], - deps = [ - "//pkg/base", - "//pkg/ccl/kvccl/kvtenantccl", - "//pkg/clusterversion", - "//pkg/keys", - "//pkg/roachpb", - "//pkg/security", - "//pkg/security/securitytest", - "//pkg/security/username", - "//pkg/server", - "//pkg/settings/cluster", - "//pkg/spanconfig", - "//pkg/testutils", - "//pkg/testutils/serverutils", - "//pkg/testutils/sqlutils", - "//pkg/testutils/testcluster", - "//pkg/util/leaktest", - "//pkg/util/log", - "@com_github_stretchr_testify//require", - ], -) diff --git a/pkg/ccl/multitenantccl/tenantcostserver/system_table.go b/pkg/ccl/multitenantccl/tenantcostserver/system_table.go index ccb31cb8e335..2e7a5a63a835 100644 --- a/pkg/ccl/multitenantccl/tenantcostserver/system_table.go +++ b/pkg/ccl/multitenantccl/tenantcostserver/system_table.go @@ -189,7 +189,7 @@ func (h *sysTableHelper) readTenantAndInstanceState( CurrentShareSum: float64(tree.MustBeDFloat(r[6])), } if consumption := r[7]; consumption != tree.DNull { - // total_consumption can be NULL because of a migration of the + // total_consumption can be NULL because of an upgrade of the // tenant_usage table. if err := protoutil.Unmarshal( []byte(tree.MustBeDBytes(consumption)), &tenant.Consumption, @@ -512,7 +512,7 @@ func (h *sysTableHelper) checkInvariants() error { return errors.Errorf("expected NULL column %d", j) } // We have an exception for total_consumption, which can be NULL because - // of a migration of the tenant_usage table. + // of an upgrade of the tenant_usage table. if i != 7 { return errors.Errorf("expected non-NULL column %d", j) } diff --git a/pkg/ccl/upgradeccl/upgradessccl/BUILD.bazel b/pkg/ccl/upgradeccl/upgradessccl/BUILD.bazel new file mode 100644 index 000000000000..97ebd6a72ac4 --- /dev/null +++ b/pkg/ccl/upgradeccl/upgradessccl/BUILD.bazel @@ -0,0 +1,59 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_test") + +go_test( + name = "upgradesccl_test", + srcs = [ + "main_test.go", + "seed_span_counts_external_test.go", + "seed_tenant_span_configs_external_test.go", + ], + deps = [ + "//pkg/base", + "//pkg/ccl/kvccl/kvtenantccl", + "//pkg/clusterversion", + "//pkg/keys", + "//pkg/roachpb", + "//pkg/security", + "//pkg/security/securitytest", + "//pkg/security/username", + "//pkg/server", + "//pkg/settings/cluster", + "//pkg/spanconfig", + "//pkg/testutils", + "//pkg/testutils/serverutils", + "//pkg/testutils/sqlutils", + "//pkg/testutils/testcluster", + "//pkg/util/leaktest", + "//pkg/util/log", + "@com_github_stretchr_testify//require", + ], +) + +go_test( + name = "upgradessccl_test", + srcs = [ + "main_test.go", + "seed_span_counts_external_test.go", + "seed_tenant_span_configs_external_test.go", + ], + deps = [ + "//pkg/base", + "//pkg/ccl/kvccl/kvtenantccl", + "//pkg/clusterversion", + "//pkg/keys", + "//pkg/roachpb", + "//pkg/security", + "//pkg/security/securitytest", + "//pkg/security/username", + "//pkg/server", + "//pkg/settings/cluster", + "//pkg/spanconfig", + "//pkg/testutils", + "//pkg/testutils/serverutils", + "//pkg/testutils/sqlutils", + "//pkg/testutils/testcluster", + "//pkg/util/leaktest", + "//pkg/util/log", + "@com_github_stretchr_testify//require", + ], +) diff --git a/pkg/ccl/migrationccl/migrationsccl/main_test.go b/pkg/ccl/upgradeccl/upgradessccl/main_test.go similarity index 97% rename from pkg/ccl/migrationccl/migrationsccl/main_test.go rename to pkg/ccl/upgradeccl/upgradessccl/main_test.go index dbc9aefe032b..8ee5557d3bd5 100644 --- a/pkg/ccl/migrationccl/migrationsccl/main_test.go +++ b/pkg/ccl/upgradeccl/upgradessccl/main_test.go @@ -6,7 +6,7 @@ // // https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt -package migrationsccl_test +package upgradessccl_test import ( "os" diff --git a/pkg/ccl/migrationccl/migrationsccl/seed_span_counts_external_test.go b/pkg/ccl/upgradeccl/upgradessccl/seed_span_counts_external_test.go similarity index 98% rename from pkg/ccl/migrationccl/migrationsccl/seed_span_counts_external_test.go rename to pkg/ccl/upgradeccl/upgradessccl/seed_span_counts_external_test.go index 4ec6d4bba70f..38dc65b15f72 100644 --- a/pkg/ccl/migrationccl/migrationsccl/seed_span_counts_external_test.go +++ b/pkg/ccl/upgradeccl/upgradessccl/seed_span_counts_external_test.go @@ -6,7 +6,7 @@ // // https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt -package migrationsccl_test +package upgradessccl_test import ( "context" @@ -105,7 +105,7 @@ func TestPreSeedSpanCountTable(t *testing.T) { require.Equal(t, 5, spanCount) } -// TestSeedSpanCountTable tests that the migration seeds system.span_count +// TestSeedSpanCountTable tests that the upgrade seeds system.span_count // correctly for secondary tenants. func TestSeedSpanCountTable(t *testing.T) { defer leaktest.AfterTest(t)() @@ -171,7 +171,7 @@ func TestSeedSpanCountTable(t *testing.T) { require.Equal(t, 3, spanCount) } -// TestSeedSpanCountTableOverLimit tests that the migration seeds +// TestSeedSpanCountTableOverLimit tests that the upgrade seeds // system.span_count correctly for secondary tenants, even if over the // proscribed limit. In these cases the tenant goes into debt -- all subsequent // schema changes that add schema elements will be rejected. Attempts to free up diff --git a/pkg/ccl/migrationccl/migrationsccl/seed_tenant_span_configs_external_test.go b/pkg/ccl/upgradeccl/upgradessccl/seed_tenant_span_configs_external_test.go similarity index 97% rename from pkg/ccl/migrationccl/migrationsccl/seed_tenant_span_configs_external_test.go rename to pkg/ccl/upgradeccl/upgradessccl/seed_tenant_span_configs_external_test.go index daa712827d67..73dc0f285f4d 100644 --- a/pkg/ccl/migrationccl/migrationsccl/seed_tenant_span_configs_external_test.go +++ b/pkg/ccl/upgradeccl/upgradessccl/seed_tenant_span_configs_external_test.go @@ -6,7 +6,7 @@ // // https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt -package migrationsccl_test +package upgradessccl_test import ( "context" @@ -79,7 +79,7 @@ func TestPreSeedSpanConfigsWrittenWhenActive(t *testing.T) { } } -// TestSeedTenantSpanConfigs tests that the migration installs relevant seed +// TestSeedTenantSpanConfigs tests that the upgrade installs relevant seed // span configs for existing secondary tenants. func TestSeedTenantSpanConfigs(t *testing.T) { defer leaktest.AfterTest(t)() @@ -148,7 +148,7 @@ func TestSeedTenantSpanConfigs(t *testing.T) { } } -// TestSeedTenantSpanConfigsWithExistingEntry tests that the migration ignores +// TestSeedTenantSpanConfigsWithExistingEntry tests that the upgrade ignores // tenants with existing span config records. func TestSeedTenantSpanConfigsWithExistingEntry(t *testing.T) { defer leaktest.AfterTest(t)() diff --git a/pkg/cli/clisqlclient/statement_diag.go b/pkg/cli/clisqlclient/statement_diag.go index 110cf718e304..3c514f8094ca 100644 --- a/pkg/cli/clisqlclient/statement_diag.go +++ b/pkg/cli/clisqlclient/statement_diag.go @@ -102,7 +102,7 @@ func StmtDiagListOutstandingRequests( // TODO(yuzefovich): remove this in 22.2. func isAtLeast22dot1ClusterVersion(ctx context.Context, conn Conn) (bool, error) { - // Check whether the migration to add the conditional diagnostics columns to + // Check whether the upgrade to add the conditional diagnostics columns to // the statement_diagnostics_requests system table has already been run. row, err := conn.QueryRow(ctx, ` SELECT diff --git a/pkg/cli/mt_start_sql.go b/pkg/cli/mt_start_sql.go index 7160c4f4f7f4..e695d86c6114 100644 --- a/pkg/cli/mt_start_sql.go +++ b/pkg/cli/mt_start_sql.go @@ -102,7 +102,7 @@ func runStartSQL(cmd *cobra.Command, args []string) error { // In the initial 20.2 release of multi-tenant clusters, no version state was // ever populated in the version cluster setting. A value is populated during // the activation of 21.1. See the documentation attached to the TenantCluster - // in migration/migrationcluster for more details on the tenant upgrade flow. + // in upgrade/upgradecluster for more details on the tenant upgrade flow. // Note that a the value of 21.1 is populated when a tenant cluster is created // during 21.1 in crdb_internal.create_tenant. // diff --git a/pkg/clusterversion/clusterversion.go b/pkg/clusterversion/clusterversion.go index 1ecbbeb665ed..a6c0ab4aa22b 100644 --- a/pkg/clusterversion/clusterversion.go +++ b/pkg/clusterversion/clusterversion.go @@ -11,7 +11,7 @@ // Package clusterversion defines the interfaces to interact with cluster/binary // versions in order accommodate backward incompatible behaviors. It handles the // feature gates and so must maintain a fairly lightweight set of dependencies. -// The migration sub-package handles advancing a cluster from one version to +// The upgrade sub-package handles advancing a cluster from one version to // a later one. // // Ideally, every code change in a database would be backward compatible, but @@ -269,7 +269,7 @@ func (cv ClusterVersion) SafeFormat(p redact.SafePrinter, _ rune) { // not it is a fence version. func (cv ClusterVersion) PrettyPrint() string { // If we're a version greater than v20.2 and have an odd internal version, - // we're a fence version. See fenceVersionFor in pkg/migration to understand + // we're a fence version. See fenceVersionFor in pkg/upgrade to understand // what these are. fenceVersion := !cv.Version.LessEq(roachpb.Version{Major: 20, Minor: 2}) && (cv.Internal%2) == 1 if !fenceVersion { diff --git a/pkg/clusterversion/keyed_versions.go b/pkg/clusterversion/keyed_versions.go index 3f4ae584fe14..83c0a1fda22d 100644 --- a/pkg/clusterversion/keyed_versions.go +++ b/pkg/clusterversion/keyed_versions.go @@ -89,7 +89,7 @@ func (kv keyedVersions) Validate() error { // a bit more lenient and allow one more release cycle until validation fails. // In the above example, we would tolerate 20.1-x but not 19.2-x. // Currently we're actually a few versions behind in enforcing a ban on old - // versions/migrations. See #47447. + // versions/upgrades. See #47447. if n := len(byRelease) - 5; n >= 0 { var buf strings.Builder for i, mami := range byRelease[:n+1] { diff --git a/pkg/clusterversion/setting.go b/pkg/clusterversion/setting.go index 87e2cafc1887..abe9c1437b3a 100644 --- a/pkg/clusterversion/setting.go +++ b/pkg/clusterversion/setting.go @@ -25,7 +25,7 @@ const KeyVersionSetting = "version" // version represents the cluster's "active version". This is a cluster setting, // but a special one. It can only advance to higher and higher versions. The -// setting can be used to see if migrations are to be considered enabled or +// setting can be used to see if upgrades are to be considered enabled or // disabled through the `isActive()` method. All external usage of the cluster // settings takes place through a Handle and `Initialize()`. // diff --git a/pkg/config/system_test.go b/pkg/config/system_test.go index f5a06a3eb513..b31c1b0d4351 100644 --- a/pkg/config/system_test.go +++ b/pkg/config/system_test.go @@ -315,12 +315,12 @@ func TestComputeSplitKeySystemRanges(t *testing.T) { {roachpb.RKey(keys.NodeLivenessPrefix), roachpb.RKey(keys.NodeLivenessKeyMax), nil}, {roachpb.RKey(keys.NodeLivenessPrefix), roachpb.RKeyMax, keys.NodeLivenessKeyMax}, {roachpb.RKey(keys.NodeLivenessKeyMax), roachpb.RKeyMax, keys.TimeseriesPrefix}, - {roachpb.RKey(keys.MigrationPrefix), roachpb.RKey(keys.NodeLivenessPrefix), nil}, - {roachpb.RKey(keys.MigrationPrefix), roachpb.RKey(keys.NodeLivenessKeyMax), nil}, - {roachpb.RKey(keys.MigrationPrefix), roachpb.RKey(keys.StoreIDGenerator), nil}, - {roachpb.RKey(keys.MigrationPrefix), roachpb.RKey(keys.TimeseriesPrefix), nil}, - {roachpb.RKey(keys.MigrationPrefix), roachpb.RKey(keys.TimeseriesPrefix.Next()), keys.TimeseriesPrefix}, - {roachpb.RKey(keys.MigrationPrefix), roachpb.RKeyMax, keys.TimeseriesPrefix}, + {roachpb.RKey(keys.StartupMigrationPrefix), roachpb.RKey(keys.NodeLivenessPrefix), nil}, + {roachpb.RKey(keys.StartupMigrationPrefix), roachpb.RKey(keys.NodeLivenessKeyMax), nil}, + {roachpb.RKey(keys.StartupMigrationPrefix), roachpb.RKey(keys.StoreIDGenerator), nil}, + {roachpb.RKey(keys.StartupMigrationPrefix), roachpb.RKey(keys.TimeseriesPrefix), nil}, + {roachpb.RKey(keys.StartupMigrationPrefix), roachpb.RKey(keys.TimeseriesPrefix.Next()), keys.TimeseriesPrefix}, + {roachpb.RKey(keys.StartupMigrationPrefix), roachpb.RKeyMax, keys.TimeseriesPrefix}, {roachpb.RKey(keys.TimeseriesPrefix), roachpb.RKey(keys.TimeseriesPrefix.Next()), nil}, {roachpb.RKey(keys.TimeseriesPrefix), roachpb.RKey(keys.TimeseriesPrefix.PrefixEnd()), nil}, {roachpb.RKey(keys.TimeseriesPrefix), roachpb.RKeyMax, keys.TimeseriesPrefix.PrefixEnd()}, @@ -557,7 +557,7 @@ func TestGetZoneConfigForKey(t *testing.T) { {roachpb.RKey(keys.MetaMax), keys.SystemRangesID}, {roachpb.RKey(keys.SystemPrefix), keys.SystemRangesID}, {roachpb.RKey(keys.SystemPrefix.Next()), keys.SystemRangesID}, - {roachpb.RKey(keys.MigrationLease), keys.SystemRangesID}, + {roachpb.RKey(keys.StartupMigrationLease), keys.SystemRangesID}, {roachpb.RKey(keys.NodeLivenessPrefix), keys.LivenessRangesID}, {roachpb.RKey(keys.SystemSQLCodec.DescIDSequenceKey()), keys.SystemRangesID}, {roachpb.RKey(keys.NodeIDGenerator), keys.SystemRangesID}, diff --git a/pkg/keys/constants.go b/pkg/keys/constants.go index c26a935135b8..e8298374857a 100644 --- a/pkg/keys/constants.go +++ b/pkg/keys/constants.go @@ -291,11 +291,11 @@ var ( // StatusNodePrefix stores all status info for nodes. StatusNodePrefix = roachpb.Key(makeKey(StatusPrefix, roachpb.RKey("node-"))) // - // MigrationPrefix specifies the key prefix to store all migration details. - MigrationPrefix = roachpb.Key(makeKey(SystemPrefix, roachpb.RKey("system-version/"))) - // MigrationLease is the key that nodes must take a lease on in order to run + // StartupMigrationPrefix specifies the key prefix to store all migration details. + StartupMigrationPrefix = roachpb.Key(makeKey(SystemPrefix, roachpb.RKey("system-version/"))) + // StartupMigrationLease is the key that nodes must take a lease on in order to run // system migrations on the cluster. - MigrationLease = roachpb.Key(makeKey(MigrationPrefix, roachpb.RKey("lease"))) + StartupMigrationLease = roachpb.Key(makeKey(StartupMigrationPrefix, roachpb.RKey("lease"))) // // TimeseriesPrefix is the key prefix for all timeseries data. TimeseriesPrefix = roachpb.Key(makeKey(SystemPrefix, roachpb.RKey("tsd"))) diff --git a/pkg/keys/doc.go b/pkg/keys/doc.go index 2bda3c4b54c9..6a24c5a14954 100644 --- a/pkg/keys/doc.go +++ b/pkg/keys/doc.go @@ -254,8 +254,8 @@ var _ = [...]interface{}{ StatusPrefix, // "status-" StatusNodePrefix, // "status-node-" StoreIDGenerator, // "store-idgen" - MigrationPrefix, // "system-version/" - MigrationLease, // "system-version/lease" + StartupMigrationPrefix, // "system-version/" + StartupMigrationLease, // "system-version/lease" TimeseriesPrefix, // "tsd" SystemSpanConfigPrefix, // "xffsys-scfg" SystemMax, diff --git a/pkg/keys/sql.go b/pkg/keys/sql.go index d2a4654a4823..0c2c3982b34d 100644 --- a/pkg/keys/sql.go +++ b/pkg/keys/sql.go @@ -163,15 +163,16 @@ func (e sqlEncoder) ZoneKey(id uint32) roachpb.Key { return MakeFamilyKey(k, uint32(ZonesTableConfigColumnID)) } -// MigrationKeyPrefix returns the key prefix to store all migration details. -func (e sqlEncoder) MigrationKeyPrefix() roachpb.Key { - return append(e.TenantPrefix(), MigrationPrefix...) +// StartupMigrationKeyPrefix returns the key prefix to store all startup +// migration details. +func (e sqlEncoder) StartupMigrationKeyPrefix() roachpb.Key { + return append(e.TenantPrefix(), StartupMigrationPrefix...) } -// MigrationLeaseKey returns the key that nodes must take a lease on in order to -// run system migrations on the cluster. -func (e sqlEncoder) MigrationLeaseKey() roachpb.Key { - return append(e.TenantPrefix(), MigrationLease...) +// StartupMigrationLeaseKey returns the key that nodes must take a lease on in +// order to run startup migration upgrades on the cluster. +func (e sqlEncoder) StartupMigrationLeaseKey() roachpb.Key { + return append(e.TenantPrefix(), StartupMigrationLease...) } // unexpected to avoid colliding with sqlEncoder.tenantPrefix. diff --git a/pkg/roachprod/vm/azure/doc.go b/pkg/roachprod/vm/azure/doc.go index 4f1dab266007..7ec56825f3f1 100644 --- a/pkg/roachprod/vm/azure/doc.go +++ b/pkg/roachprod/vm/azure/doc.go @@ -45,6 +45,6 @@ // each location that clusters may be deployed into. Each NIC that is // created will be bound to a common subnet. All of the managed VNets // are peered together. This allows arbitrary connectivity between -// roachprod-managed clusters (e.g. to test cluster migration +// roachprod-managed clusters (e.g. to test cluster upgrade // strategies). package azure diff --git a/pkg/server/BUILD.bazel b/pkg/server/BUILD.bazel index 5fcddd29edc8..eae2318c43c4 100644 --- a/pkg/server/BUILD.bazel +++ b/pkg/server/BUILD.bazel @@ -110,9 +110,6 @@ go_library( "//pkg/kv/kvserver/protectedts/ptreconcile", "//pkg/kv/kvserver/rangefeed", "//pkg/kv/kvserver/reports", - "//pkg/migration", - "//pkg/migration/migrationcluster", - "//pkg/migration/migrationmanager", "//pkg/multitenant", "//pkg/multitenant/tenantcostmodel", "//pkg/roachpb", @@ -212,6 +209,9 @@ go_library( "//pkg/ts", "//pkg/ts/catalog", "//pkg/ui", + "//pkg/upgrade", + "//pkg/upgrade/upgradecluster", + "//pkg/upgrade/upgrademanager", "//pkg/util", "//pkg/util/admission", "//pkg/util/buildutil", @@ -378,8 +378,6 @@ go_test( "//pkg/kv/kvserver/kvserverpb", "//pkg/kv/kvserver/liveness", "//pkg/kv/kvserver/liveness/livenesspb", - "//pkg/migration", - "//pkg/migration/migrations", "//pkg/roachpb", "//pkg/rpc", "//pkg/security", @@ -420,6 +418,8 @@ go_test( "//pkg/ts/catalog", "//pkg/ts/tspb", "//pkg/ui", + "//pkg/upgrade", + "//pkg/upgrade/upgrades", "//pkg/util", "//pkg/util/envutil", "//pkg/util/grpcutil", diff --git a/pkg/server/admin.go b/pkg/server/admin.go index 26cbe4ca8102..078f45f89c4a 100644 --- a/pkg/server/admin.go +++ b/pkg/server/admin.go @@ -2863,7 +2863,7 @@ func (s *adminServer) enqueueRangeLocal( // should stop sending "gc" in v22.2. When removing, confirm that the // associated TODO in index.tsx was addressed in the previous release. // - // Explanation of migration: + // Explanation of upgrade: // - v22.1 will understand "gc" and "mvccGC" on the server. Its client will // continue to send "gc" to interop with v21.2 servers. // - v22.2's client will send "mvccGC" but will still have to understand "gc" diff --git a/pkg/server/migration.go b/pkg/server/migration.go index 03f70c0a2495..defa536fef6e 100644 --- a/pkg/server/migration.go +++ b/pkg/server/migration.go @@ -26,7 +26,7 @@ import ( ) // migrationServer is an implementation of the Migration service. The RPCs here -// are used to power the migrations infrastructure in pkg/migrations. +// are used to power the upgrades infrastructure in pkg/upgrades. type migrationServer struct { server *Server @@ -60,7 +60,7 @@ func (m *migrationServer) ValidateTargetClusterVersion( } // TODO(irfansharif): These errors are propagated all the way back to the - // user during improper version upgrades. Given the migrations + // user during improper version upgrades. Given the upgrades // infrastructure is stepping through internal versions during major cluster // version upgrades, and given we don't use negative internal versions (as // suggested in #33578), it currently manifests (see diff --git a/pkg/server/migration_test.go b/pkg/server/migration_test.go index f5f1b007bc5a..5d0efa6df526 100644 --- a/pkg/server/migration_test.go +++ b/pkg/server/migration_test.go @@ -237,7 +237,7 @@ func TestMigrationPurgeOutdatedReplicas(t *testing.T) { } // TestUpgradeHappensAfterMigration is a regression test to ensure that -// migrations run prior to attempting to upgrade the cluster to the current +// upgrades run prior to attempting to upgrade the cluster to the current // version. func TestUpgradeHappensAfterMigrations(t *testing.T) { defer leaktest.AfterTest(t)() diff --git a/pkg/server/node.go b/pkg/server/node.go index 5ee72c7ba55c..ec9c2d942531 100644 --- a/pkg/server/node.go +++ b/pkg/server/node.go @@ -534,8 +534,8 @@ func (n *Node) start( n.admissionController.SetTenantWeightProvider(n, n.stopper) // Be careful about moving this line above where we start stores; store - // migrations rely on the fact that the cluster version has not been updated - // via Gossip (we have migrations that want to run only if the server starts + // upgrades rely on the fact that the cluster version has not been updated + // via Gossip (we have upgrades that want to run only if the server starts // with a given cluster version, but not if the server starts with a lower // one and gets bumped immediately, which would be possible if gossip got // started earlier). @@ -1541,7 +1541,7 @@ func (n *Node) Join( // manually create a liveness record to maintain this same invariant. // // NB: This invariant will be required for when we introduce long running - // migrations. See https://github.com/cockroachdb/cockroach/pull/48843 for + // upgrades. See https://github.com/cockroachdb/cockroach/pull/48843 for // details. if err := n.storeCfg.NodeLiveness.CreateLivenessRecord(ctx, nodeID); err != nil { return nil, err diff --git a/pkg/server/server.go b/pkg/server/server.go index 9c5ba94de2d6..7439e7eae6fe 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -1066,7 +1066,7 @@ func (s *Server) PreStart(ctx context.Context) error { serverpb.RegisterInitServer(s.grpc.Server, initServer) - // Register the Migration service, to power internal crdb migrations. + // Register the Migration service, to power internal crdb upgrades. migrationServer := &migrationServer{server: s} serverpb.RegisterMigrationServer(s.grpc.Server, migrationServer) s.migrationServer = migrationServer // only for testing via TestServer diff --git a/pkg/server/server_sql.go b/pkg/server/server_sql.go index 5262dbc7a8f9..07e552146505 100644 --- a/pkg/server/server_sql.go +++ b/pkg/server/server_sql.go @@ -34,9 +34,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv/kvserver" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/protectedts" - "github.com/cockroachdb/cockroach/pkg/migration" - "github.com/cockroachdb/cockroach/pkg/migration/migrationcluster" - "github.com/cockroachdb/cockroach/pkg/migration/migrationmanager" "github.com/cockroachdb/cockroach/pkg/multitenant" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/rpc" @@ -95,6 +92,9 @@ import ( "github.com/cockroachdb/cockroach/pkg/startupmigrations" "github.com/cockroachdb/cockroach/pkg/storage" "github.com/cockroachdb/cockroach/pkg/storage/fs" + "github.com/cockroachdb/cockroach/pkg/upgrade" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgradecluster" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrademanager" "github.com/cockroachdb/cockroach/pkg/util" "github.com/cockroachdb/cockroach/pkg/util/admission" "github.com/cockroachdb/cockroach/pkg/util/envutil" @@ -186,7 +186,7 @@ type sqlServerOptionalKVArgs struct { // nodesStatusServer gives access to the NodesStatus service. nodesStatusServer serverpb.OptionalNodesStatusServer // Narrowed down version of *NodeLiveness. Used by jobs, DistSQLPlanner, and - // migration manager. + // upgrade manager. nodeLiveness optionalnodeliveness.Container // Gossip is relied upon by distSQLCfg (execinfra.ServerConfig), the executor // config, the DistSQL planner, the table statistics cache, the statements @@ -938,36 +938,36 @@ func newSQLServer(ctx context.Context, cfg sqlServerArgs) (*SQLServer, error) { // We only need to attach a version upgrade hook if we're the system // tenant. Regular tenants are disallowed from changing cluster // versions. - var c migration.Cluster - var systemDeps migration.SystemDeps + var c upgrade.Cluster + var systemDeps upgrade.SystemDeps if codec.ForSystemTenant() { - c = migrationcluster.New(migrationcluster.ClusterConfig{ + c = upgradecluster.New(upgradecluster.ClusterConfig{ NodeLiveness: nodeLiveness, Dialer: cfg.nodeDialer, DB: cfg.db, }) - systemDeps = migration.SystemDeps{ + systemDeps = upgrade.SystemDeps{ Cluster: c, DB: cfg.db, DistSender: cfg.distSender, Stopper: cfg.stopper, } } else { - c = migrationcluster.NewTenantCluster(cfg.db) - systemDeps = migration.SystemDeps{ + c = upgradecluster.NewTenantCluster(cfg.db) + systemDeps = upgrade.SystemDeps{ Cluster: c, DB: cfg.db, } } - knobs, _ := cfg.TestingKnobs.MigrationManager.(*migration.TestingKnobs) - migrationMgr := migrationmanager.NewManager( + knobs, _ := cfg.TestingKnobs.UpgradeManager.(*upgrade.TestingKnobs) + migrationMgr := upgrademanager.NewManager( systemDeps, leaseMgr, cfg.circularInternalExecutor, jobRegistry, codec, cfg.Settings, knobs, ) - execCfg.MigrationJobDeps = migrationMgr + execCfg.UpgradeJobDeps = migrationMgr execCfg.VersionUpgradeHook = migrationMgr.Migrate - execCfg.MigrationTestingKnobs = knobs + execCfg.UpgradeTestingKnobs = knobs } if !codec.ForSystemTenant() || !cfg.SpanConfigsDisabled { @@ -1207,7 +1207,7 @@ func (s *SQLServer) preStart( &sessiondata.SessionData{ LocalOnlySessionData: sessiondatapb.LocalOnlySessionData{ // Migrations need an executor with query distribution turned off. This is - // because the node crashes if migrations fail to execute, and query + // because the node crashes if upgrades fail to execute, and query // distribution introduces more moving parts. Local execution is more // robust; for example, the DistSender has retries if it can't connect to // another node, but DistSQL doesn't. Also see #44101 for why DistSQL is @@ -1259,9 +1259,9 @@ func (s *SQLServer) preStart( // and pass a lower-bound on the bootstrap version. We know that no tenants // could have been created before the start of the v20.2 dev cycle, so we // pass Start20_2. bootstrapVersion is only used to avoid performing - // superfluous but necessarily idempotent SQL migrations, so at worst, we're + // superfluous but necessarily idempotent SQL upgrades, so at worst, we're // doing more work than strictly necessary during the first time that the - // migrations are run. + // upgrades are run. bootstrapVersion = roachpb.Version{Major: 20, Minor: 1, Internal: 1} } @@ -1272,7 +1272,7 @@ func (s *SQLServer) preStart( return errors.Wrap(err, "initializing settings") } - // Run startup migrations (note: these depend on jobs subsystem running). + // Run startup upgrades (note: these depend on jobs subsystem running). if err := startupMigrationsMgr.EnsureMigrations(ctx, bootstrapVersion); err != nil { return errors.Wrap(err, "ensuring SQL migrations") } diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 385821fd2f20..faeec3130a39 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -455,7 +455,7 @@ func TestSystemConfigGossip(t *testing.T) { t.Fatal(err) } - // This has to be wrapped in a SucceedSoon because system migrations on the + // This has to be wrapped in a SucceedSoon because system upgrades on the // testserver's startup can trigger system config updates without the key we // wrote. testutils.SucceedsSoon(t, func() error { diff --git a/pkg/server/version_cluster_test.go b/pkg/server/version_cluster_test.go index 87510b778f27..73ed304d1715 100644 --- a/pkg/server/version_cluster_test.go +++ b/pkg/server/version_cluster_test.go @@ -22,14 +22,14 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/kv/kvserver" - "github.com/cockroachdb/cockroach/pkg/migration" - "github.com/cockroachdb/cockroach/pkg/migration/migrations" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/server" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" + "github.com/cockroachdb/cockroach/pkg/upgrade" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/protoutil" @@ -115,7 +115,7 @@ func setupMixedCluster( }) // We simulate crashes using this cluster, and having this enabled (which is - // a default migration) causes leaktest to complain. + // a default upgrade) causes leaktest to complain. if _, err := tc.ServerConn(0).Exec("SET CLUSTER SETTING diagnostics.reporting.enabled = 'false'"); err != nil { t.Fatal(err) } @@ -417,22 +417,22 @@ func TestClusterVersionMixedVersionTooOld(t *testing.T) { DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: v0, }, - // Inject a migration which would run to upgrade the cluster. - // We'll validate that we never create a job for this migration. - MigrationManager: &migration.TestingKnobs{ + // Inject an upgrade which would run to upgrade the cluster. + // We'll validate that we never create a job for this upgrade. + UpgradeManager: &upgrade.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { return []clusterversion.ClusterVersion{to} }, - RegistryOverride: func(cv clusterversion.ClusterVersion) (migration.Migration, bool) { + RegistryOverride: func(cv clusterversion.ClusterVersion) (upgrade.Upgrade, bool) { if !cv.Version.Equal(v1) { return nil, false } - return migration.NewTenantMigration("testing", clusterversion.ClusterVersion{ + return upgrade.NewTenantUpgrade("testing", clusterversion.ClusterVersion{ Version: v1, }, - migrations.NoPrecondition, + upgrades.NoPrecondition, func( - ctx context.Context, version clusterversion.ClusterVersion, deps migration.TenantDeps, _ *jobs.Job, + ctx context.Context, version clusterversion.ClusterVersion, deps upgrade.TenantDeps, _ *jobs.Job, ) error { return nil }), true @@ -470,10 +470,10 @@ func TestClusterVersionMixedVersionTooOld(t *testing.T) { }) } - // Ensure that no migration jobs got created. + // Ensure that no upgrade jobs got created. { sqlutils.MakeSQLRunner(tc.ServerConn(0)).CheckQueryResults( - t, "SELECT * FROM crdb_internal.jobs WHERE job_type = 'MIGRATION'", [][]string{}) + t, "SELECT * FROM crdb_internal.jobs WHERE job_type = 'upgrade'", [][]string{}) } // Check that we can still talk to the first three nodes. diff --git a/pkg/sql/BUILD.bazel b/pkg/sql/BUILD.bazel index c5a18204c34d..1829c70738c8 100644 --- a/pkg/sql/BUILD.bazel +++ b/pkg/sql/BUILD.bazel @@ -276,7 +276,6 @@ go_library( "//pkg/kv/kvserver/kvserverbase", "//pkg/kv/kvserver/liveness/livenesspb", "//pkg/kv/kvserver/protectedts", - "//pkg/migration", "//pkg/multitenant", "//pkg/roachpb", "//pkg/rpc", @@ -416,6 +415,7 @@ go_library( "//pkg/sql/vtable", "//pkg/storage/enginepb", "//pkg/testutils/serverutils", + "//pkg/upgrade", "//pkg/util", "//pkg/util/admission", "//pkg/util/admission/admissionpb", diff --git a/pkg/sql/create_test.go b/pkg/sql/create_test.go index 1ffd82159cd6..fbbbd8834c9b 100644 --- a/pkg/sql/create_test.go +++ b/pkg/sql/create_test.go @@ -446,7 +446,7 @@ func TestAutoStatsTableSettingsDisallowedOnOldCluster(t *testing.T) { sqlDB.ExpectErr(t, "pq: auto stats table settings are only available once the cluster is fully upgraded", "ALTER TABLE t2 SET (sql_stats_automatic_collection_enabled = true)") - // Run the migration. + // Run the upgrade. sqlDB.Exec(t, "SET CLUSTER SETTING version = $1", clusterversion.ByKey(clusterversion.AutoStatsTableSettings).String()) sqlDB.Exec(t, diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go index 89aef4030f01..971b410adb7d 100644 --- a/pkg/sql/exec_util.go +++ b/pkg/sql/exec_util.go @@ -43,7 +43,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv/kvclient/rangefeed" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/protectedts" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/multitenant" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/rpc" @@ -96,6 +95,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/stmtdiagnostics" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util/bitarray" "github.com/cockroachdb/cockroach/pkg/util/duration" "github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" @@ -1207,7 +1207,7 @@ type ExecutorConfig struct { InternalRowMetrics *rowinfra.Metrics TestingKnobs ExecutorTestingKnobs - MigrationTestingKnobs *migration.TestingKnobs + UpgradeTestingKnobs *upgrade.TestingKnobs PGWireTestingKnobs *PGWireTestingKnobs SchemaChangerTestingKnobs *SchemaChangerTestingKnobs DeclarativeSchemaChangerTestingKnobs *scrun.TestingKnobs @@ -1252,12 +1252,12 @@ type ExecutorConfig struct { RangeFeedFactory *rangefeed.Factory // VersionUpgradeHook is called after validating a `SET CLUSTER SETTING - // version` but before executing it. It can carry out arbitrary migrations + // version` but before executing it. It can carry out arbitrary upgrades // that allow us to eventually remove legacy code. VersionUpgradeHook VersionUpgradeHook - // MigrationJobDeps is used to drive migrations. - MigrationJobDeps migration.JobDeps + // UpgradeJobDeps is used to drive upgrades. + UpgradeJobDeps upgrade.JobDeps // IndexBackfiller is used to backfill indexes. It is another rather circular // object which mostly just holds on to an ExecConfig. @@ -1301,10 +1301,10 @@ type ExecutorConfig struct { SystemTableIDResolver catalog.SystemTableIDResolver // SpanConfigReconciler is used to drive the span config reconciliation job - // and related migrations. + // and related upgrades. SpanConfigReconciler spanconfig.Reconciler - // SpanConfigSplitter is used during migrations to seed system.span_count with + // SpanConfigSplitter is used during upgrades to seed system.span_count with // the right number of tenant spans. SpanConfigSplitter spanconfig.Splitter @@ -1331,8 +1331,8 @@ type ExecutorConfig struct { // UpdateVersionSystemSettingHook provides a callback that allows us // update the cluster version inside the system.settings table. This hook // is aimed at mainly updating tenant pods, which will currently skip over -// the existing migration logic for bumping version numbers (this logic is -// stubbed out for them). As a result there is a potential danger of migrations +// the existing upgrade logic for bumping version numbers (this logic is +// stubbed out for them). As a result there is a potential danger of upgrades // partially being completed without the version number being persisted to storage // for tenants. This hook allows the version number to bumped and saved at // each step. @@ -1341,7 +1341,7 @@ type UpdateVersionSystemSettingHook func( version clusterversion.ClusterVersion, ) error -// VersionUpgradeHook is used to run migrations starting in v21.1. +// VersionUpgradeHook is used to run upgrades starting in v21.1. type VersionUpgradeHook func( ctx context.Context, user username.SQLUsername, diff --git a/pkg/sql/importer/import_table_creation.go b/pkg/sql/importer/import_table_creation.go index fef075b0a055..1d9b7c1141f7 100644 --- a/pkg/sql/importer/import_table_creation.go +++ b/pkg/sql/importer/import_table_creation.go @@ -68,7 +68,7 @@ func MakeTestingSimpleTableDescriptor( var sc catalog.SchemaDescriptor if !st.Version.IsActive(ctx, clusterversion.PublicSchemasWithDescriptors) && parentSchemaID == keys.PublicSchemaIDForBackup { // If we're not on version PublicSchemasWithDescriptors, continue to - // use a synthetic public schema, the migration when we update to + // use a synthetic public schema, the upgrade when we update to // PublicSchemasWithDescriptors will handle creating the explicit public // schema. sc = schemadesc.GetPublicSchema() diff --git a/pkg/sql/indexbackfiller_test.go b/pkg/sql/indexbackfiller_test.go index c0586a32dcd2..3912799fed35 100644 --- a/pkg/sql/indexbackfiller_test.go +++ b/pkg/sql/indexbackfiller_test.go @@ -87,7 +87,7 @@ func TestIndexBackfiller(t *testing.T) { <-moveToBackfill }, }, - // Disable backfill migrations, we still need the jobs table migration. + // Disable backfill upgrades, we still need the jobs table upgrade. StartupMigrationManager: &startupmigrations.MigrationManagerTestingKnobs{ DisableBackfillMigrations: true, }, diff --git a/pkg/sql/job_exec_context.go b/pkg/sql/job_exec_context.go index bddad9ab30ac..bae9e6643d95 100644 --- a/pkg/sql/job_exec_context.go +++ b/pkg/sql/job_exec_context.go @@ -14,7 +14,6 @@ import ( "context" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/spanconfig" @@ -24,6 +23,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" "github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) // plannerJobExecContext is a wrapper to implement JobExecContext with a planner @@ -64,7 +64,7 @@ func (e *plannerJobExecContext) ExecCfg() *ExecutorConfig { return e.p.Ex func (e *plannerJobExecContext) DistSQLPlanner() *DistSQLPlanner { return e.p.DistSQLPlanner() } func (e *plannerJobExecContext) LeaseMgr() *lease.Manager { return e.p.LeaseMgr() } func (e *plannerJobExecContext) User() username.SQLUsername { return e.p.User() } -func (e *plannerJobExecContext) MigrationJobDeps() migration.JobDeps { +func (e *plannerJobExecContext) MigrationJobDeps() upgrade.JobDeps { return e.p.MigrationJobDeps() } func (e *plannerJobExecContext) SpanConfigReconciler() spanconfig.Reconciler { @@ -102,7 +102,7 @@ type JobExecContext interface { DistSQLPlanner() *DistSQLPlanner LeaseMgr() *lease.Manager User() username.SQLUsername - MigrationJobDeps() migration.JobDeps + MigrationJobDeps() upgrade.JobDeps SpanConfigReconciler() spanconfig.Reconciler Txn() *kv.Txn } diff --git a/pkg/sql/job_exec_context_test_util.go b/pkg/sql/job_exec_context_test_util.go index dd0a7a781d93..044d5c73d5b3 100644 --- a/pkg/sql/job_exec_context_test_util.go +++ b/pkg/sql/job_exec_context_test_util.go @@ -11,12 +11,12 @@ package sql import ( - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/spanconfig" "github.com/cockroachdb/cockroach/pkg/sql/catalog/lease" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) // FakeJobExecContext is used for mocking the JobExecContext in tests. @@ -66,7 +66,7 @@ func (p *FakeJobExecContext) User() username.SQLUsername { } // MigrationJobDeps implements the JobExecContext interface. -func (p *FakeJobExecContext) MigrationJobDeps() migration.JobDeps { +func (p *FakeJobExecContext) MigrationJobDeps() upgrade.JobDeps { panic("unimplemented") } diff --git a/pkg/sql/logictest/BUILD.bazel b/pkg/sql/logictest/BUILD.bazel index 2388a9cee420..423046cbeb35 100644 --- a/pkg/sql/logictest/BUILD.bazel +++ b/pkg/sql/logictest/BUILD.bazel @@ -17,7 +17,6 @@ go_library( "//pkg/build/bazel", "//pkg/clusterversion", "//pkg/kv/kvserver", - "//pkg/migration", "//pkg/roachpb", "//pkg/security/username", "//pkg/server", @@ -39,6 +38,7 @@ go_library( "//pkg/testutils/serverutils", "//pkg/testutils/skip", "//pkg/testutils/sqlutils", + "//pkg/upgrade", "//pkg/util", "//pkg/util/envutil", "//pkg/util/log", diff --git a/pkg/sql/logictest/logic.go b/pkg/sql/logictest/logic.go index 9deae01a7ae3..5909c89ac3b0 100644 --- a/pkg/sql/logictest/logic.go +++ b/pkg/sql/logictest/logic.go @@ -43,7 +43,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/build/bazel" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/kv/kvserver" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server" @@ -65,6 +64,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/testutils/skip" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util" "github.com/cockroachdb/cockroach/pkg/util/envutil" "github.com/cockroachdb/cockroach/pkg/util/log" @@ -1749,10 +1749,10 @@ func (t *logicTest) newCluster( from := clusterversion.ClusterVersion{Version: cfg.bootstrapVersion} to := clusterversion.ClusterVersion{Version: cfg.binaryVersion} if len(clusterversion.ListBetween(from, to)) == 0 { - mm, ok := nodeParams.Knobs.MigrationManager.(*migration.TestingKnobs) + mm, ok := nodeParams.Knobs.UpgradeManager.(*upgrade.TestingKnobs) if !ok { - mm = &migration.TestingKnobs{} - nodeParams.Knobs.MigrationManager = mm + mm = &upgrade.TestingKnobs{} + nodeParams.Knobs.UpgradeManager = mm } mm.ListBetweenOverride = func( from, to clusterversion.ClusterVersion, diff --git a/pkg/sql/metric_util_test.go b/pkg/sql/metric_util_test.go index 817c70803fb4..bb2ac30876df 100644 --- a/pkg/sql/metric_util_test.go +++ b/pkg/sql/metric_util_test.go @@ -20,7 +20,7 @@ import ( ) // initializeQueryCounter returns a queryCounter that accounts for system -// migrations that may have run DDL statements. +// upgrades that may have run DDL statements. func initializeQueryCounter(s serverutils.TestServerInterface) queryCounter { return queryCounter{ txnBeginCount: s.MustGetSQLCounter(sql.MetaTxnBeginStarted.Name), diff --git a/pkg/sql/mvcc_backfiller_test.go b/pkg/sql/mvcc_backfiller_test.go index fd96253bcfe3..0a425b569b69 100644 --- a/pkg/sql/mvcc_backfiller_test.go +++ b/pkg/sql/mvcc_backfiller_test.go @@ -121,7 +121,7 @@ func TestIndexBackfillMergeRetry(t *testing.T) { }, }, }, - // Disable backfill migrations, we still need the jobs table migration. + // Disable backfill upgrades, we still need the jobs table upgrade. StartupMigrationManager: &startupmigrations.MigrationManagerTestingKnobs{ DisableBackfillMigrations: true, }, diff --git a/pkg/sql/opt_catalog.go b/pkg/sql/opt_catalog.go index 14872d71b07e..aedf02926313 100644 --- a/pkg/sql/opt_catalog.go +++ b/pkg/sql/opt_catalog.go @@ -808,7 +808,7 @@ func newOptTable( // Set up any registered system columns. However, we won't add the column // in case a non-system column with the same name already exists in the table. - // This check is done for migration purposes. We need to avoid adding the + // This check is done for upgrade purposes. We need to avoid adding the // system column if the table has a column with this name for some reason. for _, sysCol := range ot.desc.SystemColumns() { found, _ := desc.FindColumnWithName(sysCol.ColName()) diff --git a/pkg/sql/planhook.go b/pkg/sql/planhook.go index cb38eacc8229..24fb361598e6 100644 --- a/pkg/sql/planhook.go +++ b/pkg/sql/planhook.go @@ -14,7 +14,6 @@ import ( "context" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/spanconfig" @@ -29,6 +28,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util/tracing" ) @@ -109,7 +109,7 @@ type PlanHookState interface { ) (string, error) CreateSchemaNamespaceEntry(ctx context.Context, schemaNameKey roachpb.Key, schemaID descpb.ID) error - MigrationJobDeps() migration.JobDeps + MigrationJobDeps() upgrade.JobDeps SpanConfigReconciler() spanconfig.Reconciler BufferClientNotice(ctx context.Context, notice pgnotice.Notice) Txn() *kv.Txn diff --git a/pkg/sql/planner.go b/pkg/sql/planner.go index 544229d9117d..4be9aa7f90b4 100644 --- a/pkg/sql/planner.go +++ b/pkg/sql/planner.go @@ -17,7 +17,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/spanconfig" @@ -40,6 +39,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb" "github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats" "github.com/cockroachdb/cockroach/pkg/sql/types" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util/cancelchecker" "github.com/cockroachdb/cockroach/pkg/util/envutil" "github.com/cockroachdb/cockroach/pkg/util/hlc" @@ -554,9 +554,9 @@ func (p *planner) DistSQLPlanner() *DistSQLPlanner { return p.extendedEvalCtx.DistSQLPlanner } -// MigrationJobDeps returns the migration.JobDeps. -func (p *planner) MigrationJobDeps() migration.JobDeps { - return p.execCfg.MigrationJobDeps +// MigrationJobDeps returns the upgrade.JobDeps. +func (p *planner) MigrationJobDeps() upgrade.JobDeps { + return p.execCfg.UpgradeJobDeps } // SpanConfigReconciler returns the spanconfig.Reconciler. diff --git a/pkg/sql/rowexec/backfiller_test.go b/pkg/sql/rowexec/backfiller_test.go index 7e1f758c0375..8530899777b2 100644 --- a/pkg/sql/rowexec/backfiller_test.go +++ b/pkg/sql/rowexec/backfiller_test.go @@ -77,7 +77,7 @@ func TestWriteResumeSpan(t *testing.T) { return true }, }, - // Disable backfill migrations, we still need the jobs table migration. + // Disable backfill upgrades, we still need the jobs table upgrade. StartupMigrationManager: &startupmigrations.MigrationManagerTestingKnobs{ DisableBackfillMigrations: true, }, diff --git a/pkg/sql/schema_changer.go b/pkg/sql/schema_changer.go index 9db917b7421a..9942ef5ce3af 100644 --- a/pkg/sql/schema_changer.go +++ b/pkg/sql/schema_changer.go @@ -460,7 +460,7 @@ func (sc *SchemaChanger) maybeMakeAddTablePublic( // returns. If the job is resumed only on an older node, then the // reverted schema change will continue as it would have previously. // -// TODO(ssd): Once we install a version gate and migration that drains +// TODO(ssd): Once we install a version gate and upgrade that drains // in-flight schema changes and disallows any old-style index // backfills, we can remove this extra transaction since we will know // that any reverted DROP INDEX mutations will either have already diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index f31ebf505ddf..d3df4489f7ae 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -5833,7 +5833,7 @@ value if you rely on the HLC for accuracy.`, Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.StringArray), Fn: func(ctx *eval.Context, args tree.Datums) (tree.Datum, error) { - prefix := ctx.Codec.MigrationKeyPrefix() + prefix := ctx.Codec.StartupMigrationKeyPrefix() keyvals, err := ctx.Txn.Scan(ctx.Context, prefix, prefix.PrefixEnd(), 0 /* maxRows */) if err != nil { return nil, errors.Wrapf(err, "failed to get list of completed migrations") @@ -5841,8 +5841,8 @@ value if you rely on the HLC for accuracy.`, ret := &tree.DArray{ParamTyp: types.String, Array: make(tree.Datums, 0, len(keyvals))} for _, keyval := range keyvals { key := keyval.Key - if len(key) > len(keys.MigrationPrefix) { - key = key[len(keys.MigrationPrefix):] + if len(key) > len(keys.StartupMigrationPrefix) { + key = key[len(keys.StartupMigrationPrefix):] } ret.Array = append(ret.Array, tree.NewDString(string(key))) } diff --git a/pkg/sql/sqlstats/persistedsqlstats/compaction_scheduling.go b/pkg/sql/sqlstats/persistedsqlstats/compaction_scheduling.go index 24d22a496509..91fd38685a45 100644 --- a/pkg/sql/sqlstats/persistedsqlstats/compaction_scheduling.go +++ b/pkg/sql/sqlstats/persistedsqlstats/compaction_scheduling.go @@ -34,7 +34,7 @@ var ErrDuplicatedSchedules = errors.New("creating multiple sql stats compaction // CreateSQLStatsCompactionScheduleIfNotYetExist registers SQL Stats compaction job with the // scheduled job subsystem so the compaction job can be run periodically. This -// is done during the cluster startup migration. +// is done during the cluster startup upgrade. func CreateSQLStatsCompactionScheduleIfNotYetExist( ctx context.Context, ie sqlutil.InternalExecutor, txn *kv.Txn, st *cluster.Settings, ) (*jobs.ScheduledJob, error) { diff --git a/pkg/startupmigrations/migrations.go b/pkg/startupmigrations/migrations.go index c02e1b4ca616..cea7ef0d2474 100644 --- a/pkg/startupmigrations/migrations.go +++ b/pkg/startupmigrations/migrations.go @@ -544,7 +544,7 @@ func (m *Manager) EnsureMigrations(ctx context.Context, bootstrapVersion roachpb log.Info(ctx, "trying to acquire lease") } for r := retry.StartWithCtx(ctx, base.DefaultRetryOptions()); r.Next(); { - lease, err = m.leaseManager.AcquireLease(ctx, m.codec.MigrationLeaseKey()) + lease, err = m.leaseManager.AcquireLease(ctx, m.codec.StartupMigrationLeaseKey()) if err == nil { break } @@ -668,7 +668,7 @@ func getCompletedMigrations( if log.V(1) { log.Info(ctx, "trying to get the list of completed migrations") } - prefix := codec.MigrationKeyPrefix() + prefix := codec.StartupMigrationKeyPrefix() keyvals, err := db.Scan(ctx, prefix, prefix.PrefixEnd(), 0 /* maxRows */) if err != nil { return nil, errors.Wrapf(err, "failed to get list of completed migrations") @@ -681,7 +681,7 @@ func getCompletedMigrations( } func migrationKey(codec keys.SQLCodec, migration migrationDescriptor) roachpb.Key { - return append(codec.MigrationKeyPrefix(), roachpb.RKey(migration.name)...) + return append(codec.StartupMigrationKeyPrefix(), roachpb.RKey(migration.name)...) } func extendCreateRoleWithCreateLogin(ctx context.Context, r runner) error { diff --git a/pkg/startupmigrations/migrations_test.go b/pkg/startupmigrations/migrations_test.go index 94588ed28b33..8b322678da4d 100644 --- a/pkg/startupmigrations/migrations_test.go +++ b/pkg/startupmigrations/migrations_test.go @@ -96,7 +96,7 @@ func (f *fakeDB) Scan( if f.scanErr != nil { return nil, f.scanErr } - min := f.codec.MigrationKeyPrefix() + min := f.codec.StartupMigrationKeyPrefix() max := min.PrefixEnd() if !bytes.Equal(begin.(roachpb.Key), min) { return nil, errors.Errorf("expected begin key %q, got %q", min, begin) diff --git a/pkg/migration/BUILD.bazel b/pkg/upgrade/BUILD.bazel similarity index 79% rename from pkg/migration/BUILD.bazel rename to pkg/upgrade/BUILD.bazel index 910c7527c0e7..82cda5f4d9e3 100644 --- a/pkg/migration/BUILD.bazel +++ b/pkg/upgrade/BUILD.bazel @@ -1,15 +1,15 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( - name = "migration", + name = "upgrade", srcs = [ "helpers.go", - "migration.go", - "system_migration.go", - "tenant_migration.go", + "system_upgrade.go", + "tenant_upgrade.go", "testing_knobs.go", + "upgrade.go", ], - importpath = "github.com/cockroachdb/cockroach/pkg/migration", + importpath = "github.com/cockroachdb/cockroach/pkg/upgrade", visibility = ["//visibility:public"], deps = [ "//pkg/base", diff --git a/pkg/migration/helpers.go b/pkg/upgrade/helpers.go similarity index 85% rename from pkg/migration/helpers.go rename to pkg/upgrade/helpers.go index b32c76c4eb0c..7db450fcad61 100644 --- a/pkg/migration/helpers.go +++ b/pkg/upgrade/helpers.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migration +package upgrade import ( "context" @@ -18,12 +18,12 @@ import ( ) // FenceVersionFor constructs the appropriate "fence version" for the given -// cluster version. Fence versions allow the migrations infrastructure to safely +// cluster version. Fence versions allow the upgrades infrastructure to safely // step through consecutive cluster versions in the presence of Nodes (running -// any binary version) being added to the cluster. See the migration manager +// any binary version) being added to the cluster. See the upgrade manager // above for intended usage. // -// Fence versions (and the migrations infrastructure entirely) were introduced +// Fence versions (and the upgrades infrastructure entirely) were introduced // in the 21.1 release cycle. In the same release cycle, we introduced the // invariant that new user-defined versions (users being crdb engineers) must // always have even-numbered Internal versions, thus reserving the odd numbers diff --git a/pkg/migration/nodelivenesstest/BUILD.bazel b/pkg/upgrade/nodelivenesstest/BUILD.bazel similarity index 76% rename from pkg/migration/nodelivenesstest/BUILD.bazel rename to pkg/upgrade/nodelivenesstest/BUILD.bazel index 027901493e8c..5d03ee534f6b 100644 --- a/pkg/migration/nodelivenesstest/BUILD.bazel +++ b/pkg/upgrade/nodelivenesstest/BUILD.bazel @@ -3,7 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "nodelivenesstest", srcs = ["test_node_liveness.go"], - importpath = "github.com/cockroachdb/cockroach/pkg/migration/nodelivenesstest", + importpath = "github.com/cockroachdb/cockroach/pkg/upgrade/nodelivenesstest", visibility = ["//visibility:public"], deps = [ "//pkg/kv/kvserver/liveness/livenesspb", diff --git a/pkg/migration/nodelivenesstest/test_node_liveness.go b/pkg/upgrade/nodelivenesstest/test_node_liveness.go similarity index 97% rename from pkg/migration/nodelivenesstest/test_node_liveness.go rename to pkg/upgrade/nodelivenesstest/test_node_liveness.go index e930ad1d83e1..ae6568571ecf 100644 --- a/pkg/migration/nodelivenesstest/test_node_liveness.go +++ b/pkg/upgrade/nodelivenesstest/test_node_liveness.go @@ -9,7 +9,7 @@ // licenses/APL.txt. // Package nodelivenesstest provides a mock implementation of NodeLiveness -// to facilitate testing of migration infrastructure. +// to facilitate testing of upgrade infrastructure. package nodelivenesstest import ( diff --git a/pkg/migration/system_migration.go b/pkg/upgrade/system_upgrade.go similarity index 85% rename from pkg/migration/system_migration.go rename to pkg/upgrade/system_upgrade.go index 085ec36fe4b2..1e50e1310d87 100644 --- a/pkg/migration/system_migration.go +++ b/pkg/upgrade/system_upgrade.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migration +package upgrade import ( "context" @@ -25,7 +25,7 @@ import ( ) // Cluster abstracts a physical KV cluster and can be utilized by a long-running -// migration. +// upgrade. type Cluster interface { // NumNodes returns the number of nodes in the cluster. This is merely a // convenience method and is not meant to be used to infer cluster stability; @@ -74,12 +74,12 @@ type Cluster interface { // ForEveryNode, where after we return, we can rely on the guarantee that all // nodes in the cluster will have their cluster versions bumped. This then // implies that future node additions will observe the latest version (through - // the join RPC). That in turn lets us author migrations that can assume that + // the join RPC). That in turn lets us author upgrades that can assume that // a certain version gate has been enabled on all nodes in the cluster, and // will always be enabled for any new nodes in the system. // // Given that it'll always be possible for new nodes to join after an - // UntilClusterStable round, it means that some migrations may have to be + // UntilClusterStable round, it means that some upgrades may have to be // split up into two version bumps: one that phases out the old version (i.e. // stops creation of stale data or behavior) and a cleanup version, which // removes any vestiges of the stale data/behavior, and which, when active, @@ -90,7 +90,7 @@ type Cluster interface { // IterateRangeDescriptors provides a handle on every range descriptor in the // system, which callers can then use to send out arbitrary KV requests to in - // order to run arbitrary KV-level migrations. These requests will typically + // order to run arbitrary KV-level upgrades. These requests will typically // just be the `Migrate` request, with code added within [1] to do the // specific things intended for the specified version. // @@ -127,7 +127,7 @@ type Cluster interface { ) error } -// SystemDeps are the dependencies of migrations which perform actions at the +// SystemDeps are the dependencies of upgrades which perform actions at the // KV layer on behalf of the system tenant. type SystemDeps struct { Cluster Cluster @@ -136,24 +136,24 @@ type SystemDeps struct { Stopper *stop.Stopper } -// SystemMigration is an implementation of Migration for system-level -// migrations. It is only to be run on the system tenant. These migrations +// SystemUpgrade is an implementation of Upgrade for system-level +// upgrades. It is only to be run on the system tenant. These upgrades // tend to touch the kv layer. -type SystemMigration struct { - migration - fn SystemMigrationFunc +type SystemUpgrade struct { + upgrade + fn SystemUpgradeFunc } -// SystemMigrationFunc is used to perform kv-level migrations. It should only be +// SystemUpgradeFunc is used to perform kv-level upgrades. It should only be // run from the system tenant. -type SystemMigrationFunc func(context.Context, clusterversion.ClusterVersion, SystemDeps, *jobs.Job) error +type SystemUpgradeFunc func(context.Context, clusterversion.ClusterVersion, SystemDeps, *jobs.Job) error -// NewSystemMigration constructs a SystemMigration. -func NewSystemMigration( - description string, cv clusterversion.ClusterVersion, fn SystemMigrationFunc, -) *SystemMigration { - return &SystemMigration{ - migration: migration{ +// NewSystemUpgrade constructs a SystemUpgrade. +func NewSystemUpgrade( + description string, cv clusterversion.ClusterVersion, fn SystemUpgradeFunc, +) *SystemUpgrade { + return &SystemUpgrade{ + upgrade: upgrade{ description: description, cv: cv, }, @@ -161,10 +161,10 @@ func NewSystemMigration( } } -// Run kickstarts the actual migration process for system-level migrations. -func (m *SystemMigration) Run( +// Run kickstarts the actual upgrade process for system-level upgrades. +func (m *SystemUpgrade) Run( ctx context.Context, cv clusterversion.ClusterVersion, d SystemDeps, job *jobs.Job, ) error { - ctx = logtags.AddTag(ctx, fmt.Sprintf("migration=%s", cv), nil) + ctx = logtags.AddTag(ctx, fmt.Sprintf("upgrade=%s", cv), nil) return m.fn(ctx, cv, d, job) } diff --git a/pkg/migration/tenant_migration.go b/pkg/upgrade/tenant_upgrade.go similarity index 64% rename from pkg/migration/tenant_migration.go rename to pkg/upgrade/tenant_upgrade.go index f0204e1349db..27e5910383d4 100644 --- a/pkg/migration/tenant_migration.go +++ b/pkg/upgrade/tenant_upgrade.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migration +package upgrade import ( "context" @@ -27,7 +27,7 @@ import ( "github.com/cockroachdb/logtags" ) -// TenantDeps are the dependencies of migrations which perform actions at the +// TenantDeps are the dependencies of upgrades which perform actions at the // SQL layer. type TenantDeps struct { DB *kv.DB @@ -37,7 +37,7 @@ type TenantDeps struct { LeaseManager *lease.Manager InternalExecutor sqlutil.InternalExecutor - SpanConfig struct { // deps for span config migrations; can be removed accordingly + SpanConfig struct { // deps for span config upgrades; can be removed accordingly spanconfig.KVAccessor spanconfig.Splitter Default roachpb.SpanConfig @@ -46,37 +46,37 @@ type TenantDeps struct { TestingKnobs *TestingKnobs } -// TenantMigrationFunc is used to perform sql-level migrations. It may be run from +// TenantUpgradeFunc is used to perform sql-level upgrades. It may be run from // any tenant. -type TenantMigrationFunc func(context.Context, clusterversion.ClusterVersion, TenantDeps, *jobs.Job) error +type TenantUpgradeFunc func(context.Context, clusterversion.ClusterVersion, TenantDeps, *jobs.Job) error // PreconditionFunc is a function run without isolation before attempting an -// upgrade that includes this migration. It is used to verify that the -// required conditions for the migration to succeed are met. This can allow +// upgrade that includes this upgrade. It is used to verify that the +// required conditions for the upgrade to succeed are met. This can allow // users to fix any problems before "crossing the rubicon" and no longer // being able to upgrade. type PreconditionFunc func(context.Context, clusterversion.ClusterVersion, TenantDeps) error -// TenantMigration is an implementation of Migration for tenant-level -// migrations. This is used for all migration which might affect the state of +// TenantUpgrade is an implementation of Upgrade for tenant-level +// upgrades. This is used for all upgrade which might affect the state of // sql. It includes the system tenant. -type TenantMigration struct { - migration - fn TenantMigrationFunc +type TenantUpgrade struct { + upgrade + fn TenantUpgradeFunc precondition PreconditionFunc } -var _ Migration = (*TenantMigration)(nil) +var _ Upgrade = (*TenantUpgrade)(nil) -// NewTenantMigration constructs a TenantMigration. -func NewTenantMigration( +// NewTenantUpgrade constructs a TenantUpgrade. +func NewTenantUpgrade( description string, cv clusterversion.ClusterVersion, precondition PreconditionFunc, - fn TenantMigrationFunc, -) *TenantMigration { - m := &TenantMigration{ - migration: migration{ + fn TenantUpgradeFunc, +) *TenantUpgrade { + m := &TenantUpgrade{ + upgrade: upgrade{ description: description, cv: cv, }, @@ -86,19 +86,19 @@ func NewTenantMigration( return m } -// Run kickstarts the actual migration process for tenant-level migrations. -func (m *TenantMigration) Run( +// Run kick-starts the actual upgrade process for tenant-level upgrades. +func (m *TenantUpgrade) Run( ctx context.Context, cv clusterversion.ClusterVersion, d TenantDeps, job *jobs.Job, ) error { - ctx = logtags.AddTag(ctx, fmt.Sprintf("migration=%s", cv), nil) + ctx = logtags.AddTag(ctx, fmt.Sprintf("upgrade=%s", cv), nil) return m.fn(ctx, cv, d, job) } // Precondition runs the precondition check if there is one and reports // any errors. -func (m *TenantMigration) Precondition( +func (m *TenantUpgrade) Precondition( ctx context.Context, cv clusterversion.ClusterVersion, d TenantDeps, ) error { - ctx = logtags.AddTag(ctx, fmt.Sprintf("migration=%s,precondition", cv), nil) + ctx = logtags.AddTag(ctx, fmt.Sprintf("upgrade=%s,precondition", cv), nil) return m.precondition(ctx, cv, d) } diff --git a/pkg/migration/testing_knobs.go b/pkg/upgrade/testing_knobs.go similarity index 73% rename from pkg/migration/testing_knobs.go rename to pkg/upgrade/testing_knobs.go index db5920eb106f..e203a1033068 100644 --- a/pkg/migration/testing_knobs.go +++ b/pkg/upgrade/testing_knobs.go @@ -8,24 +8,24 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migration +package upgrade import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/clusterversion" ) -// TestingKnobs are knobs to inject behavior into the migration manager which +// TestingKnobs are knobs to inject behavior into the upgrade manager which // are useful for testing. type TestingKnobs struct { // ListBetweenOverride injects an override for `clusterversion.ListBetween() - // in order to run migrations corresponding to versions which do not + // in order to run upgrades corresponding to versions which do not // actually exist. ListBetweenOverride func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion - // RegistryOverride is used to inject migrations for specific cluster versions. - RegistryOverride func(cv clusterversion.ClusterVersion) (Migration, bool) + // RegistryOverride is used to inject upgrades for specific cluster versions. + RegistryOverride func(cv clusterversion.ClusterVersion) (Upgrade, bool) } // ModuleTestingKnobs makes TestingKnobs a base.ModuleTestingKnobs. diff --git a/pkg/migration/migration.go b/pkg/upgrade/upgrade.go similarity index 54% rename from pkg/migration/migration.go rename to pkg/upgrade/upgrade.go index 59cc502f05c0..b00f3b5d00ae 100644 --- a/pkg/migration/migration.go +++ b/pkg/upgrade/upgrade.go @@ -8,18 +8,18 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -// Package migration captures the facilities needed to define and execute -// migrations for a crdb cluster. These migrations can be arbitrarily long +// Package upgrade captures the facilities needed to define and execute +// upgrades for a crdb cluster. These upgrades can be arbitrarily long // running, are free to send out arbitrary requests cluster wide, change // internal DB state, and much more. They're typically reserved for crdb -// internal operations and state. Each migration is idempotent in nature, is +// internal operations and state. Each upgrade is idempotent in nature, is // associated with a specific cluster version, and executed when the cluster // version is made active on every node in the cluster. // -// Examples of migrations that apply would be migrations to move all raft state +// Examples of upgrades that apply would be upgrades to move all raft state // from one storage engine to another, or purging all usage of the replicated // truncated state in KV. -package migration +package upgrade import ( "fmt" @@ -27,32 +27,32 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" ) -// Migration defines a program to be executed once every node in the cluster is +// Upgrade defines a program to be executed once every node in the cluster is // (a) running a specific binary version, and (b) has completed all prior -// migrations. Note that there are two types of migrations, a SystemMigration -// and a TenantMigration. A SystemMigration only runs on the system tenant and -// is used to migrate state at the KV layer. A TenantMigration runs on all +// upgrades. Note that there are two types of upgrades, a SystemUpgrade +// and a TenantUpgrade. A SystemUpgrade only runs on the system tenant and +// is used to migrate state at the KV layer. A TenantUpgrade runs on all // tenants (including the system tenant) and should be used whenever state at // the SQL layer is being migrated. // -// Each migration is associated with a specific internal cluster version and is +// Each upgrade is associated with a specific internal cluster version and is // idempotent in nature. When setting the cluster version (via `SET CLUSTER -// SETTING version`), the manager process determines the set of migrations +// SETTING version`), the manager process determines the set of upgrades // needed to bridge the gap between the current active cluster version, and the // target one. See [1] for where that happens. // -// To introduce a migration, start by adding version key to pkg/clusterversion +// To introduce an upgrade, start by adding version key to pkg/clusterversion // and introducing a corresponding internal cluster version for it. See [2] for -// more details. Following that, define a Migration in the migrations package -// and add it to the appropriate migrations slice to the registry. Be sure to +// more details. Following that, define an Upgrade in the upgrades package +// and add it to the appropriate upgrades slice to the registry. Be sure to // key it in with the new cluster version we just added. During cluster // upgrades, once the operator is able to set a cluster version setting that's // past the version that was introduced (typically the major release version -// the migration was introduced in), the manager will execute the defined -// migration before letting the upgrade finalize. +// the upgrade was introduced in), the manager will execute the defined +// upgrade before letting the upgrade finalize. // -// If the migration requires below-Raft level changes ([3] is one example), -// you'll need to add a version switch and the relevant system-level migration +// If the upgrade requires below-Raft level changes ([3] is one example), +// you'll need to add a version switch and the relevant system-level upgrade // in [4]. See IterateRangeDescriptors and the Migrate KV request for more // details. // @@ -61,37 +61,37 @@ import ( // [3]: truncatedStateMigration // [4]: pkg/kv/kvserver/batch_eval/cmd_migrate.go // -type Migration interface { +type Upgrade interface { ClusterVersion() clusterversion.ClusterVersion Name() string internal() // restrict implementations to this package } -// JobDeps are migration-specific dependencies used by the migration job to run -// migrations. +// JobDeps are upgrade-specific dependencies used by the upgrade job to run +// upgrades. type JobDeps interface { - // GetMigration returns the migration associated with the cluster version + // GetUpgrade returns the upgrade associated with the cluster version // if one exists. - GetMigration(key clusterversion.ClusterVersion) (Migration, bool) + GetUpgrade(key clusterversion.ClusterVersion) (Upgrade, bool) - // SystemDeps returns a handle to migration dependencies on a system tenant. + // SystemDeps returns a handle to upgrade dependencies on a system tenant. SystemDeps() SystemDeps } -type migration struct { +type upgrade struct { description string cv clusterversion.ClusterVersion } -// ClusterVersion makes SystemMigration a Migration. -func (m *migration) ClusterVersion() clusterversion.ClusterVersion { +// ClusterVersion makes SystemUpgrade an Upgrade. +func (m *upgrade) ClusterVersion() clusterversion.ClusterVersion { return m.cv } -// Name returns a human readable name for this migration. -func (m *migration) Name() string { - return fmt.Sprintf("Migration to %s: %q", m.cv.String(), m.description) +// Name returns a human-readable name for this upgrade. +func (m *upgrade) Name() string { + return fmt.Sprintf("Upgrade to %s: %q", m.cv.String(), m.description) } -func (m *migration) internal() {} +func (m *upgrade) internal() {} diff --git a/pkg/migration/migrationcluster/BUILD.bazel b/pkg/upgrade/upgradecluster/BUILD.bazel similarity index 84% rename from pkg/migration/migrationcluster/BUILD.bazel rename to pkg/upgrade/upgradecluster/BUILD.bazel index 71e51d5e48ab..03687b6a8383 100644 --- a/pkg/migration/migrationcluster/BUILD.bazel +++ b/pkg/upgrade/upgradecluster/BUILD.bazel @@ -1,13 +1,13 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( - name = "migrationcluster", + name = "upgradecluster", srcs = [ "cluster.go", "nodes.go", "tenant_cluster.go", ], - importpath = "github.com/cockroachdb/cockroach/pkg/migration/migrationcluster", + importpath = "github.com/cockroachdb/cockroach/pkg/upgrade/upgradecluster", visibility = ["//visibility:public"], deps = [ "//pkg/keys", @@ -26,7 +26,7 @@ go_library( ) go_test( - name = "migrationcluster_test", + name = "upgradecluster_test", size = "small", srcs = [ "client_test.go", @@ -34,11 +34,10 @@ go_test( "main_test.go", "nodes_test.go", ], - embed = [":migrationcluster"], + embed = [":upgradecluster"], deps = [ "//pkg/keys", "//pkg/kv/kvserver", - "//pkg/migration/nodelivenesstest", "//pkg/roachpb", "//pkg/rpc", "//pkg/security", @@ -49,6 +48,7 @@ go_test( "//pkg/testutils", "//pkg/testutils/serverutils", "//pkg/testutils/testcluster", + "//pkg/upgrade/nodelivenesstest", "//pkg/util/leaktest", "//pkg/util/syncutil", "@org_golang_google_grpc//:go_default_library", diff --git a/pkg/migration/migrationcluster/client_test.go b/pkg/upgrade/upgradecluster/client_test.go similarity index 90% rename from pkg/migration/migrationcluster/client_test.go rename to pkg/upgrade/upgradecluster/client_test.go index 2ee48cb256b7..69346044364f 100644 --- a/pkg/migration/migrationcluster/client_test.go +++ b/pkg/upgrade/upgradecluster/client_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrationcluster_test +package upgradecluster_test import ( "context" @@ -17,11 +17,11 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv/kvserver" - "github.com/cockroachdb/cockroach/pkg/migration/migrationcluster" - "github.com/cockroachdb/cockroach/pkg/migration/nodelivenesstest" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/sql/tests" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" + "github.com/cockroachdb/cockroach/pkg/upgrade/nodelivenesstest" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgradecluster" "github.com/cockroachdb/cockroach/pkg/util/leaktest" ) @@ -59,9 +59,9 @@ func TestClusterIterateRangeDescriptors(t *testing.T) { } c := nodelivenesstest.New(numNodes) - h := migrationcluster.New(migrationcluster.ClusterConfig{ + h := upgradecluster.New(upgradecluster.ClusterConfig{ NodeLiveness: c, - Dialer: migrationcluster.NoopDialer{}, + Dialer: upgradecluster.NoopDialer{}, DB: kvDB, }) diff --git a/pkg/migration/migrationcluster/cluster.go b/pkg/upgrade/upgradecluster/cluster.go similarity index 93% rename from pkg/migration/migrationcluster/cluster.go rename to pkg/upgrade/upgradecluster/cluster.go index 5435fae9e4ce..7edc8a3039ba 100644 --- a/pkg/migration/migrationcluster/cluster.go +++ b/pkg/upgrade/upgradecluster/cluster.go @@ -8,8 +8,8 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -// Package migrationcluster provides implementations of migration.Cluster. -package migrationcluster +// Package upgradecluster provides implementations of upgrade.Cluster. +package upgradecluster import ( "context" @@ -57,7 +57,7 @@ type NodeDialer interface { } // NodeLiveness is the subset of the interface satisfied by CRDB's node liveness -// component that the migration manager relies upon. +// component that the upgrade manager relies upon. type NodeLiveness interface { GetLivenessesFromKV(context.Context) ([]livenesspb.Liveness, error) IsLive(roachpb.NodeID) (bool, error) @@ -68,7 +68,7 @@ func New(cfg ClusterConfig) *Cluster { return &Cluster{c: cfg} } -// UntilClusterStable is part of the migration.Cluster interface. +// UntilClusterStable is part of the upgrade.Cluster interface. func (c *Cluster) UntilClusterStable(ctx context.Context, fn func() error) error { ns, err := NodesFromNodeLiveness(ctx, c.c.NodeLiveness) if err != nil { @@ -94,7 +94,7 @@ func (c *Cluster) UntilClusterStable(ctx context.Context, fn func() error) error return nil } -// NumNodes is part of the migration.Cluster interface. +// NumNodes is part of the upgrade.Cluster interface. func (c *Cluster) NumNodes(ctx context.Context) (int, error) { ns, err := NodesFromNodeLiveness(ctx, c.c.NodeLiveness) if err != nil { @@ -103,7 +103,7 @@ func (c *Cluster) NumNodes(ctx context.Context) (int, error) { return len(ns), nil } -// ForEveryNode is part of the migration.Cluster interface. +// ForEveryNode is part of the upgrade.Cluster interface. func (c *Cluster) ForEveryNode( ctx context.Context, op string, fn func(context.Context, serverpb.MigrationClient) error, ) error { @@ -139,7 +139,7 @@ func (c *Cluster) ForEveryNode( return grp.Wait() } -// IterateRangeDescriptors is part of the migration.Cluster interface. +// IterateRangeDescriptors is part of the upgrade.Cluster interface. func (c *Cluster) IterateRangeDescriptors( ctx context.Context, blockSize int, init func(), fn func(...roachpb.RangeDescriptor) error, ) error { diff --git a/pkg/migration/migrationcluster/helper_test.go b/pkg/upgrade/upgradecluster/helper_test.go similarity index 98% rename from pkg/migration/migrationcluster/helper_test.go rename to pkg/upgrade/upgradecluster/helper_test.go index 3cae54da5b4b..c3264527f56f 100644 --- a/pkg/migration/migrationcluster/helper_test.go +++ b/pkg/upgrade/upgradecluster/helper_test.go @@ -8,18 +8,18 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrationcluster +package upgradecluster import ( "context" "fmt" "testing" - "github.com/cockroachdb/cockroach/pkg/migration/nodelivenesstest" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/rpc" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/testutils" + "github.com/cockroachdb/cockroach/pkg/upgrade/nodelivenesstest" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/syncutil" "google.golang.org/grpc" diff --git a/pkg/migration/migrationmanager/main_test.go b/pkg/upgrade/upgradecluster/main_test.go similarity index 97% rename from pkg/migration/migrationmanager/main_test.go rename to pkg/upgrade/upgradecluster/main_test.go index 922058bdefec..b458481b1707 100644 --- a/pkg/migration/migrationmanager/main_test.go +++ b/pkg/upgrade/upgradecluster/main_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrationmanager_test +package upgradecluster_test import ( "os" diff --git a/pkg/migration/migrationcluster/nodes.go b/pkg/upgrade/upgradecluster/nodes.go similarity index 98% rename from pkg/migration/migrationcluster/nodes.go rename to pkg/upgrade/upgradecluster/nodes.go index 15b789f90ec1..8170977c3d4b 100644 --- a/pkg/migration/migrationcluster/nodes.go +++ b/pkg/upgrade/upgradecluster/nodes.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrationcluster +package upgradecluster import ( "context" @@ -18,7 +18,7 @@ import ( "github.com/cockroachdb/redact" ) -// Node captures the relevant bits of each node as it pertains to the migration +// Node captures the relevant bits of each node as it pertains to the upgrade // infrastructure. type Node struct { ID roachpb.NodeID diff --git a/pkg/migration/migrationcluster/nodes_test.go b/pkg/upgrade/upgradecluster/nodes_test.go similarity index 98% rename from pkg/migration/migrationcluster/nodes_test.go rename to pkg/upgrade/upgradecluster/nodes_test.go index 15a9526f036c..1d2b76f3a808 100644 --- a/pkg/migration/migrationcluster/nodes_test.go +++ b/pkg/upgrade/upgradecluster/nodes_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrationcluster +package upgradecluster import ( "sort" diff --git a/pkg/migration/migrationcluster/tenant_cluster.go b/pkg/upgrade/upgradecluster/tenant_cluster.go similarity index 94% rename from pkg/migration/migrationcluster/tenant_cluster.go rename to pkg/upgrade/upgradecluster/tenant_cluster.go index 455ebea6b9c9..c99af14e262f 100644 --- a/pkg/migration/migrationcluster/tenant_cluster.go +++ b/pkg/upgrade/upgradecluster/tenant_cluster.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrationcluster +package upgradecluster import ( "context" @@ -20,8 +20,8 @@ import ( ) // TenantCluster represents the set of sql nodes running in a secondary tenant. -// It implements the migration.Cluster interface. It is used to drive forward -// migrations in the secondary tenants. In the current iteration, it assumes +// It implements the upgrade.Cluster interface. It is used to drive forward +// upgrades in the secondary tenants. In the current iteration, it assumes // that there is a single pod per tenant. // // Tenants and cluster upgrades @@ -127,19 +127,19 @@ func NewTenantCluster(db *kv.DB) *TenantCluster { return &TenantCluster{db: db} } -// NumNodes is part of the migration.Cluster interface. +// NumNodes is part of the upgrade.Cluster interface. func (t *TenantCluster) NumNodes(ctx context.Context) (int, error) { return 0, errors.AssertionFailedf("non-system tenants cannot iterate nodes") } -// ForEveryNode is part of the migration.Cluster interface. +// ForEveryNode is part of the upgrade.Cluster interface. func (t *TenantCluster) ForEveryNode( ctx context.Context, op string, fn func(context.Context, serverpb.MigrationClient) error, ) error { return errors.AssertionFailedf("non-system tenants cannot iterate nodes") } -// UntilClusterStable is part of the migration.Cluster interface. +// UntilClusterStable is part of the upgrade.Cluster interface. // // Tenant clusters in the current version assume their cluster is stable // because they presently assume there is at most one running SQL pod. When @@ -148,7 +148,7 @@ func (t TenantCluster) UntilClusterStable(ctx context.Context, fn func() error) return nil } -// IterateRangeDescriptors is part of the migration.Cluster interface. +// IterateRangeDescriptors is part of the upgrade.Cluster interface. func (t TenantCluster) IterateRangeDescriptors( ctx context.Context, size int, init func(), f func(descriptors ...roachpb.RangeDescriptor) error, ) error { diff --git a/pkg/migration/migrationjob/BUILD.bazel b/pkg/upgrade/upgradejob/BUILD.bazel similarity index 74% rename from pkg/migration/migrationjob/BUILD.bazel rename to pkg/upgrade/upgradejob/BUILD.bazel index 69e4dfbb8633..937aba5a9371 100644 --- a/pkg/migration/migrationjob/BUILD.bazel +++ b/pkg/upgrade/upgradejob/BUILD.bazel @@ -1,22 +1,22 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( - name = "migrationjob", - srcs = ["migration_job.go"], - importpath = "github.com/cockroachdb/cockroach/pkg/migration/migrationjob", + name = "upgrade_job", + srcs = ["upgrade_job.go"], + importpath = "github.com/cockroachdb/cockroach/pkg/upgrade/upgradejob", visibility = ["//visibility:public"], deps = [ "//pkg/clusterversion", "//pkg/jobs", "//pkg/jobs/jobspb", "//pkg/kv", - "//pkg/migration", "//pkg/security/username", "//pkg/settings/cluster", "//pkg/sql", "//pkg/sql/sem/tree", "//pkg/sql/sessiondata", "//pkg/sql/sqlutil", + "//pkg/upgrade", "//pkg/util/timeutil", "@com_github_cockroachdb_errors//:errors", ], diff --git a/pkg/migration/migrationjob/migration_job.go b/pkg/upgrade/upgradejob/upgrade_job.go similarity index 82% rename from pkg/migration/migrationjob/migration_job.go rename to pkg/upgrade/upgradejob/upgrade_job.go index 4e561d464ef8..9abfc3ca14c9 100644 --- a/pkg/migration/migrationjob/migration_job.go +++ b/pkg/upgrade/upgradejob/upgrade_job.go @@ -8,9 +8,9 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -// Package migrationjob contains the jobs.Resumer implementation -// used for long-running migrations. -package migrationjob +// Package upgradejob contains the jobs.Resumer implementation +// used for long-running upgrades. +package upgradejob import ( "context" @@ -19,13 +19,13 @@ import ( "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" "github.com/cockroachdb/cockroach/pkg/sql/sqlutil" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util/timeutil" "github.com/cockroachdb/errors" ) @@ -36,7 +36,7 @@ func init() { }) } -// NewRecord constructs a new jobs.Record for this migration. +// NewRecord constructs a new jobs.Record for this upgrade. func NewRecord( version clusterversion.ClusterVersion, user username.SQLUsername, name string, ) jobs.Record { @@ -68,28 +68,28 @@ func (r resumer) Resume(ctx context.Context, execCtxI interface{}) error { return errors.Wrapf(err, "checking migration completion for %v", cv) } mc := execCtx.MigrationJobDeps() - m, ok := mc.GetMigration(cv) + m, ok := mc.GetUpgrade(cv) if !ok { // TODO(ajwerner): Consider treating this as an assertion failure. Jobs // should only be created for a cluster version if there is an associated - // migration. It seems possible that a migration job could be launched by - // a node running a older version where a migration then runs on a job - // with a newer version where the migration has been re-ordered to be later. + // upgrade. It seems possible that an upgrade job could be launched by + // a node running a older version where an upgrade then runs on a job + // with a newer version where the upgrade has been re-ordered to be later. // This should only happen between alphas but is theoretically not illegal. return nil } switch m := m.(type) { - case *migration.SystemMigration: + case *upgrade.SystemUpgrade: err = m.Run(ctx, cv, mc.SystemDeps(), r.j) - case *migration.TenantMigration: - tenantDeps := migration.TenantDeps{ + case *upgrade.TenantUpgrade: + tenantDeps := upgrade.TenantDeps{ DB: execCtx.ExecCfg().DB, Codec: execCtx.ExecCfg().Codec, Settings: execCtx.ExecCfg().Settings, CollectionFactory: execCtx.ExecCfg().CollectionFactory, LeaseManager: execCtx.ExecCfg().LeaseManager, InternalExecutor: execCtx.ExecCfg().InternalExecutor, - TestingKnobs: execCtx.ExecCfg().MigrationTestingKnobs, + TestingKnobs: execCtx.ExecCfg().UpgradeTestingKnobs, } tenantDeps.SpanConfig.KVAccessor = execCtx.ExecCfg().SpanConfigKVAccessor tenantDeps.SpanConfig.Splitter = execCtx.ExecCfg().SpanConfigSplitter @@ -103,7 +103,7 @@ func (r resumer) Resume(ctx context.Context, execCtxI interface{}) error { return errors.Wrapf(err, "running migration for %v", cv) } - // Mark the migration as having been completed so that subsequent iterations + // Mark the upgrade as having been completed so that subsequent iterations // no-op and new jobs are not created. if err := markMigrationCompleted(ctx, ie, cv); err != nil { return errors.Wrapf(err, "marking migration complete for %v", cv) @@ -111,8 +111,8 @@ func (r resumer) Resume(ctx context.Context, execCtxI interface{}) error { return nil } -// CheckIfMigrationCompleted queries the system.migrations table to determine -// if the migration associated with this version has already been completed. +// CheckIfMigrationCompleted queries the system.upgrades table to determine +// if the upgrade associated with this version has already been completed. // The txn may be nil, in which case the check will be run in its own // transaction. func CheckIfMigrationCompleted( @@ -169,7 +169,7 @@ VALUES ($1, $2, $3, $4, $5)`, return err } -// The long-running migration resumer has no reverting logic. +// The long-running upgrade resumer has no reverting logic. func (r resumer) OnFailOrCancel(ctx context.Context, execCtx interface{}) error { return nil } diff --git a/pkg/migration/migrationmanager/BUILD.bazel b/pkg/upgrade/upgrademanager/BUILD.bazel similarity index 83% rename from pkg/migration/migrationmanager/BUILD.bazel rename to pkg/upgrade/upgrademanager/BUILD.bazel index d0f277fded53..e50572090af0 100644 --- a/pkg/migration/migrationmanager/BUILD.bazel +++ b/pkg/upgrade/upgrademanager/BUILD.bazel @@ -1,9 +1,9 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( - name = "migrationmanager", + name = "upgrademanager", srcs = ["manager.go"], - importpath = "github.com/cockroachdb/cockroach/pkg/migration/migrationmanager", + importpath = "github.com/cockroachdb/cockroach/pkg/upgrade/upgrademanager", visibility = ["//visibility:public"], deps = [ "//pkg/clusterversion", @@ -11,9 +11,6 @@ go_library( "//pkg/jobs/jobspb", "//pkg/keys", "//pkg/kv", - "//pkg/migration", - "//pkg/migration/migrationjob", - "//pkg/migration/migrations", "//pkg/security/username", "//pkg/server/serverpb", "//pkg/settings/cluster", @@ -22,6 +19,9 @@ go_library( "//pkg/sql/protoreflect", "//pkg/sql/sem/tree", "//pkg/sql/sqlutil", + "//pkg/upgrade", + "//pkg/upgrade/upgradejob:upgrade_job", + "//pkg/upgrade/upgrades", "//pkg/util/log", "@com_github_cockroachdb_errors//:errors", "@com_github_cockroachdb_logtags//:logtags", @@ -30,7 +30,7 @@ go_library( ) go_test( - name = "migrationmanager_test", + name = "upgrademanager_test", size = "medium", srcs = [ "main_test.go", @@ -43,8 +43,6 @@ go_test( "//pkg/jobs/jobspb", "//pkg/kv/kvserver/batcheval", "//pkg/kv/kvserver/liveness", - "//pkg/migration", - "//pkg/migration/migrations", "//pkg/roachpb", "//pkg/security", "//pkg/security/securitytest", @@ -55,6 +53,8 @@ go_test( "//pkg/testutils/serverutils", "//pkg/testutils/sqlutils", "//pkg/testutils/testcluster", + "//pkg/upgrade", + "//pkg/upgrade/upgrades", "//pkg/util", "//pkg/util/leaktest", "//pkg/util/log", diff --git a/pkg/migration/migrationcluster/main_test.go b/pkg/upgrade/upgrademanager/main_test.go similarity index 97% rename from pkg/migration/migrationcluster/main_test.go rename to pkg/upgrade/upgrademanager/main_test.go index 16a5de729f85..f9913dcc431f 100644 --- a/pkg/migration/migrationcluster/main_test.go +++ b/pkg/upgrade/upgrademanager/main_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrationcluster_test +package upgrademanager_test import ( "os" diff --git a/pkg/migration/migrationmanager/manager.go b/pkg/upgrade/upgrademanager/manager.go similarity index 84% rename from pkg/migration/migrationmanager/manager.go rename to pkg/upgrade/upgrademanager/manager.go index 2092ec953fcf..7fe25bd2186f 100644 --- a/pkg/migration/migrationmanager/manager.go +++ b/pkg/upgrade/upgrademanager/manager.go @@ -8,9 +8,9 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -// Package migrationmanager provides an implementation of migration.Manager +// Package upgrademanager provides an implementation of upgrade.Manager // for use on kv nodes. -package migrationmanager +package upgrademanager import ( "context" @@ -21,9 +21,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" - "github.com/cockroachdb/cockroach/pkg/migration/migrationjob" - "github.com/cockroachdb/cockroach/pkg/migration/migrations" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -32,52 +29,55 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/protoreflect" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sqlutil" + "github.com/cockroachdb/cockroach/pkg/upgrade" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgradejob" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" "github.com/cockroachdb/logtags" "github.com/cockroachdb/redact" ) -// Manager is the instance responsible for executing migrations across the +// Manager is the instance responsible for executing upgrades across the // cluster. type Manager struct { - deps migration.SystemDeps + deps upgrade.SystemDeps lm *lease.Manager ie sqlutil.InternalExecutor jr *jobs.Registry codec keys.SQLCodec settings *cluster.Settings - knobs migration.TestingKnobs + knobs upgrade.TestingKnobs } -// GetMigration returns the migration associated with this key. -func (m *Manager) GetMigration(key clusterversion.ClusterVersion) (migration.Migration, bool) { +// GetUpgrade returns the upgrade associated with this key. +func (m *Manager) GetUpgrade(key clusterversion.ClusterVersion) (upgrade.Upgrade, bool) { if m.knobs.RegistryOverride != nil { if m, ok := m.knobs.RegistryOverride(key); ok { return m, ok } } - return migrations.GetMigration(key) + return upgrades.GetUpgrade(key) } -// SystemDeps returns dependencies to run system migrations for the cluster +// SystemDeps returns dependencies to run system upgrades for the cluster // associated with this manager. It may be the zero value in a secondary tenant. -func (m *Manager) SystemDeps() migration.SystemDeps { +func (m *Manager) SystemDeps() upgrade.SystemDeps { return m.deps } // NewManager constructs a new Manager. The SystemDeps parameter may be zero in // secondary tenants. The testingKnobs parameter may be nil. func NewManager( - deps migration.SystemDeps, + deps upgrade.SystemDeps, lm *lease.Manager, ie sqlutil.InternalExecutor, jr *jobs.Registry, codec keys.SQLCodec, settings *cluster.Settings, - testingKnobs *migration.TestingKnobs, + testingKnobs *upgrade.TestingKnobs, ) *Manager { - var knobs migration.TestingKnobs + var knobs upgrade.TestingKnobs if testingKnobs != nil { knobs = *testingKnobs } @@ -92,9 +92,9 @@ func NewManager( } } -var _ migration.JobDeps = (*Manager)(nil) +var _ upgrade.JobDeps = (*Manager)(nil) -// Migrate runs the set of migrations required to upgrade the cluster version +// Migrate runs the set of upgrades required to upgrade the cluster version // from the current version to the target one. func (m *Manager) Migrate( ctx context.Context, @@ -103,7 +103,7 @@ func (m *Manager) Migrate( updateSystemVersionSetting sql.UpdateVersionSystemSettingHook, ) error { // TODO(irfansharif): Should we inject every ctx here with specific labels - // for each migration, so they log distinctly? + // for each upgrade, so they log distinctly? ctx = logtags.AddTag(ctx, "migration-mgr", nil) if from == to { // Nothing to do here. @@ -133,14 +133,14 @@ func (m *Manager) Migrate( for _, clusterVersion := range clusterVersions { log.Infof(ctx, "stepping through %s", clusterVersion) - // First, run the actual migration if any. + // First, run the actual upgrade if any. if err := m.runMigration(ctx, user, clusterVersion); err != nil { return err } // Next we'll push out the version gate to every node in the cluster. // Each node will persist the version, bump the local version gates, and - // then return. The migration associated with the specific version is + // then return. The upgrade associated with the specific version is // executed before every node in the cluster has the corresponding // version activated. Migrations that depend on a certain version // already being activated will need to registered using a cluster @@ -152,9 +152,9 @@ func (m *Manager) Migrate( // the cluster (including ones added concurrently during version // upgrades) are running binaries that know about the version. - // Below-raft migrations mutate replica state, making use of the + // Below-raft upgrades mutate replica state, making use of the // Migrate(version=V) primitive which they issue against the entire - // keyspace. These migrations typically want to rely on the invariant + // keyspace. These upgrades typically want to rely on the invariant // that there are no extant replicas in the system that haven't seen the // specific Migrate command. // @@ -170,11 +170,11 @@ func (m *Manager) Migrate( // forward. // // That still leaves rooms for replicas in the replica GC queue to evade - // detection. To address this, below-raft migrations typically take a + // detection. To address this, below-raft upgrades typically take a // two-phrase approach (the TruncatedAndRangeAppliedStateMigration being // one example of this), where after having migrated the entire keyspace // to version V, and after having prevented subsequent snapshots - // originating from replicas with versions < V, the migration sets out + // originating from replicas with versions < V, the upgrade sets out // to purge outdated replicas in the system[3]. Specifically it // processes all replicas in the GC queue with a version < V (which are // not accessible during the application of the Migrate command). @@ -182,12 +182,12 @@ func (m *Manager) Migrate( // [1]: See ReplicaState.Version. // [2]: See Replica.executeWriteBatch, specifically how proposals with the // Migrate request are handled downstream of raft. - // [3]: See PurgeOutdatedReplicas from the SystemMigration service. + // [3]: See PurgeOutdatedReplicas from the SystemUpgrade service. { - // The migrations infrastructure makes use of internal fence + // The upgrades infrastructure makes use of internal fence // versions when stepping through consecutive versions. It's - // instructive to walk through how we expect a version migration + // instructive to walk through how we expect a version upgrade // from v21.1 to v21.2 to take place, and how we behave in the // presence of new v21.1 or v21.2 Nodes being added to the cluster. // @@ -195,7 +195,7 @@ func (m *Manager) Migrate( // - All Nodes are rolled into v21.2 binaries, but with active // cluster version still as v21.1 // - The first version bump will be into v21.2-1(fence), see the - // migration manager above for where that happens + // upgrade manager above for where that happens // // Then concurrently: // @@ -217,7 +217,7 @@ func (m *Manager) Migrate( // can join the cluster will run a release that support the fence // version, and by design also supports the actual version (which is // the direct successor of the fence). - fenceVersion := migration.FenceVersionFor(ctx, clusterVersion) + fenceVersion := upgrade.FenceVersionFor(ctx, clusterVersion) if err := bumpClusterVersion(ctx, m.deps.Cluster, fenceVersion); err != nil { return err } @@ -248,7 +248,7 @@ func (m *Manager) Migrate( // bumpClusterVersion will invoke the BumpClusterVersion rpc on every node // until the cluster is stable. func bumpClusterVersion( - ctx context.Context, c migration.Cluster, clusterVersion clusterversion.ClusterVersion, + ctx context.Context, c upgrade.Cluster, clusterVersion clusterversion.ClusterVersion, ) error { req := &serverpb.BumpClusterVersionRequest{ClusterVersion: &clusterVersion} op := fmt.Sprintf("bump-cluster-version=%s", req.ClusterVersion.PrettyPrint()) @@ -263,7 +263,7 @@ func bumpClusterVersion( // bumpClusterVersion will invoke the ValidateTargetClusterVersion rpc on // every node until the cluster is stable. func validateTargetClusterVersion( - ctx context.Context, c migration.Cluster, clusterVersion clusterversion.ClusterVersion, + ctx context.Context, c upgrade.Cluster, clusterVersion clusterversion.ClusterVersion, ) error { req := &serverpb.ValidateTargetClusterVersionRequest{ClusterVersion: &clusterVersion} op := fmt.Sprintf("validate-cluster-version=%s", req.ClusterVersion.PrettyPrint()) @@ -278,7 +278,7 @@ func validateTargetClusterVersion( func forEveryNodeUntilClusterStable( ctx context.Context, op string, - c migration.Cluster, + c upgrade.Cluster, f func(ctx context.Context, client serverpb.MigrationClient) error, ) error { return c.UntilClusterStable(ctx, func() error { @@ -289,11 +289,11 @@ func forEveryNodeUntilClusterStable( func (m *Manager) runMigration( ctx context.Context, user username.SQLUsername, version clusterversion.ClusterVersion, ) error { - mig, exists := m.GetMigration(version) + mig, exists := m.GetUpgrade(version) if !exists { return nil } - _, isSystemMigration := mig.(*migration.SystemMigration) + _, isSystemMigration := mig.(*upgrade.SystemUpgrade) if isSystemMigration && !m.codec.ForSystemTenant() { return nil } @@ -312,7 +312,7 @@ func (m *Manager) getOrCreateMigrationJob( ) (alreadyCompleted bool, jobID jobspb.JobID, _ error) { newJobID := m.jr.MakeJobID() if err := m.deps.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) (err error) { - alreadyCompleted, err = migrationjob.CheckIfMigrationCompleted(ctx, txn, m.ie, version) + alreadyCompleted, err = upgradejob.CheckIfMigrationCompleted(ctx, txn, m.ie, version) if err != nil && ctx.Err() == nil { log.Warningf(ctx, "failed to check if migration already completed: %v", err) } @@ -328,7 +328,7 @@ func (m *Manager) getOrCreateMigrationJob( return nil } jobID = newJobID - _, err = m.jr.CreateJobWithTxn(ctx, migrationjob.NewRecord(version, user, name), jobID, txn) + _, err = m.jr.CreateJobWithTxn(ctx, upgradejob.NewRecord(version, user, name), jobID, txn) return err }); err != nil { return false, 0, err @@ -396,21 +396,21 @@ func (m *Manager) listBetween( return clusterversion.ListBetween(from, to) } -// checkPreconditions runs the precondition check for each tenant migration +// checkPreconditions runs the precondition check for each tenant upgrade // associated with the provided versions. func (m *Manager) checkPreconditions( ctx context.Context, versions []clusterversion.ClusterVersion, ) error { for _, v := range versions { - mig, ok := m.GetMigration(v) + mig, ok := m.GetUpgrade(v) if !ok { continue } - tm, ok := mig.(*migration.TenantMigration) + tm, ok := mig.(*upgrade.TenantUpgrade) if !ok { continue } - if err := tm.Precondition(ctx, v, migration.TenantDeps{ + if err := tm.Precondition(ctx, v, upgrade.TenantDeps{ DB: m.deps.DB, Codec: m.codec, Settings: m.settings, diff --git a/pkg/migration/migrationmanager/manager_external_test.go b/pkg/upgrade/upgrademanager/manager_external_test.go similarity index 86% rename from pkg/migration/migrationmanager/manager_external_test.go rename to pkg/upgrade/upgrademanager/manager_external_test.go index bba4caed870e..98b589d8c380 100644 --- a/pkg/migration/migrationmanager/manager_external_test.go +++ b/pkg/upgrade/upgrademanager/manager_external_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrationmanager_test +package upgrademanager_test import ( "context" @@ -25,8 +25,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" - "github.com/cockroachdb/cockroach/pkg/migration" - "github.com/cockroachdb/cockroach/pkg/migration/migrations" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/server" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -34,6 +32,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" + "github.com/cockroachdb/cockroach/pkg/upgrade" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades" "github.com/cockroachdb/cockroach/pkg/util" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" @@ -45,11 +45,11 @@ import ( // TestAlreadyRunningJobsAreHandledProperly is a relatively low-level test to // ensure that the behavior to detect running jobs is sane. The test intercepts -// and blocks a migration that it first runs. It then duplicates the job to +// and blocks an upgrade that it first runs. It then duplicates the job to // break the single-running job invariant. It then ensures that that invariant // violation is detected. After that errant job is finished, it ensures that // concurrent attempts to bump the cluster version detect the already running -// migration and wait. +// upgrade and wait. func TestAlreadyRunningJobsAreHandledProperly(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -70,16 +70,16 @@ func TestAlreadyRunningJobsAreHandledProperly(t *testing.T) { BinaryVersionOverride: startCV.Version, DisableAutomaticVersionUpgrade: make(chan struct{}), }, - MigrationManager: &migration.TestingKnobs{ + UpgradeManager: &upgrade.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { return []clusterversion.ClusterVersion{to} }, - RegistryOverride: func(cv clusterversion.ClusterVersion) (migration.Migration, bool) { + RegistryOverride: func(cv clusterversion.ClusterVersion) (upgrade.Upgrade, bool) { if cv != endCV { return nil, false } - return migration.NewTenantMigration("test", cv, migrations.NoPrecondition, func( - ctx context.Context, version clusterversion.ClusterVersion, deps migration.TenantDeps, _ *jobs.Job, + return upgrade.NewTenantUpgrade("test", cv, upgrades.NoPrecondition, func( + ctx context.Context, version clusterversion.ClusterVersion, deps upgrade.TenantDeps, _ *jobs.Job, ) error { canResume := make(chan error) ch <- canResume @@ -99,7 +99,7 @@ func TestAlreadyRunningJobsAreHandledProperly(t *testing.T) { }() unblock := <-ch - // Inject a second job for the same migration and ensure that that causes + // Inject a second job for the same upgrade and ensure that that causes // an error. This is pretty gnarly. var secondID jobspb.JobID require.NoError(t, tc.ServerConn(0).QueryRow(` @@ -146,7 +146,7 @@ RETURNING id;`).Scan(&secondID)) fakeJobBlockChan <- jobs.MarkAsPermanentJobError(errors.New("boom")) require.Regexp(t, "boom", <-runErr) - // Launch a second migration which later we'll ensure does not kick off + // Launch a second upgrade which later we'll ensure does not kick off // another job. We'll make sure this happens by polling the trace to see // the log line indicating what we want. tr := tc.Server(0).TracerI().(*tracing.Tracer) @@ -171,7 +171,7 @@ RETURNING id;`).Scan(&secondID)) // // At the moment it works in a very fragile manner (by making sure that // no processors actually create their own spans). Instead, a different - // way to observe the status of the migration manager should be + // way to observe the status of the upgrade manager should be // introduced and should be used here. rec := sp.GetConfiguredRecording() if tracing.FindMsgInRecording(rec, "found existing migration job") > 0 { @@ -203,16 +203,16 @@ func TestMigrateUpdatesReplicaVersion(t *testing.T) { BinaryVersionOverride: startCV.Version, DisableAutomaticVersionUpgrade: make(chan struct{}), }, - MigrationManager: &migration.TestingKnobs{ + UpgradeManager: &upgrade.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { return []clusterversion.ClusterVersion{from, to} }, - RegistryOverride: func(cv clusterversion.ClusterVersion) (migration.Migration, bool) { + RegistryOverride: func(cv clusterversion.ClusterVersion) (upgrade.Upgrade, bool) { if cv != endCV { return nil, false } - return migration.NewSystemMigration("test", cv, func( - ctx context.Context, version clusterversion.ClusterVersion, d migration.SystemDeps, _ *jobs.Job, + return upgrade.NewSystemUpgrade("test", cv, func( + ctx context.Context, version clusterversion.ClusterVersion, d upgrade.SystemDeps, _ *jobs.Job, ) error { return d.DB.Migrate(ctx, desc.StartKey, desc.EndKey, cv.Version) }), true @@ -222,16 +222,16 @@ func TestMigrateUpdatesReplicaVersion(t *testing.T) { }, }) defer tc.Stopper().Stop(ctx) - // RegisterKVMigration the below raft migration. + // RegisterKVMigration the below raft upgrade. unregisterKVMigration := batcheval.TestingRegisterMigrationInterceptor(endCV.Version, func() {}) defer unregisterKVMigration() // We'll take a specific range, still running at startCV, generate an // outgoing snapshot and then suspend it temporarily. We'll then bump the - // cluster version on all the stores, as part of the migration process, and + // cluster version on all the stores, as part of the upgrade process, and // then resume the snapshot process. Seeing as how the snapshot was // generated pre-version bump, off of a version of the range that hadn't - // observed the migration corresponding to the latest cluster version, we + // observed the upgrade corresponding to the latest cluster version, we // expect the store to reject it. key := tc.ScratchRange(t) @@ -268,7 +268,7 @@ func TestMigrateUpdatesReplicaVersion(t *testing.T) { return nil }) - // Kick off the migration process. + // Kick off the upgrade process. _, err = tc.Conns[0].ExecContext(ctx, `SET CLUSTER SETTING version = $1`, endCV.String()) require.NoError(t, err) @@ -278,8 +278,8 @@ func TestMigrateUpdatesReplicaVersion(t *testing.T) { } // TestConcurrentMigrationAttempts ensures that concurrent attempts to run -// migrations over a number of versions exhibits reasonable behavior. Namely, -// that each migration gets run one time and that migrations do not get run +// upgrades over a number of versions exhibits reasonable behavior. Namely, +// that each upgrade gets run one time and that upgrades do not get run // again. func TestConcurrentMigrationAttempts(t *testing.T) { defer leaktest.AfterTest(t)() @@ -294,7 +294,7 @@ func TestConcurrentMigrationAttempts(t *testing.T) { ) migrationRunCounts := make(map[clusterversion.ClusterVersion]int) - // RegisterKVMigration the migrations to update the map with run counts. + // RegisterKVMigration the upgrades to update the map with run counts. // There should definitely not be any concurrency of execution, so the race // detector should not fire. var versions []clusterversion.ClusterVersion @@ -321,13 +321,13 @@ func TestConcurrentMigrationAttempts(t *testing.T) { BinaryVersionOverride: versions[0].Version, DisableAutomaticVersionUpgrade: make(chan struct{}), }, - MigrationManager: &migration.TestingKnobs{ + UpgradeManager: &upgrade.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { return versions }, - RegistryOverride: func(cv clusterversion.ClusterVersion) (migration.Migration, bool) { - return migration.NewSystemMigration("test", cv, func( - ctx context.Context, version clusterversion.ClusterVersion, d migration.SystemDeps, _ *jobs.Job, + RegistryOverride: func(cv clusterversion.ClusterVersion) (upgrade.Upgrade, bool) { + return upgrade.NewSystemUpgrade("test", cv, func( + ctx context.Context, version clusterversion.ClusterVersion, d upgrade.SystemDeps, _ *jobs.Job, ) error { if atomic.AddInt32(&active, 1) != 1 { t.Error("unexpected concurrency") @@ -344,10 +344,10 @@ func TestConcurrentMigrationAttempts(t *testing.T) { }) defer tc.Stopper().Stop(ctx) - // Run N instances of the migration concurrently on different connections. + // Run N instances of the upgrade concurrently on different connections. // They should all eventually succeed; some may internally experience a // serializable restart but cockroach will handle that transparently. - // Afterwards we'll ensure that no migration was run more than once. + // Afterwards we'll ensure that no upgrade was run more than once. N := 25 if util.RaceEnabled { N = 5 @@ -376,8 +376,8 @@ func TestConcurrentMigrationAttempts(t *testing.T) { require.Len(t, migrationRunCounts, len(versions)) } -// TestPauseMigration ensures that migrations can indeed be paused and that -// concurrent attempts to perform a migration will block on the existing, +// TestPauseMigration ensures that upgrades can indeed be paused and that +// concurrent attempts to perform an upgrade will block on the existing, // paused job. func TestPauseMigration(t *testing.T) { defer leaktest.AfterTest(t)() @@ -403,16 +403,16 @@ func TestPauseMigration(t *testing.T) { BinaryVersionOverride: startCV.Version, DisableAutomaticVersionUpgrade: make(chan struct{}), }, - MigrationManager: &migration.TestingKnobs{ + UpgradeManager: &upgrade.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { return []clusterversion.ClusterVersion{to} }, - RegistryOverride: func(cv clusterversion.ClusterVersion) (migration.Migration, bool) { + RegistryOverride: func(cv clusterversion.ClusterVersion) (upgrade.Upgrade, bool) { if cv != endCV { return nil, false } - return migration.NewTenantMigration("test", cv, migrations.NoPrecondition, func( - ctx context.Context, version clusterversion.ClusterVersion, deps migration.TenantDeps, _ *jobs.Job, + return upgrade.NewTenantUpgrade("test", cv, upgrades.NoPrecondition, func( + ctx context.Context, version clusterversion.ClusterVersion, deps upgrade.TenantDeps, _ *jobs.Job, ) error { canResume := make(chan error) ch <- migrationEvent{ @@ -488,7 +488,7 @@ SELECT id require.NoError(t, err) } -// Test that the precondition prevents migrations from being run. +// Test that the precondition prevents upgrades from being run. func TestPrecondition(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -508,9 +508,9 @@ func TestPrecondition(t *testing.T) { var preconditionErr, migrationErr atomic.Value preconditionErr.Store(true) migrationErr.Store(true) - cf := func(run *int64, err *atomic.Value) migration.TenantMigrationFunc { + cf := func(run *int64, err *atomic.Value) upgrade.TenantUpgradeFunc { return func( - context.Context, clusterversion.ClusterVersion, migration.TenantDeps, *jobs.Job, + context.Context, clusterversion.ClusterVersion, upgrade.TenantDeps, *jobs.Job, ) error { atomic.AddInt64(run, 1) if err.Load().(bool) { @@ -524,28 +524,28 @@ func TestPrecondition(t *testing.T) { DisableAutomaticVersionUpgrade: make(chan struct{}), BinaryVersionOverride: v0.Version, }, - // Inject a migration which would run to upgrade the cluster. - // We'll validate that we never create a job for this migration. - MigrationManager: &migration.TestingKnobs{ + // Inject an upgrade which would run to upgrade the cluster. + // We'll validate that we never create a job for this upgrade. + UpgradeManager: &upgrade.TestingKnobs{ ListBetweenOverride: func(from, to clusterversion.ClusterVersion) []clusterversion.ClusterVersion { start := sort.Search(len(versions), func(i int) bool { return from.Less(versions[i].Version) }) end := sort.Search(len(versions), func(i int) bool { return to.Less(versions[i].Version) }) return versions[start:end] }, - RegistryOverride: func(cv clusterversion.ClusterVersion) (migration.Migration, bool) { + RegistryOverride: func(cv clusterversion.ClusterVersion) (upgrade.Upgrade, bool) { switch cv { case v1: - return migration.NewTenantMigration("v1", cv, - migration.PreconditionFunc(func( - ctx context.Context, cv clusterversion.ClusterVersion, td migration.TenantDeps, + return upgrade.NewTenantUpgrade("v1", cv, + upgrade.PreconditionFunc(func( + ctx context.Context, cv clusterversion.ClusterVersion, td upgrade.TenantDeps, ) error { return cf(&preconditionRun, &preconditionErr)(ctx, cv, td, nil) }), cf(&migrationRun, &migrationErr), ), true case v2: - return migration.NewTenantMigration("v2", cv, - migrations.NoPrecondition, + return upgrade.NewTenantUpgrade("v2", cv, + upgrades.NoPrecondition, cf(&migrationRun, &migrationErr), ), true default: diff --git a/pkg/migration/migrations/BUILD.bazel b/pkg/upgrade/upgrades/BUILD.bazel similarity index 95% rename from pkg/migration/migrations/BUILD.bazel rename to pkg/upgrade/upgrades/BUILD.bazel index 5a2cf6cac545..9825b18aee63 100644 --- a/pkg/migration/migrations/BUILD.bazel +++ b/pkg/upgrade/upgrades/BUILD.bazel @@ -1,7 +1,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( - name = "migrations", + name = "upgrades", srcs = [ "alter_statement_diagnostics_requests.go", "alter_table_protected_timestamp_records.go", @@ -13,7 +13,6 @@ go_library( "grant_option_migration.go", "insert_missing_public_schema_namespace_entry.go", "migrate_span_configs.go", - "migrations.go", "public_schema_migration.go", "raft_applied_index_term.go", "remove_invalid_database_privileges.go", @@ -21,8 +20,9 @@ go_library( "seed_tenant_span_configs.go", "span_count_table.go", "tenant_settings.go", + "upgrades.go", ], - importpath = "github.com/cockroachdb/cockroach/pkg/migration/migrations", + importpath = "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades", visibility = ["//visibility:public"], deps = [ "//pkg/clusterversion", @@ -30,7 +30,6 @@ go_library( "//pkg/jobs/jobspb", "//pkg/keys", "//pkg/kv", - "//pkg/migration", "//pkg/roachpb", "//pkg/security/username", "//pkg/server/serverpb", @@ -49,6 +48,7 @@ go_library( "//pkg/sql/privilege", "//pkg/sql/sem/tree", "//pkg/sql/sessiondata", + "//pkg/upgrade", "//pkg/util/hlc", "//pkg/util/log", "//pkg/util/protoutil", @@ -60,7 +60,7 @@ go_library( ) go_test( - name = "migrations_test", + name = "upgrades_test", size = "large", srcs = [ "alter_statement_diagnostics_requests_test.go", @@ -81,7 +81,7 @@ go_test( "remove_invalid_database_privileges_external_test.go", ], data = glob(["testdata/**"]), - embed = [":migrations"], + embed = [":upgrades"], shard_count = 16, deps = [ "//pkg/base", diff --git a/pkg/migration/migrations/alter_statement_diagnostics_requests.go b/pkg/upgrade/upgrades/alter_statement_diagnostics_requests.go similarity index 93% rename from pkg/migration/migrations/alter_statement_diagnostics_requests.go rename to pkg/upgrade/upgrades/alter_statement_diagnostics_requests.go index 94423955cc13..a52fbb1cd9f9 100644 --- a/pkg/migration/migrations/alter_statement_diagnostics_requests.go +++ b/pkg/upgrade/upgrades/alter_statement_diagnostics_requests.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -16,9 +16,9 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) // Target schema changes in the system.statement_diagnostics_requests table, @@ -40,7 +40,7 @@ CREATE INDEX completed_idx_v2 ON system.statement_diagnostics_requests (complete // system.statement_diagnostics_requests table. It adds two columns which are // then included into STORING clause of the secondary index. func alterSystemStmtDiagReqs( - ctx context.Context, cs clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, cs clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { for _, op := range []operation{ { diff --git a/pkg/migration/migrations/alter_statement_diagnostics_requests_test.go b/pkg/upgrade/upgrades/alter_statement_diagnostics_requests_test.go similarity index 90% rename from pkg/migration/migrations/alter_statement_diagnostics_requests_test.go rename to pkg/upgrade/upgrades/alter_statement_diagnostics_requests_test.go index c21f76e9b073..824b040c05d5 100644 --- a/pkg/migration/migrations/alter_statement_diagnostics_requests_test.go +++ b/pkg/upgrade/upgrades/alter_statement_diagnostics_requests_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -17,7 +17,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/migration/migrations" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" @@ -27,6 +26,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/privilege" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" ) @@ -59,19 +59,19 @@ func TestAlterSystemStmtDiagReqs(t *testing.T) { `SELECT min_execution_latency, expires_at FROM system.statement_diagnostics_requests LIMIT 0`, `SELECT min_execution_latency, expires_at FROM system.statement_diagnostics_requests@completed_idx_v2 LIMIT 0`, } - validationSchemas = []migrations.Schema{ - {Name: "min_execution_latency", ValidationFn: migrations.HasColumn}, - {Name: "expires_at", ValidationFn: migrations.HasColumn}, - {Name: "primary", ValidationFn: migrations.HasColumnFamily}, - {Name: "completed_idx", ValidationFn: migrations.DoesNotHaveIndex}, + validationSchemas = []upgrades.Schema{ + {Name: "min_execution_latency", ValidationFn: upgrades.HasColumn}, + {Name: "expires_at", ValidationFn: upgrades.HasColumn}, + {Name: "primary", ValidationFn: upgrades.HasColumnFamily}, + {Name: "completed_idx", ValidationFn: upgrades.DoesNotHaveIndex}, } ) // Inject the old copy of the descriptor. - migrations.InjectLegacyTable(ctx, t, s, systemschema.StatementDiagnosticsRequestsTable, + upgrades.InjectLegacyTable(ctx, t, s, systemschema.StatementDiagnosticsRequestsTable, getDeprecatedStmtDiagReqsDescriptor) validateSchemaExists := func(expectExists bool) { - migrations.ValidateSchemaExists( + upgrades.ValidateSchemaExists( ctx, t, s, @@ -86,8 +86,8 @@ func TestAlterSystemStmtDiagReqs(t *testing.T) { // Validate that the statement_diagnostics_requests table has the old // schema. validateSchemaExists(false) - // Run the migration. - migrations.Migrate( + // Run the upgrade. + upgrades.Upgrade( t, sqlDB, clusterversion.AlterSystemStmtDiagReqs, diff --git a/pkg/migration/migrations/alter_table_protected_timestamp_records.go b/pkg/upgrade/upgrades/alter_table_protected_timestamp_records.go similarity index 87% rename from pkg/migration/migrations/alter_table_protected_timestamp_records.go rename to pkg/upgrade/upgrades/alter_table_protected_timestamp_records.go index 1c51b6758905..6939fee5a430 100644 --- a/pkg/migration/migrations/alter_table_protected_timestamp_records.go +++ b/pkg/upgrade/upgrades/alter_table_protected_timestamp_records.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -16,8 +16,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) const addTargetCol = ` @@ -26,7 +26,7 @@ ADD COLUMN IF NOT EXISTS target BYTES FAMILY "primary" ` func alterTableProtectedTimestampRecords( - ctx context.Context, cs clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, cs clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { op := operation{ name: "add-table-pts-records-target-col", diff --git a/pkg/migration/migrations/alter_table_protected_timestamp_records_test.go b/pkg/upgrade/upgrades/alter_table_protected_timestamp_records_test.go similarity index 90% rename from pkg/migration/migrations/alter_table_protected_timestamp_records_test.go rename to pkg/upgrade/upgrades/alter_table_protected_timestamp_records_test.go index c727062a9353..b777b45278f3 100644 --- a/pkg/migration/migrations/alter_table_protected_timestamp_records_test.go +++ b/pkg/upgrade/upgrades/alter_table_protected_timestamp_records_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -17,7 +17,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/migration/migrations" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" @@ -26,6 +25,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/privilege" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" ) @@ -56,15 +56,15 @@ func TestAlterSystemProtectedTimestampRecordsTable(t *testing.T) { defer tc.Stopper().Stop(ctx) var ( - validationSchemas = []migrations.Schema{ - {Name: "target", ValidationFn: migrations.HasColumn}, + validationSchemas = []upgrades.Schema{ + {Name: "target", ValidationFn: upgrades.HasColumn}, } ) // Inject the old copy of the descriptor. - migrations.InjectLegacyTable(ctx, t, s, systemschema.ProtectedTimestampsRecordsTable, getDeprecatedProtectedTimestampRecordsDescriptor) + upgrades.InjectLegacyTable(ctx, t, s, systemschema.ProtectedTimestampsRecordsTable, getDeprecatedProtectedTimestampRecordsDescriptor) // Validate that the protected timestamp records table has the old schema. - migrations.ValidateSchemaExists( + upgrades.ValidateSchemaExists( ctx, t, s, @@ -75,8 +75,8 @@ func TestAlterSystemProtectedTimestampRecordsTable(t *testing.T) { validationSchemas, false, /* expectExists */ ) - // Run the migration. - migrations.Migrate( + // Run the upgrade. + upgrades.Upgrade( t, sqlDB, clusterversion.AlterSystemProtectedTimestampAddColumn, @@ -84,7 +84,7 @@ func TestAlterSystemProtectedTimestampRecordsTable(t *testing.T) { false, /* expectError */ ) // Validate that the table has new schema. - migrations.ValidateSchemaExists( + upgrades.ValidateSchemaExists( ctx, t, s, diff --git a/pkg/migration/migrations/alter_table_statistics_avg_size.go b/pkg/upgrade/upgrades/alter_table_statistics_avg_size.go similarity index 88% rename from pkg/migration/migrations/alter_table_statistics_avg_size.go rename to pkg/upgrade/upgrades/alter_table_statistics_avg_size.go index 3e6cda4b40d7..bd70ff7159a3 100644 --- a/pkg/migration/migrations/alter_table_statistics_avg_size.go +++ b/pkg/upgrade/upgrades/alter_table_statistics_avg_size.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -16,8 +16,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) const addAvgSizeCol = ` @@ -27,7 +27,7 @@ FAMILY "fam_0_tableID_statisticID_name_columnIDs_createdAt_rowCount_distinctCoun ` func alterSystemTableStatisticsAddAvgSize( - ctx context.Context, cs clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, cs clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { op := operation{ name: "add-table-statistics-avgSize-col", diff --git a/pkg/migration/migrations/alter_table_statistics_avg_size_test.go b/pkg/upgrade/upgrades/alter_table_statistics_avg_size_test.go similarity index 90% rename from pkg/migration/migrations/alter_table_statistics_avg_size_test.go rename to pkg/upgrade/upgrades/alter_table_statistics_avg_size_test.go index 7826f5933c77..bef154231435 100644 --- a/pkg/migration/migrations/alter_table_statistics_avg_size_test.go +++ b/pkg/upgrade/upgrades/alter_table_statistics_avg_size_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -17,7 +17,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/migration/migrations" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" @@ -26,6 +25,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/privilege" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" ) @@ -56,17 +56,17 @@ func TestAlterSystemTableStatisticsTable(t *testing.T) { defer tc.Stopper().Stop(ctx) var ( - validationSchemas = []migrations.Schema{ - {Name: "avgSize", ValidationFn: migrations.HasColumn}, + validationSchemas = []upgrades.Schema{ + {Name: "avgSize", ValidationFn: upgrades.HasColumn}, {Name: "fam_0_tableID_statisticID_name_columnIDs_createdAt_rowCount_distinctCount_nullCount_histogram", - ValidationFn: migrations.HasColumnFamily}, + ValidationFn: upgrades.HasColumnFamily}, } ) // Inject the old copy of the descriptor. - migrations.InjectLegacyTable(ctx, t, s, systemschema.TableStatisticsTable, getDeprecatedTableStatisticsDescriptor) + upgrades.InjectLegacyTable(ctx, t, s, systemschema.TableStatisticsTable, getDeprecatedTableStatisticsDescriptor) // Validate that the table statistics table has the old schema. - migrations.ValidateSchemaExists( + upgrades.ValidateSchemaExists( ctx, t, s, @@ -77,8 +77,8 @@ func TestAlterSystemTableStatisticsTable(t *testing.T) { validationSchemas, false, /* expectExists */ ) - // Run the migration. - migrations.Migrate( + // Run the upgrade. + upgrades.Upgrade( t, sqlDB, clusterversion.AlterSystemTableStatisticsAddAvgSizeCol, @@ -86,7 +86,7 @@ func TestAlterSystemTableStatisticsTable(t *testing.T) { false, /* expectError */ ) // Validate that the table has new schema. - migrations.ValidateSchemaExists( + upgrades.ValidateSchemaExists( ctx, t, s, diff --git a/pkg/migration/migrations/builtins_test.go b/pkg/upgrade/upgrades/builtins_test.go similarity index 97% rename from pkg/migration/migrations/builtins_test.go rename to pkg/upgrade/upgrades/builtins_test.go index f37a67befa3c..015400305988 100644 --- a/pkg/migration/migrations/builtins_test.go +++ b/pkg/upgrade/upgrades/builtins_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -50,7 +50,7 @@ func TestIsAtLeastVersionBuiltin(t *testing.T) { // because we are still on 21.1. sqlDB.CheckQueryResults(t, "SELECT crdb_internal.is_at_least_version('21.2-10')", [][]string{{"false"}}) - // Run the migration. + // Run the upgrade. sqlDB.Exec(t, "SET CLUSTER SETTING version = $1", clusterversion.ByKey(clusterversion.TraceIDDoesntImplyStructuredRecording).String()) // It should now return true. diff --git a/pkg/migration/migrations/comment_on_index_migration.go b/pkg/upgrade/upgrades/comment_on_index_migration.go similarity index 90% rename from pkg/migration/migrations/comment_on_index_migration.go rename to pkg/upgrade/upgrades/comment_on_index_migration.go index 4c2c415a9b83..209a24d17e37 100644 --- a/pkg/migration/migrations/comment_on_index_migration.go +++ b/pkg/upgrade/upgrades/comment_on_index_migration.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -17,15 +17,15 @@ import ( "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) // ensureCommentsHaveNonDroppedIndexes cleans up any comments associated with // indexes that no longer exist. func ensureCommentsHaveNonDroppedIndexes( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { return d.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { // Delete the rows that don't belong to any indexes. diff --git a/pkg/migration/migrations/comment_on_index_migration_external_test.go b/pkg/upgrade/upgrades/comment_on_index_migration_external_test.go similarity index 98% rename from pkg/migration/migrations/comment_on_index_migration_external_test.go rename to pkg/upgrade/upgrades/comment_on_index_migration_external_test.go index 409118fa2c05..a3b8e2c85bea 100644 --- a/pkg/migration/migrations/comment_on_index_migration_external_test.go +++ b/pkg/upgrade/upgrades/comment_on_index_migration_external_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -84,7 +84,7 @@ func TestEnsureIndexesExistForComments(t *testing.T) { }, ) - // Migrate to the new cluster version. + // Upgrade to the new cluster version. tdb.Exec(t, `SET CLUSTER SETTING version = $1`, clusterversion.ByKey(clusterversion.DeleteCommentsWithDroppedIndexes).String()) diff --git a/pkg/migration/migrations/descriptor_utils.go b/pkg/upgrade/upgrades/descriptor_utils.go similarity index 95% rename from pkg/migration/migrations/descriptor_utils.go rename to pkg/upgrade/upgrades/descriptor_utils.go index 95211cc6c3f7..710e40398a4a 100644 --- a/pkg/migration/migrations/descriptor_utils.go +++ b/pkg/upgrade/upgrades/descriptor_utils.go @@ -8,14 +8,13 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descidgen" @@ -23,6 +22,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) // CreateSystemTable is a function to inject a new system table. If the table @@ -67,13 +67,13 @@ func createSystemTable( // runPostDeserializationChangesOnAllDescriptors will paginate through the // descriptor table and upgrade all descriptors in need of upgrading. func runPostDeserializationChangesOnAllDescriptors( - ctx context.Context, d migration.TenantDeps, + ctx context.Context, d upgrade.TenantDeps, ) error { // maybeUpgradeDescriptors writes the descriptors with the given IDs // and writes new versions for all descriptors which required post // deserialization changes. maybeUpgradeDescriptors := func( - ctx context.Context, d migration.TenantDeps, toUpgrade []descpb.ID, + ctx context.Context, d upgrade.TenantDeps, toUpgrade []descpb.ID, ) error { return d.CollectionFactory.Txn(ctx, d.InternalExecutor, d.DB, func( ctx context.Context, txn *kv.Txn, descriptors *descs.Collection, diff --git a/pkg/migration/migrations/descriptor_utils_test.go b/pkg/upgrade/upgrades/descriptor_utils_test.go similarity index 94% rename from pkg/migration/migrations/descriptor_utils_test.go rename to pkg/upgrade/upgrades/descriptor_utils_test.go index 730a3a9a5d1e..862fc3db627d 100644 --- a/pkg/migration/migrations/descriptor_utils_test.go +++ b/pkg/upgrade/upgrades/descriptor_utils_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -16,7 +16,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/migration/migrations" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" @@ -26,6 +25,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/stretchr/testify/require" ) @@ -89,7 +89,7 @@ SELECT * table.GetParentID(), table.GetParentSchemaID(), table.GetName()) } require.Len(t, checkEntries(t), 0) - require.NoError(t, migrations.CreateSystemTable( + require.NoError(t, upgrades.CreateSystemTable( ctx, tc.Server(0).DB(), keys.SystemSQLCodec, table, )) require.Len(t, checkEntries(t), 1) @@ -98,7 +98,7 @@ SELECT * [][]string{{fakeTableSchema}}) // Make sure it's idempotent. - require.NoError(t, migrations.CreateSystemTable( + require.NoError(t, upgrades.CreateSystemTable( ctx, tc.Server(0).DB(), keys.SystemSQLCodec, table, )) require.Len(t, checkEntries(t), 1) diff --git a/pkg/migration/migrations/ensure_constraint_id_test.go b/pkg/upgrade/upgrades/ensure_constraint_id_test.go similarity index 98% rename from pkg/migration/migrations/ensure_constraint_id_test.go rename to pkg/upgrade/upgrades/ensure_constraint_id_test.go index 086cd274a414..c6e02fca3f58 100644 --- a/pkg/migration/migrations/ensure_constraint_id_test.go +++ b/pkg/upgrade/upgrades/ensure_constraint_id_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -123,7 +123,7 @@ func TestEnsureConstraintIDs(t *testing.T) { `);`, [][]string{{"false", "false"}}, ) - // Migrate to the new cluster version. + // Upgrade to the new cluster version. tdb.Exec(t, `SET CLUSTER SETTING version = $1`, clusterversion.ByKey(tabledesc.ConstraintIDsAddedToTableDescsVersion).String()) tdb.CheckQueryResultsRetry(t, "SHOW CLUSTER SETTING version", diff --git a/pkg/migration/migrations/ensure_no_draining_names.go b/pkg/upgrade/upgrades/ensure_no_draining_names.go similarity index 92% rename from pkg/migration/migrations/ensure_no_draining_names.go rename to pkg/upgrade/upgrades/ensure_no_draining_names.go index 907a05ed4d0a..b5c1c4987b92 100644 --- a/pkg/migration/migrations/ensure_no_draining_names.go +++ b/pkg/upgrade/upgrades/ensure_no_draining_names.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -16,11 +16,11 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/retry" ) @@ -48,7 +48,7 @@ LIMIT 1; // ensureNoDrainingNames waits until every descriptor has no draining names. func ensureNoDrainingNames( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { retryOpts := retry.Options{ MaxBackoff: 10 * time.Second, diff --git a/pkg/migration/migrations/ensure_no_draining_names_external_test.go b/pkg/upgrade/upgrades/ensure_no_draining_names_external_test.go similarity index 96% rename from pkg/migration/migrations/ensure_no_draining_names_external_test.go rename to pkg/upgrade/upgrades/ensure_no_draining_names_external_test.go index 83adaa82fba0..e52ebd131938 100644 --- a/pkg/migration/migrations/ensure_no_draining_names_external_test.go +++ b/pkg/upgrade/upgrades/ensure_no_draining_names_external_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -29,7 +29,7 @@ import ( "github.com/stretchr/testify/require" ) -// TestEnsureNoDrainingNames tests that the draining names migration performs +// TestEnsureNoDrainingNames tests that the draining names upgrade performs // as expected. func TestEnsureNoDrainingNames(t *testing.T) { defer leaktest.AfterTest(t)() @@ -111,7 +111,7 @@ func TestEnsureNoDrainingNames(t *testing.T) { renameUnblocked <- struct{}{} - // Migrate to the new cluster version. + // Upgrade to the new cluster version. tdb.Exec(t, `SET CLUSTER SETTING version = $1`, clusterversion.ByKey(clusterversion.DrainingNamesMigration).String()) diff --git a/pkg/migration/migrations/fix_cast_for_style_migration.go b/pkg/upgrade/upgrades/fix_cast_for_style_migration.go similarity index 79% rename from pkg/migration/migrations/fix_cast_for_style_migration.go rename to pkg/upgrade/upgrades/fix_cast_for_style_migration.go index 1d02d4416571..1adcb4b2c0cd 100644 --- a/pkg/migration/migrations/fix_cast_for_style_migration.go +++ b/pkg/upgrade/upgrades/fix_cast_for_style_migration.go @@ -8,18 +8,18 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" - "github.com/cockroachdb/cockroach/pkg/migration" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) func fixCastForStyleMigration( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { return runPostDeserializationChangesOnAllDescriptors(ctx, d) diff --git a/pkg/migration/migrations/fix_cast_for_style_migration_test.go b/pkg/upgrade/upgrades/fix_cast_for_style_migration_test.go similarity index 96% rename from pkg/migration/migrations/fix_cast_for_style_migration_test.go rename to pkg/upgrade/upgrades/fix_cast_for_style_migration_test.go index 02301421098b..6e0d89715ab6 100644 --- a/pkg/migration/migrations/fix_cast_for_style_migration_test.go +++ b/pkg/upgrade/upgrades/fix_cast_for_style_migration_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -17,10 +17,10 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/clusterversion" - "github.com/cockroachdb/cockroach/pkg/migration/migrations" "github.com/cockroachdb/cockroach/pkg/server" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" + "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/stretchr/testify/require" ) @@ -63,7 +63,7 @@ c4 interval AS ((s)::INTERVAL(4)) STORED c2 interval AS (ch::interval) STORED )`) - migrations.Migrate( + upgrades.Upgrade( t, sqlDB, clusterversion.DateStyleIntervalStyleCastRewrite, diff --git a/pkg/migration/migrations/grant_option_migration.go b/pkg/upgrade/upgrades/grant_option_migration.go similarity index 82% rename from pkg/migration/migrations/grant_option_migration.go rename to pkg/upgrade/upgrades/grant_option_migration.go index 084108d00366..f33c5837ff2f 100644 --- a/pkg/migration/migrations/grant_option_migration.go +++ b/pkg/upgrade/upgrades/grant_option_migration.go @@ -8,20 +8,20 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" - "github.com/cockroachdb/cockroach/pkg/migration" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) // grantOptionMigration iterates through every descriptor and sets a user's grant option bits // equal to its privilege bits if it holds the "GRANT" privilege. func grantOptionMigration( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { return runPostDeserializationChangesOnAllDescriptors(ctx, d) } diff --git a/pkg/migration/migrations/grant_option_migration_external_test.go b/pkg/upgrade/upgrades/grant_option_migration_external_test.go similarity index 99% rename from pkg/migration/migrations/grant_option_migration_external_test.go rename to pkg/upgrade/upgrades/grant_option_migration_external_test.go index 44d71421ec7d..c7787c57ba70 100644 --- a/pkg/migration/migrations/grant_option_migration_external_test.go +++ b/pkg/upgrade/upgrades/grant_option_migration_external_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -110,7 +110,7 @@ func TestGrantOptionMigration(t *testing.T) { 0ab4020a027432183a203728023a00423a0a05726f77696410011a0c08011040180030005014600020002a0e756e697175655f726f77696428293001680070007800800100880100980100480252500a077072696d617279100118012205726f776964300140004a10080010001a00200028003000380040005a007a0408002000800100880100900104980101a20106080012001800a80100b20100ba010060026a3a0a090a0561646d696e10020a080a04726f6f7410020a0c0a08746573747573657210020a0d0a0974657374757365723210021204726f6f741802800101880103980100b201160a077072696d61727910001a05726f77696420012800b80101c20100e80100f2010408001200f801008002009202009a020a08c8c7f884dcbdede616b20200b80200c00238c80200e00200f00200 ` - // Test the migration for types + // Test the upgrade for types /* CREATE USER testuser; CREATE DATABASE db; diff --git a/pkg/migration/migrations/helpers_test.go b/pkg/upgrade/upgrades/helpers_test.go similarity index 97% rename from pkg/migration/migrations/helpers_test.go rename to pkg/upgrade/upgrades/helpers_test.go index 59dd1dedd667..fd42b9e347bb 100644 --- a/pkg/migration/migrations/helpers_test.go +++ b/pkg/upgrade/upgrades/helpers_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -43,8 +43,8 @@ type Schema struct { ValidationFn func(catalog.TableDescriptor, catalog.TableDescriptor, string) (bool, error) } -// Migrate runs cluster migration by changing the 'version' cluster setting. -func Migrate( +// 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, ) { defer func() { diff --git a/pkg/migration/migrations/insert_missing_public_schema_namespace_entry.go b/pkg/upgrade/upgrades/insert_missing_public_schema_namespace_entry.go similarity index 94% rename from pkg/migration/migrations/insert_missing_public_schema_namespace_entry.go rename to pkg/upgrade/upgrades/insert_missing_public_schema_namespace_entry.go index 28bf9b8ed635..b069e7e45437 100644 --- a/pkg/migration/migrations/insert_missing_public_schema_namespace_entry.go +++ b/pkg/upgrade/upgrades/insert_missing_public_schema_namespace_entry.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -17,11 +17,11 @@ import ( "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) // insertMissingPublicSchemaNamespaceEntry creates a system.namespace entries @@ -29,7 +29,7 @@ import ( // This arises from restore where we mistakenly did not create system.namespace // entries for public schemas when restoring databases. func insertMissingPublicSchemaNamespaceEntry( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { // Get the ID of all databases where we're missing a public schema namespace // entry for. diff --git a/pkg/migration/migrations/main_test.go b/pkg/upgrade/upgrades/main_test.go similarity index 97% rename from pkg/migration/migrations/main_test.go rename to pkg/upgrade/upgrades/main_test.go index 5a38c8b0af33..c93684eee269 100644 --- a/pkg/migration/migrations/main_test.go +++ b/pkg/upgrade/upgrades/main_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "os" diff --git a/pkg/migration/migrations/migrate_span_configs.go b/pkg/upgrade/upgrades/migrate_span_configs.go similarity index 90% rename from pkg/migration/migrations/migrate_span_configs.go rename to pkg/upgrade/upgrades/migrate_span_configs.go index 33f07ea8fd49..5b8e09376c5a 100644 --- a/pkg/migration/migrations/migrate_span_configs.go +++ b/pkg/upgrade/upgrades/migrate_span_configs.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -17,16 +17,16 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/retry" "github.com/cockroachdb/errors" ) func ensureSpanConfigReconciliation( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, j *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, j *jobs.Job, ) error { if !d.Codec.ForSystemTenant() { return nil @@ -72,7 +72,7 @@ SELECT progress } func ensureSpanConfigSubscription( - ctx context.Context, _ clusterversion.ClusterVersion, deps migration.SystemDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, deps upgrade.SystemDeps, _ *jobs.Job, ) error { return deps.Cluster.UntilClusterStable(ctx, func() error { return deps.Cluster.ForEveryNode(ctx, "ensure-span-config-subscription", diff --git a/pkg/migration/migrations/migrate_span_configs_test.go b/pkg/upgrade/upgrades/migrate_span_configs_test.go similarity index 97% rename from pkg/migration/migrations/migrate_span_configs_test.go rename to pkg/upgrade/upgrades/migrate_span_configs_test.go index 095925bf18b6..bc83bc2548ba 100644 --- a/pkg/migration/migrations/migrate_span_configs_test.go +++ b/pkg/upgrade/upgrades/migrate_span_configs_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -134,7 +134,7 @@ func TestMixedVersionClusterEnableRangefeeds(t *testing.T) { wg.Wait() } -// TestEnsureSpanConfigReconciliation verifies that the migration waits for a +// TestEnsureSpanConfigReconciliation verifies that the upgrade waits for a // span config reconciliation attempt, blocking until it occurs. func TestEnsureSpanConfigReconciliation(t *testing.T) { defer leaktest.AfterTest(t)() @@ -204,7 +204,7 @@ func TestEnsureSpanConfigReconciliation(t *testing.T) { } // TestEnsureSpanConfigReconciliationMultiNode verifies that the span config -// reconciliation migration works in a multi-node setting. +// reconciliation upgrade works in a multi-node setting. func TestEnsureSpanConfigReconciliationMultiNode(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -292,7 +292,7 @@ func TestEnsureSpanConfigReconciliationMultiNode(t *testing.T) { } } -// TestEnsureSpanConfigSubscription verifies that the migration waits for all +// TestEnsureSpanConfigSubscription verifies that the upgrade waits for all // stores to have observed a reconciliation state. func TestEnsureSpanConfigSubscription(t *testing.T) { defer leaktest.AfterTest(t)() diff --git a/pkg/migration/migrations/public_schema_migration.go b/pkg/upgrade/upgrades/public_schema_migration.go similarity index 96% rename from pkg/migration/migrations/public_schema_migration.go rename to pkg/upgrade/upgrades/public_schema_migration.go index a14621024d3a..a4ab8d5f4baa 100644 --- a/pkg/migration/migrations/public_schema_migration.go +++ b/pkg/upgrade/upgrades/public_schema_migration.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -17,7 +17,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/catalog" @@ -30,10 +29,11 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc" "github.com/cockroachdb/cockroach/pkg/sql/privilege" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) func publicSchemaMigration( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { query := ` SELECT ns_db.id @@ -76,7 +76,7 @@ ORDER BY ns_db.id ASC; } func createPublicSchemaForDatabase( - ctx context.Context, dbID descpb.ID, d migration.TenantDeps, + ctx context.Context, dbID descpb.ID, d upgrade.TenantDeps, ) error { return d.CollectionFactory.Txn(ctx, d.InternalExecutor, d.DB, func(ctx context.Context, txn *kv.Txn, descriptors *descs.Collection) error { @@ -89,7 +89,7 @@ func createPublicSchemaDescriptor( txn *kv.Txn, descriptors *descs.Collection, dbID descpb.ID, - d migration.TenantDeps, + d upgrade.TenantDeps, ) error { _, desc, err := descriptors.GetImmutableDatabaseByID(ctx, txn, dbID, tree.DatabaseLookupFlags{Required: true}) if err != nil { @@ -162,7 +162,7 @@ func createPublicSchemaDescriptor( func migrateObjectsInDatabase( ctx context.Context, dbID descpb.ID, - d migration.TenantDeps, + d upgrade.TenantDeps, txn *kv.Txn, newPublicSchemaID descpb.ID, descriptors *descs.Collection, diff --git a/pkg/migration/migrations/public_schema_migration_external_test.go b/pkg/upgrade/upgrades/public_schema_migration_external_test.go similarity index 95% rename from pkg/migration/migrations/public_schema_migration_external_test.go rename to pkg/upgrade/upgrades/public_schema_migration_external_test.go index c77cef6aaee8..aba49aaf93b6 100644 --- a/pkg/migration/migrations/public_schema_migration_external_test.go +++ b/pkg/upgrade/upgrades/public_schema_migration_external_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -39,7 +39,7 @@ func publicSchemaMigrationTest(t *testing.T, ctx context.Context, numTables int) clusterversion.ByKey(clusterversion.PublicSchemasWithDescriptors-1), false, ) - // 2048 KiB batch size - 4x the public schema migration's minBatchSizeInBytes. + // 2048 KiB batch size - 4x the public schema upgrade's minBatchSizeInBytes. const maxCommandSize = 1 << 22 kvserver.MaxCommandSize.Override(ctx, &settings.SV, maxCommandSize) tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ @@ -73,7 +73,7 @@ func publicSchemaMigrationTest(t *testing.T, ctx context.Context, numTables int) tdb.Exec(t, `CREATE TABLE defaultdb.public.t(x INT)`) tdb.Exec(t, `INSERT INTO defaultdb.public.t VALUES (1), (2), (3)`) tdb.Exec(t, `CREATE TYPE defaultdb.public.typ AS ENUM()`) - // Ensure the migration works if we have UDS in the database. + // Ensure the upgrade works if we have UDS in the database. tdb.Exec(t, `CREATE SCHEMA defaultdb.s`) tdb.Exec(t, `CREATE TABLE defaultdb.s.table_in_uds(x INT)`) tdb.Exec(t, `INSERT INTO defaultdb.s.table_in_uds VALUES (1), (2), (3)`) @@ -82,7 +82,7 @@ func publicSchemaMigrationTest(t *testing.T, ctx context.Context, numTables int) // The name of the table is approx 1000 bytes. // Thus, we create approximately 5000 KiB of descriptors in this database. // This is also larger than the 2048 KiB max command size we set. - // The batch size in the migration is 512 KiB so this ensures we have at + // The batch size in the upgrade is 512 KiB so this ensures we have at // least two batches. mkTableName := func(i int) string { return fmt.Sprintf("t%s%d", strings.Repeat("x", 10000), i) @@ -92,9 +92,9 @@ func publicSchemaMigrationTest(t *testing.T, ctx context.Context, numTables int) } // Create a few goroutines which are querying some new tables and might run - // into trouble resolving these tables during the migration. This code is + // into trouble resolving these tables during the upgrade. This code is // to ensure that the resolution logic is robust to the adding of the - // public schema to the migration. + // public schema to the upgrade. var g sync.WaitGroup workerCtx, cancel := context.WithCancel(ctx) defer g.Wait() diff --git a/pkg/migration/migrations/raft_applied_index_term.go b/pkg/upgrade/upgrades/raft_applied_index_term.go similarity index 85% rename from pkg/migration/migrations/raft_applied_index_term.go rename to pkg/upgrade/upgrades/raft_applied_index_term.go index 7b6ea09134b1..fe33e1393a43 100644 --- a/pkg/migration/migrations/raft_applied_index_term.go +++ b/pkg/upgrade/upgrades/raft_applied_index_term.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "bytes" @@ -18,14 +18,14 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/server/serverpb" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util/log" ) // defaultPageSize controls how many ranges are paged in by default when -// iterating through all ranges in a cluster during any given migration. We +// iterating through all ranges in a cluster during any given upgrade. We // pulled this number out of thin air(-ish). Let's consider a cluster with 50k // ranges, with each range taking ~200ms. We're being somewhat conservative with // the duration, but in a wide-area cluster with large hops between the manager @@ -38,7 +38,7 @@ import ( const defaultPageSize = 200 func raftAppliedIndexTermMigration( - ctx context.Context, cv clusterversion.ClusterVersion, deps migration.SystemDeps, _ *jobs.Job, + ctx context.Context, cv clusterversion.ClusterVersion, deps upgrade.SystemDeps, _ *jobs.Job, ) error { var batchIdx, numMigratedRanges int init := func() { batchIdx, numMigratedRanges = 1, 0 } @@ -57,7 +57,7 @@ func raftAppliedIndexTermMigration( } // TODO(irfansharif): Instead of logging this to the debug log, we - // should insert these into a `system.migrations` table for external + // should insert these into a `system.upgrades` table for external // observability. numMigratedRanges += len(descriptors) log.Infof(ctx, "[batch %d/??] migrated %d ranges", batchIdx, numMigratedRanges) @@ -71,7 +71,7 @@ func raftAppliedIndexTermMigration( log.Infof(ctx, "[batch %d/%d] migrated %d ranges", batchIdx, batchIdx, numMigratedRanges) // Make sure that all stores have synced. Given we're a below-raft - // migrations, this ensures that the applied state is flushed to disk. + // upgrades, this ensures that the applied state is flushed to disk. req := &serverpb.SyncAllEnginesRequest{} op := "flush-stores" return deps.Cluster.ForEveryNode(ctx, op, func(ctx context.Context, client serverpb.MigrationClient) error { @@ -81,11 +81,11 @@ func raftAppliedIndexTermMigration( } func postRaftAppliedIndexTermMigration( - ctx context.Context, cv clusterversion.ClusterVersion, deps migration.SystemDeps, _ *jobs.Job, + ctx context.Context, cv clusterversion.ClusterVersion, deps upgrade.SystemDeps, _ *jobs.Job, ) error { // TODO(sumeer): this is copied from postTruncatedStateMigration. In // comparison, postSeparatedIntentsMigration iterated over ranges and issues - // a noop below-raft migration. I am not clear on why there is a difference. + // a noop below-raft upgrade. I am not clear on why there is a difference. // Get this clarified. // Purge all replicas that haven't been migrated to use the unreplicated diff --git a/pkg/migration/migrations/raft_applied_index_term_external_test.go b/pkg/upgrade/upgrades/raft_applied_index_term_external_test.go similarity index 96% rename from pkg/migration/migrations/raft_applied_index_term_external_test.go rename to pkg/upgrade/upgrades/raft_applied_index_term_external_test.go index fa84dd525fdd..44563fc09e37 100644 --- a/pkg/migration/migrations/raft_applied_index_term_external_test.go +++ b/pkg/upgrade/upgrades/raft_applied_index_term_external_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -121,7 +121,7 @@ func TestRaftAppliedIndexTermMigration(t *testing.T) { binaryVersion, bootstrapVersion, false, ) args.Knobs.Server = &server.TestingKnobs{ - // Start at the version immediately preceding the migration. + // Start at the version immediately preceding the upgrade. BinaryVersionOverride: bootstrapVersion, // We want to exercise manual control over the upgrade process. DisableAutomaticVersionUpgrade: make(chan struct{}), @@ -161,7 +161,7 @@ func TestRaftAppliedIndexTermMigration(t *testing.T) { t.Logf("after split: totalReplicas: %d, replicasWithTerm: %d", totalReplicas, replicasWithTerm) } - // Do the migration. + // Do the upgrade. _, err := tc.Conns[0].ExecContext( ctx, `SET CLUSTER SETTING version = $1`, binaryVersion.String(), ) @@ -170,9 +170,9 @@ func TestRaftAppliedIndexTermMigration(t *testing.T) { testutils.SucceedsSoon(t, func() error { return forAllReplicas(tc, func(repl *kvserver.Replica) error { // NB: repl.Version() is not the cluster version. It's the version of - // the highest Migrate() command that has been executed on the range. So - // the migration will set it to AddRaftAppliedIndexTermMigration, since - // there is no Range migration associated with + // the highest Upgrade() command that has been executed on the range. So + // the upgrade will set it to AddRaftAppliedIndexTermMigration, since + // there is no Range upgrade associated with // PostAddRaftAppliedIndexTermMigration. if repl.Version().Less(clusterversion.ByKey( clusterversion.AddRaftAppliedIndexTermMigration)) { diff --git a/pkg/migration/migrations/remove_invalid_database_privileges.go b/pkg/upgrade/upgrades/remove_invalid_database_privileges.go similarity index 79% rename from pkg/migration/migrations/remove_invalid_database_privileges.go rename to pkg/upgrade/upgrades/remove_invalid_database_privileges.go index 4a287655f952..d12d18e4d4a4 100644 --- a/pkg/migration/migrations/remove_invalid_database_privileges.go +++ b/pkg/upgrade/upgrades/remove_invalid_database_privileges.go @@ -8,23 +8,23 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" - "github.com/cockroachdb/cockroach/pkg/migration" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) // runRemoveInvalidDatabasePrivileges calls RunPostDeserializationChanges on // every database descriptor. It also calls RunPostDeserializationChanges on // all table descriptors to add constraint IDs. -// This migration is done to convert invalid privileges on the +// This upgrade is done to convert invalid privileges on the // database to default privileges. func runRemoveInvalidDatabasePrivileges( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { return runPostDeserializationChangesOnAllDescriptors(ctx, d) } diff --git a/pkg/migration/migrations/remove_invalid_database_privileges_external_test.go b/pkg/upgrade/upgrades/remove_invalid_database_privileges_external_test.go similarity index 98% rename from pkg/migration/migrations/remove_invalid_database_privileges_external_test.go rename to pkg/upgrade/upgrades/remove_invalid_database_privileges_external_test.go index 736fdb9437b2..dc6decc59e75 100644 --- a/pkg/migration/migrations/remove_invalid_database_privileges_external_test.go +++ b/pkg/upgrade/upgrades/remove_invalid_database_privileges_external_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations_test +package upgrades_test import ( "context" @@ -112,7 +112,7 @@ func TestConvertIncompatibleDatabasePrivilegesToDefaultPrivileges(t *testing.T) ctx, sqlDB, []*descpb.Descriptor{&desc}, true, /* force */ )) - // Migrate to the new cluster version. + // Upgrade to the new cluster version. tdb.Exec(t, `SET CLUSTER SETTING version = $1`, clusterversion.ByKey(clusterversion.RemoveIncompatibleDatabasePrivileges).String()) diff --git a/pkg/migration/migrations/schema_changes.go b/pkg/upgrade/upgrades/schema_changes.go similarity index 96% rename from pkg/migration/migrations/schema_changes.go rename to pkg/upgrade/upgrades/schema_changes.go index bb45312eb552..59fb39275447 100644 --- a/pkg/migration/migrations/schema_changes.go +++ b/pkg/upgrade/upgrades/schema_changes.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "bytes" @@ -18,13 +18,13 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/protoutil" "github.com/cockroachdb/errors" @@ -43,7 +43,7 @@ type operation struct { schemaExistsFn func(catalog.TableDescriptor, catalog.TableDescriptor, string) (bool, error) } -// migrateTable is run during a migration to a new version and changes an existing +// 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. // @@ -61,7 +61,7 @@ type operation struct { func migrateTable( ctx context.Context, _ clusterversion.ClusterVersion, - d migration.TenantDeps, + d upgrade.TenantDeps, op operation, storedTableID descpb.ID, expectedTable catalog.TableDescriptor, @@ -69,14 +69,14 @@ func migrateTable( for { // - Fetch the table, reading its descriptor from storage. // - Check if any mutation jobs exist for the table. These mutations can - // belong to a previous migration attempt that failed. + // belong to a previous upgrade attempt that failed. // - If any mutation job exists: // - Wait for the ongoing mutations to complete. // - Continue to the beginning of the loop to cater for the mutations // that may have started while waiting for existing mutations to complete. // - Check if the intended schema-changes already exist. // - If the changes already exist, skip the schema-change and return as - // the changes are already done in a previous migration attempt. + // the changes are already done in a previous upgrade attempt. // - Otherwise, perform the schema-change and return. log.Infof(ctx, "performing table migration operation %v", op.name) @@ -134,7 +134,7 @@ func migrateTable( } func readTableDescriptor( - ctx context.Context, d migration.TenantDeps, tableID descpb.ID, + ctx context.Context, d upgrade.TenantDeps, tableID descpb.ID, ) (catalog.TableDescriptor, error) { var t catalog.TableDescriptor diff --git a/pkg/migration/migrations/seed_tenant_span_configs.go b/pkg/upgrade/upgrades/seed_tenant_span_configs.go similarity index 92% rename from pkg/migration/migrations/seed_tenant_span_configs.go rename to pkg/upgrade/upgrades/seed_tenant_span_configs.go index d8a129c84b86..824d5f7f6977 100644 --- a/pkg/migration/migrations/seed_tenant_span_configs.go +++ b/pkg/upgrade/upgrades/seed_tenant_span_configs.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -17,17 +17,17 @@ import ( "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/spanconfig" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/cockroach/pkg/util/hlc" "github.com/cockroachdb/errors" ) func seedTenantSpanConfigsMigration( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { if !d.Codec.ForSystemTenant() { return nil @@ -80,7 +80,7 @@ func seedTenantSpanConfigsMigration( } if len(scRecords) != 0 { // This tenant already has span config records. It was either - // already migrated (migrations need to be idempotent) or it was + // already migrated (upgrades need to be idempotent) or it was // created after PreSeedTenantSpanConfigs was activated. There's // nothing left to do here. continue diff --git a/pkg/migration/migrations/span_count_table.go b/pkg/upgrade/upgrades/span_count_table.go similarity index 91% rename from pkg/migration/migrations/span_count_table.go rename to pkg/upgrade/upgrades/span_count_table.go index e72be831ae25..9675961c457f 100644 --- a/pkg/migration/migrations/span_count_table.go +++ b/pkg/upgrade/upgrades/span_count_table.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" @@ -16,19 +16,19 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/errors" ) // spanCountTableMigration creates the system.span_count table for secondary // tenants. func spanCountTableMigration( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { if d.Codec.ForSystemTenant() { return nil // only applicable for secondary tenants @@ -42,7 +42,7 @@ func spanCountTableMigration( // seedSpanCountTableMigration seeds system.span_count with data for existing // secondary tenants. func seedSpanCountTableMigration( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { if d.Codec.ForSystemTenant() { return nil // only applicable for secondary tenants diff --git a/pkg/migration/migrations/tenant_settings.go b/pkg/upgrade/upgrades/tenant_settings.go similarity index 84% rename from pkg/migration/migrations/tenant_settings.go rename to pkg/upgrade/upgrades/tenant_settings.go index 44a6c08a01da..1e84f930efd3 100644 --- a/pkg/migration/migrations/tenant_settings.go +++ b/pkg/upgrade/upgrades/tenant_settings.go @@ -8,21 +8,21 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package migrations +package upgrades import ( "context" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" - "github.com/cockroachdb/cockroach/pkg/migration" "github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema" + "github.com/cockroachdb/cockroach/pkg/upgrade" ) // tenantSettingsTableMigration creates the system.tenant_settings table (for the // system tenant). func tenantSettingsTableMigration( - ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, _ *jobs.Job, + ctx context.Context, _ clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error { // Only create the table on the system tenant. if !d.Codec.ForSystemTenant() { diff --git a/pkg/migration/migrations/testdata/separated_intents b/pkg/upgrade/upgrades/testdata/separated_intents similarity index 100% rename from pkg/migration/migrations/testdata/separated_intents rename to pkg/upgrade/upgrades/testdata/separated_intents diff --git a/pkg/migration/migrations/migrations.go b/pkg/upgrade/upgrades/upgrades.go similarity index 73% rename from pkg/migration/migrations/migrations.go rename to pkg/upgrade/upgrades/upgrades.go index 190bfc3561f6..83570ba44525 100644 --- a/pkg/migration/migrations/migrations.go +++ b/pkg/upgrade/upgrades/upgrades.go @@ -8,136 +8,136 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -// Package migrations contains the implementation of migrations. It is imported +// Package upgrades contains the implementation of upgrades. It is imported // by the server library. // -// This package registers the migrations with the migration package. -package migrations +// This package registers the upgrades with the upgrade package. +package upgrades import ( "context" "github.com/cockroachdb/cockroach/pkg/clusterversion" - "github.com/cockroachdb/cockroach/pkg/migration" + "github.com/cockroachdb/cockroach/pkg/upgrade" "github.com/cockroachdb/errors" ) -// GetMigration returns the migration corresponding to this version if +// GetUpgrade returns the upgrade corresponding to this version if // one exists. -func GetMigration(key clusterversion.ClusterVersion) (migration.Migration, bool) { +func GetUpgrade(key clusterversion.ClusterVersion) (upgrade.Upgrade, bool) { m, ok := registry[key] return m, ok } // NoPrecondition is a PreconditionFunc that doesn't check anything. -func NoPrecondition(context.Context, clusterversion.ClusterVersion, migration.TenantDeps) error { +func NoPrecondition(context.Context, clusterversion.ClusterVersion, upgrade.TenantDeps) error { return nil } // registry defines the global mapping between a cluster version and the -// associated migration. The migration is only executed after a cluster-wide +// associated upgrade. The upgrade is only executed after a cluster-wide // bump of the corresponding version gate. -var registry = make(map[clusterversion.ClusterVersion]migration.Migration) +var registry = make(map[clusterversion.ClusterVersion]upgrade.Upgrade) -var migrations = []migration.Migration{ - migration.NewTenantMigration( +var upgrades = []upgrade.Upgrade{ + upgrade.NewTenantUpgrade( "ensure that draining names are no longer in use", toCV(clusterversion.DrainingNamesMigration), NoPrecondition, ensureNoDrainingNames, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "add column avgSize to table system.table_statistics", toCV(clusterversion.AlterSystemTableStatisticsAddAvgSizeCol), NoPrecondition, alterSystemTableStatisticsAddAvgSize, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "update system.statement_diagnostics_requests table to support conditional stmt diagnostics", toCV(clusterversion.AlterSystemStmtDiagReqs), NoPrecondition, alterSystemStmtDiagReqs, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "seed system.span_configurations with configs for existing tenants", toCV(clusterversion.SeedTenantSpanConfigs), NoPrecondition, seedTenantSpanConfigsMigration, ), - migration.NewTenantMigration("insert missing system.namespace entries for public schemas", + upgrade.NewTenantUpgrade("insert missing system.namespace entries for public schemas", toCV(clusterversion.InsertPublicSchemaNamespaceEntryOnRestore), NoPrecondition, insertMissingPublicSchemaNamespaceEntry, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "add column target to system.protected_ts_records", toCV(clusterversion.AlterSystemProtectedTimestampAddColumn), NoPrecondition, alterTableProtectedTimestampRecords, ), - migration.NewTenantMigration("update synthetic public schemas to be backed by a descriptor", + upgrade.NewTenantUpgrade("update synthetic public schemas to be backed by a descriptor", toCV(clusterversion.PublicSchemasWithDescriptors), NoPrecondition, publicSchemaMigration, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "enable span configs infrastructure", toCV(clusterversion.EnsureSpanConfigReconciliation), NoPrecondition, ensureSpanConfigReconciliation, ), - migration.NewSystemMigration( + upgrade.NewSystemUpgrade( "enable span configs infrastructure", toCV(clusterversion.EnsureSpanConfigSubscription), ensureSpanConfigSubscription, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "track grant options on users and enable granting/revoking with them", toCV(clusterversion.ValidateGrantOption), NoPrecondition, grantOptionMigration, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "delete comments that belong to dropped indexes", toCV(clusterversion.DeleteCommentsWithDroppedIndexes), NoPrecondition, ensureCommentsHaveNonDroppedIndexes, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "convert incompatible database privileges to default privileges", toCV(clusterversion.RemoveIncompatibleDatabasePrivileges), NoPrecondition, runRemoveInvalidDatabasePrivileges, ), - migration.NewSystemMigration( + upgrade.NewSystemUpgrade( "populate RangeAppliedState.RaftAppliedIndexTerm for all ranges", toCV(clusterversion.AddRaftAppliedIndexTermMigration), raftAppliedIndexTermMigration, ), - migration.NewSystemMigration( + upgrade.NewSystemUpgrade( "purge all replicas not populating RangeAppliedState.RaftAppliedIndexTerm", toCV(clusterversion.PostAddRaftAppliedIndexTermMigration), postRaftAppliedIndexTermMigration, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "add the system.tenant_settings table", toCV(clusterversion.TenantSettingsTable), NoPrecondition, tenantSettingsTableMigration, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "Rewrites cast that are negatively affected by DateStyle/IntervalStyle", toCV(clusterversion.DateStyleIntervalStyleCastRewrite), NoPrecondition, fixCastForStyleMigration, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "add the system.span_count table", toCV(clusterversion.SpanCountTable), NoPrecondition, spanCountTableMigration, ), - migration.NewTenantMigration( + upgrade.NewTenantUpgrade( "seed system.span_count with span count for existing tenants", toCV(clusterversion.SeedSpanCountTable), NoPrecondition, @@ -146,9 +146,9 @@ var migrations = []migration.Migration{ } func init() { - for _, m := range migrations { + for _, m := range upgrades { if _, exists := registry[m.ClusterVersion()]; exists { - panic(errors.AssertionFailedf("duplicate migration registration for %v", m.ClusterVersion())) + panic(errors.AssertionFailedf("duplicate upgrade registration for %v", m.ClusterVersion())) } registry[m.ClusterVersion()] = m }