diff --git a/pkg/clusterversion/cluster_version.pb.go b/pkg/clusterversion/cluster_version.pb.go index 4e109feac915..95952071b650 100644 --- a/pkg/clusterversion/cluster_version.pb.go +++ b/pkg/clusterversion/cluster_version.pb.go @@ -33,7 +33,7 @@ type ClusterVersion struct { func (m *ClusterVersion) Reset() { *m = ClusterVersion{} } func (*ClusterVersion) ProtoMessage() {} func (*ClusterVersion) Descriptor() ([]byte, []int) { - return fileDescriptor_cluster_version_1bc4b027714f9c3f, []int{0} + return fileDescriptor_cluster_version_d76e19b7fb1f16de, []int{0} } func (m *ClusterVersion) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -59,7 +59,7 @@ func (m *ClusterVersion) XXX_DiscardUnknown() { var xxx_messageInfo_ClusterVersion proto.InternalMessageInfo func init() { - proto.RegisterType((*ClusterVersion)(nil), "cockroach.base.ClusterVersion") + proto.RegisterType((*ClusterVersion)(nil), "cockroach.clusterversion.ClusterVersion") } func (this *ClusterVersion) Equal(that interface{}) bool { if that == nil { @@ -330,23 +330,23 @@ var ( ) func init() { - proto.RegisterFile("clusterversion/cluster_version.proto", fileDescriptor_cluster_version_1bc4b027714f9c3f) + proto.RegisterFile("clusterversion/cluster_version.proto", fileDescriptor_cluster_version_d76e19b7fb1f16de) } -var fileDescriptor_cluster_version_1bc4b027714f9c3f = []byte{ - // 214 bytes of a gzipped FileDescriptorProto +var fileDescriptor_cluster_version_d76e19b7fb1f16de = []byte{ + // 212 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0xce, 0x29, 0x2d, 0x2e, 0x49, 0x2d, 0x2a, 0x4b, 0x2d, 0x2a, 0xce, 0xcc, 0xcf, 0xd3, 0x87, 0x72, 0xe3, 0xa1, 0x7c, - 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0xbe, 0xe4, 0xfc, 0xe4, 0xec, 0xa2, 0xfc, 0xc4, 0xe4, - 0x0c, 0xbd, 0xa4, 0xc4, 0xe2, 0x54, 0x29, 0x31, 0x30, 0xbb, 0x20, 0x49, 0x3f, 0x37, 0xb5, 0x24, - 0x31, 0x25, 0xb1, 0x24, 0x11, 0xa2, 0x4e, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, 0x07, - 0xb1, 0x20, 0xa2, 0x4a, 0xb9, 0x5c, 0x7c, 0xce, 0x10, 0x63, 0xc3, 0x20, 0xa6, 0x0a, 0x79, 0x73, - 0xf1, 0x25, 0x26, 0x97, 0x64, 0x96, 0xa5, 0xc2, 0xec, 0x91, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x36, - 0x92, 0xd2, 0x43, 0x58, 0x04, 0xb5, 0x42, 0x0f, 0xaa, 0xc7, 0x89, 0xe3, 0xc4, 0x3d, 0x79, 0x86, - 0x0b, 0xf7, 0xe4, 0x19, 0x83, 0x78, 0x21, 0x7a, 0xa1, 0x12, 0x56, 0x1c, 0x33, 0x16, 0xc8, 0x33, - 0xbc, 0x58, 0x20, 0xcf, 0xe8, 0xc5, 0xc2, 0xc1, 0x28, 0xc0, 0xe4, 0x64, 0x70, 0xe2, 0xa1, 0x1c, - 0xc3, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0xde, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, - 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xc5, - 0x87, 0xea, 0xe9, 0x24, 0x36, 0xb0, 0x3b, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x11, 0xdd, - 0x63, 0x6c, 0x0d, 0x01, 0x00, 0x00, + 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0x89, 0xe4, 0xfc, 0xe4, 0xec, 0xa2, 0xfc, 0xc4, 0xe4, + 0x0c, 0x3d, 0x54, 0xf5, 0x52, 0x62, 0x60, 0xd1, 0x82, 0x24, 0xfd, 0xdc, 0xd4, 0x92, 0xc4, 0x94, + 0xc4, 0x92, 0x44, 0x88, 0x0e, 0x29, 0x91, 0xf4, 0xfc, 0xf4, 0x7c, 0x30, 0x53, 0x1f, 0xc4, 0x82, + 0x88, 0x2a, 0xe5, 0x72, 0xf1, 0x39, 0x43, 0xf4, 0x87, 0x41, 0xf4, 0x0b, 0x79, 0x73, 0xf1, 0x25, + 0x26, 0x97, 0x64, 0x96, 0xa5, 0xc2, 0x6c, 0x94, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x36, 0x92, 0xd2, + 0x43, 0x58, 0x09, 0xb5, 0x42, 0x0f, 0xaa, 0xc7, 0x89, 0xe3, 0xc4, 0x3d, 0x79, 0x86, 0x0b, 0xf7, + 0xe4, 0x19, 0x83, 0x78, 0x21, 0x7a, 0xa1, 0x12, 0x56, 0x1c, 0x33, 0x16, 0xc8, 0x33, 0xbc, 0x58, + 0x20, 0xcf, 0xe8, 0xc5, 0xc2, 0xc1, 0x28, 0xc0, 0xe4, 0x64, 0x70, 0xe2, 0xa1, 0x1c, 0xc3, 0x89, + 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0xde, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, + 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xc5, 0x87, 0xea, + 0x9d, 0x24, 0x36, 0xb0, 0x3b, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7d, 0xac, 0xaa, 0x79, + 0x17, 0x01, 0x00, 0x00, } diff --git a/pkg/clusterversion/cluster_version.proto b/pkg/clusterversion/cluster_version.proto index 85407e62a50b..e3abd5db8e5a 100644 --- a/pkg/clusterversion/cluster_version.proto +++ b/pkg/clusterversion/cluster_version.proto @@ -9,7 +9,7 @@ // licenses/APL.txt. syntax = "proto3"; -package cockroach.base; +package cockroach.clusterversion; option go_package = "clusterversion"; import "roachpb/metadata.proto"; diff --git a/pkg/clusterversion/clusterversion.go b/pkg/clusterversion/clusterversion.go index 010f7795f5f3..61d9e6ca8041 100644 --- a/pkg/clusterversion/clusterversion.go +++ b/pkg/clusterversion/clusterversion.go @@ -82,7 +82,7 @@ type Handle interface { // // If this returns true then all nodes in the cluster will eventually see // this version. However, this is not atomic because version gates (for a - // given version) are pushed through to each node in parallel. Because of + // given version) are pushed through to each node concurrently. Because of // this, nodes should not be gating proper handling of remotely initiated // requests that their binary knows how to handle on this state. The // following example shows why this is important: diff --git a/pkg/clusterversion/cockroach_versions.go b/pkg/clusterversion/cockroach_versions.go index 7604fcb25aee..0ecedb516ba4 100644 --- a/pkg/clusterversion/cockroach_versions.go +++ b/pkg/clusterversion/cockroach_versions.go @@ -15,53 +15,228 @@ import "github.com/cockroachdb/cockroach/pkg/roachpb" // VersionKey is a unique identifier for a version of CockroachDB. type VersionKey int -// Version constants. +// Version constants. You'll want to add a new one in the following cases: // -// To add a version: -// - Add it at the end of this block. -// - Add it at the end of the `Versions` block below. -// - For major or minor versions, bump binaryMinSupportedVersion. For -// example, if introducing the `20.1` release, bump it to -// VersionStart19_2 (i.e. `19.1-1`). +// (a) When introducing a backwards incompatible feature. Broadly, by this we +// mean code that's structured as follows: // -// To delete a version. -// - Remove its associated runtime checks. -// - If the version is not the latest one, delete the constant and remove its -// entry in the versionsSingleton. +// if (specific-version is active) { +// // Implies that all nodes in the cluster are running binaries that +// // have this code. We can "enable" the new feature knowing that +// // outbound RPCs, requests, etc. will be handled by nodes that know +// // how to do so. +// } else { +// // There may be some nodes running older binaries without this code. +// // To be safe, we'll want to behave as we did before introducing +// // this feature. +// } +// +// Authors of migrations need to be careful in ensuring that end-users +// aren't able to enable feature gates before they're active. This is fine: +// +// func handleSomeNewStatement() error { +// if !(specific-version is active) { +// return errors.New("cluster version needs to be bumped") +// } +// // ... +// } +// +// At the same time, with requests/RPCs originating at other crdb nodes, the +// initiator of the request gets to decide what's supported. A node should +// not refuse functionality on the grounds that its view of the version gate +// is as yet inactive. Consider the sender: +// +// func invokeSomeRPC(req) { +// if (specific-version is active) { +// // Like mentioned above, this implies that all nodes in the +// // cluster are running binaries that can handle this new +// // feature. We may have learned about this fact before the +// // node on the other end. This is due to the fact that migration +// // manager informs each node about the specific-version being +// // activated active concurrently. See BumpClusterVersion for +// // where that happens. Still, it's safe for us to enable the new +// // feature flags as we trust the recipient to know how to deal +// // with it. +// req.NewFeatureFlag = true +// } +// send(req) +// } +// +// And consider the recipient: +// +// func someRPC(req) { +// if !req.NewFeatureFlag { +// // Legacy behavior... +// } +// // There's no need to even check if the specific-version is active. +// // If the flag is enabled, the specific-version must have been +// // activated, even if we haven't yet heard about it (we will pretty +// // soon). +// } +// +// See clusterversion.Handle.IsActive and usage of some existing versions +// below for more clues on the matter. +// +// (b) When cutting a major release branch. When cutting release-20.2 for +// example, you'll want to introduce the following to `master`. +// +// (i) Version20_2 (keyed to v20.2.0-0}) +// (ii) VersionStart21_1 (keyed to v20.2.0-1}) +// +// You'll then want to backport (i) to the release branch itself (i.e. +// release-20.2). You'll also want to bump binaryMinSupportedVersion. In the +// example above, you'll set it to Version20_2. This indicates that the +// minimum binary version required in a cluster with with nodes running +// v21.1 binaries (including pre-release alphas) is v20.2, i.e. that an +// upgrade into such a binary must start out from at least v20.2 nodes. +// +// Aside: At the time of writing, the binary min supported version is the +// last major release, though we may consider relaxing this in the future +// (i.e. for example could skip up to one major release) as we move to a more +// frequent release schedule. +// +// When introducing a version constant, you'll want to: +// (1) Add it at the end of this block +// (2) Add it at the end of the `versionsSingleton` block below. +// +// --- +// +// You'll want to delete versions from this list after cutting a major release. +// Once the development for 21.1 begins, after step (ii) from above, all +// versions introduced in the previous release can be removed (everything prior +// to Version20_2 in our example). +// +// When removing a version, you'll want to remove its associated runtime checks. +// All "is active" checks for the key will always evaluate to true. You'll also +// want to delete the constant and remove its entry in the `versionsSingleton` +// block below. // //go:generate stringer -type=VersionKey const ( _ VersionKey = iota - 1 // want first named one to start at zero + + // Version19_1 is CockroachDB v19.1. It's used for all v19.1.x patch + // releases. Version19_1 + + // v20.1 versions. + // + // VersionContainsEstimatesCounter is + // https://github.com/cockroachdb/cockroach/pull/37583. + // + // MVCCStats.ContainsEstimates has been migrated from boolean to a + // counter so that the consistency checker and splits can reset it by + // returning -ContainsEstimates, avoiding racing with other operations + // that want to also change it. + // + // The migration maintains the invariant that raft commands with + // ContainsEstimates zero or one want the bool behavior (i.e. 1+1=1). + // Before the cluster version is active, at proposal time we'll refuse + // any negative ContainsEstimates plus we clamp all others to {0,1}. + // When the version is active, and ContainsEstimates is positive, we + // multiply it by 2 (i.e. we avoid 1). Downstream of raft, we use old + // behavior for ContainsEstimates=1 and the additive behavior for + // anything else. VersionContainsEstimatesCounter + // VersionNamespaceTableWithSchemas is + // https://github.com/cockroachdb/cockroach/pull/41977 + // + // It represents the migration to a new system.namespace table that has an + // added parentSchemaID column. In addition to the new column, the table is + // no longer in the system config range -- implying it is no longer gossiped. VersionNamespaceTableWithSchemas + // VersionAuthLocalAndTrustRejectMethods introduces the HBA rule + // prefix 'local' and auth methods 'trust' and 'reject', for use + // in server.host_based_authentication.configuration. + // + // A separate cluster version ensures the new syntax is not + // introduced while previous-version nodes are still running, as + // this would block any new SQL client. VersionAuthLocalAndTrustRejectMethods + + // TODO(irfansharif): The versions above can/should all be removed. They + // were orinally introduced in v20.1. There are inflight PRs to do so + // (#57155, #57156, #57158). + + // v20.2 versions. + // + // VersionStart20_2 demarcates work towards CockroachDB v20.2. VersionStart20_2 + // VersionGeospatialType enables the use of Geospatial features. VersionGeospatialType + // VersionEnums enables the use of ENUM types. VersionEnums + // VersionRangefeedLeases is the enablement of leases uses rangefeeds. All + // nodes with this versions will have rangefeeds enabled on all system + // ranges. Once this version is finalized, gossip is not needed in the + // schema lease subsystem. Nodes which start with this version finalized + // will not pass gossip to the SQL layer. VersionRangefeedLeases + // VersionAlterColumnTypeGeneral enables the use of alter column type for + // conversions that require the column data to be rewritten. VersionAlterColumnTypeGeneral + // VersionAlterSystemJobsTable is a version which modified system.jobs + // table. VersionAlterSystemJobsAddCreatedByColumns + // VersionAddScheduledJobsTable is a version which adds + // system.scheduled_jobs table. VersionAddScheduledJobsTable + // VersionUserDefinedSchemas enables the creation of user defined schemas. VersionUserDefinedSchemas + // VersionNoOriginFKIndexes allows for foreign keys to no longer need + // indexes on the origin side of the relationship. VersionNoOriginFKIndexes + // VersionClientRangeInfosOnBatchResponse moves the response RangeInfos from + // individual response headers to the batch header. VersionClientRangeInfosOnBatchResponse + // VersionNodeMembershipStatus gates the usage of the MembershipStatus enum + // in the Liveness proto. See comment on proto definition for more details. VersionNodeMembershipStatus + // VersionRangeStatsRespHasDesc adds the RangeStatsResponse.RangeInfo field. VersionRangeStatsRespHasDesc + // VersionMinPasswordLength adds the server.user_login.min_password_length + // setting. VersionMinPasswordLength + // VersionAbortSpanBytes adds a field to MVCCStats + // (MVCCStats.AbortSpanBytes) that tracks the size of a range's abort span. VersionAbortSpanBytes + // VersionAlterSystemJobsTableAddLeaseColumn is a version which modified + // system.jobs table. VersionAlterSystemJobsAddSqllivenessColumnsAddNewSystemSqllivenessTable + // VersionMaterializedViews enables the use of materialized views. VersionMaterializedViews + // VersionBox2DType enables the use of the box2d type. VersionBox2DType + // VersionLeasedDatabasedDescriptors enables leased database descriptors. + // Now that we unconditionally use leased descriptors in 21.1 and the main + // usages of this version gate have been removed, this version remains to + // gate a few miscellaneous database descriptor changes. VersionLeasedDatabaseDescriptors + // VersionUpdateScheduledJobsSchema drops schedule_changes and adds + // schedule_status. VersionUpdateScheduledJobsSchema + // VersionCreateLoginPrivilege is when CREATELOGIN/NOCREATELOGIN are + // introduced. + // + // It represents adding authn principal management via CREATELOGIN role + // option. VersionCreateLoginPrivilege + // VersionHBAForNonTLS is when the 'hostssl' and 'hostnossl' HBA configs are + // introduced. VersionHBAForNonTLS + // Version20_2 is CockroachDB v20.2. It's used for all v20.2.x patch + // releases. Version20_2 + + // v21.1 versions. + // + // VersionStart21_1 demarcates work towards CockroachDB v21.1. VersionStart21_1 + // VersionEmptyArraysInInvertedIndexes is when empty arrays are added to + // array inverted indexes. VersionEmptyArraysInInvertedIndexes - // Add new versions here (step one of two). + // Step (1): Add new versions here. ) // versionsSingleton lists all historical versions here in chronological order, @@ -83,193 +258,123 @@ const ( // to be added (i.e., when cutting the final release candidate). var versionsSingleton = keyedVersions([]keyedVersion{ { - // Version19_1 is CockroachDB v19.1. It's used for all v19.1.x patch releases. Key: Version19_1, Version: roachpb.Version{Major: 19, Minor: 1}, }, { - // VersionContainsEstimatesCounter is https://github.com/cockroachdb/cockroach/pull/37583. - // - // MVCCStats.ContainsEstimates has been migrated from boolean to a - // counter so that the consistency checker and splits can reset it by - // returning -ContainsEstimates, avoiding racing with other operations - // that want to also change it. - // - // The migration maintains the invariant that raft commands with - // ContainsEstimates zero or one want the bool behavior (i.e. 1+1=1). - // Before the cluster version is active, at proposal time we'll refuse - // any negative ContainsEstimates plus we clamp all others to {0,1}. - // When the version is active, and ContainsEstimates is positive, we - // multiply it by 2 (i.e. we avoid 1). Downstream of raft, we use old - // behavior for ContainsEstimates=1 and the additive behavior for - // anything else. Key: VersionContainsEstimatesCounter, Version: roachpb.Version{Major: 19, Minor: 2, Internal: 2}, }, { - // VersionNamespaceTableWithSchemas is https://github.com/cockroachdb/cockroach/pull/41977 - // - // It represents the migration to a new system.namespace table that has an - // added parentSchemaID column. In addition to the new column, the table is - // no longer in the system config range -- implying it is no longer gossiped. Key: VersionNamespaceTableWithSchemas, Version: roachpb.Version{Major: 19, Minor: 2, Internal: 5}, }, { - // VersionAuthLocalAndTrustRejectMethods introduces the HBA rule - // prefix 'local' and auth methods 'trust' and 'reject', for use - // in server.host_based_authentication.configuration. - // - // A separate cluster version ensures the new syntax is not - // introduced while previous-version nodes are still running, as - // this would block any new SQL client. Key: VersionAuthLocalAndTrustRejectMethods, Version: roachpb.Version{Major: 19, Minor: 2, Internal: 8}, }, + + // v20.2 versions. { - // VersionStart20_2 demarcates work towards CockroachDB v20.2. Key: VersionStart20_2, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 1}, }, { - - // VersionGeospatialType enables the use of Geospatial features. Key: VersionGeospatialType, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 2}, }, { - // VersionEnums enables the use of ENUM types. Key: VersionEnums, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 3}, }, { - - // VersionRangefeedLeases is the enablement of leases uses rangefeeds. - // All nodes with this versions will have rangefeeds enabled on all system - // ranges. Once this version is finalized, gossip is not needed in the - // schema lease subsystem. Nodes which start with this version finalized - // will not pass gossip to the SQL layer. Key: VersionRangefeedLeases, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 4}, }, { - // VersionAlterColumnTypeGeneral enables the use of alter column type for - // conversions that require the column data to be rewritten. Key: VersionAlterColumnTypeGeneral, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 5}, }, { - // VersionAlterSystemJobsTable is a version which modified system.jobs table. Key: VersionAlterSystemJobsAddCreatedByColumns, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 6}, }, { - // VersionAddScheduledJobsTable is a version which adds system.scheduled_jobs table. Key: VersionAddScheduledJobsTable, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 7}, }, { - // VersionUserDefinedSchemas enables the creation of user defined schemas. Key: VersionUserDefinedSchemas, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 8}, }, { - // VersionNoOriginFKIndexes allows for foreign keys to no longer need - // indexes on the origin side of the relationship. Key: VersionNoOriginFKIndexes, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 9}, }, { - // VersionClientRangeInfosOnBatchResponse moves the response RangeInfos from - // individual response headers to the batch header. Key: VersionClientRangeInfosOnBatchResponse, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 10}, }, { - // VersionNodeMembershipStatus gates the usage of the MembershipStatus - // enum in the Liveness proto. See comment on proto definition for more - // details. Key: VersionNodeMembershipStatus, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 11}, }, { - // VersionRangeStatsRespHasDesc adds the RangeStatsResponse.RangeInfo field. Key: VersionRangeStatsRespHasDesc, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 12}, }, { - // VersionMinPasswordLength adds the server.user_login.min_password_length setting. Key: VersionMinPasswordLength, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 13}, }, { - // VersionAbortSpanBytes adds a field to MVCCStats - // (MVCCStats.AbortSpanBytes) that tracks the size of a - // range's abort span. Key: VersionAbortSpanBytes, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 14}, }, { - // VersionAlterSystemJobsTableAddLeaseColumn is a version which modified system.jobs table. Key: VersionAlterSystemJobsAddSqllivenessColumnsAddNewSystemSqllivenessTable, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 15}, }, { - // VersionMaterializedViews enables the use of materialized views. Key: VersionMaterializedViews, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 16}, }, { - // VersionBox2DType enables the use of the box2d type. Key: VersionBox2DType, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 17}, }, { - // VersionLeasedDatabasedDescriptors enables leased database descriptors. - // Now that we unconditionally use leased descriptors in 21.1 and the main - // usages of this version gate have been removed, this version remains to - // gate a few miscellaneous database descriptor changes. Key: VersionLeasedDatabaseDescriptors, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 18}, }, { - // VersionUpdateScheduledJobsSchema drops schedule_changes and adds schedule_status. Key: VersionUpdateScheduledJobsSchema, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 19}, }, { - // VersionCreateLoginPrivilege is when CREATELOGIN/NOCREATELOGIN - // are introduced. - // - // It represents adding authn principal management via CREATELOGIN - // role option. Key: VersionCreateLoginPrivilege, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 20}, }, { - // VersionHBAForNonTLS is when the 'hostssl' and 'hostnossl' HBA - // configs are introduced. Key: VersionHBAForNonTLS, Version: roachpb.Version{Major: 20, Minor: 1, Internal: 21}, }, { - // Version20_2 is CockroachDB v20.2. It's used for all v20.2.x patch releases. Key: Version20_2, Version: roachpb.Version{Major: 20, Minor: 2}, }, + + // v21.1 versions. { - // VersionStart21_1 demarcates work towards CockroachDB v21.1. Key: VersionStart21_1, Version: roachpb.Version{Major: 20, Minor: 2, Internal: 1}, }, { - // VersionEmptyArraysInInvertedIndexes is when empty arrays are added to - // array inverted indexes. Key: VersionEmptyArraysInInvertedIndexes, Version: roachpb.Version{Major: 20, Minor: 2, Internal: 2}, }, - // Add new versions here (step two of two). + // Step (2): Add new versions here. }) // TODO(irfansharif): clusterversion.binary{,MinimumSupported}Version diff --git a/pkg/migration/BUILD.bazel b/pkg/migration/BUILD.bazel index d669c27d2ae4..c02fd0142384 100644 --- a/pkg/migration/BUILD.bazel +++ b/pkg/migration/BUILD.bazel @@ -10,6 +10,7 @@ go_library( importpath = "github.com/cockroachdb/cockroach/pkg/migration", visibility = ["//visibility:public"], deps = [ + "//pkg/clusterversion", "//pkg/kv", "//pkg/kv/kvserver/liveness/livenesspb", "//pkg/roachpb", diff --git a/pkg/migration/manager.go b/pkg/migration/manager.go index 7846f7883932..adc931f12cf4 100644 --- a/pkg/migration/manager.go +++ b/pkg/migration/manager.go @@ -24,6 +24,7 @@ package migration import ( "context" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" @@ -188,14 +189,18 @@ func NewManager( } } -// MigrateTo runs the set of migrations required to upgrade the cluster version -// to the provided target version. -// -// TODO(irfansharif): Do something real here. -func (m *Manager) MigrateTo(ctx context.Context, targetV roachpb.Version) error { +// Migrate runs the set of migrations required to upgrade the cluster version +// from the current version to the target one. +func (m *Manager) Migrate(ctx context.Context, from, to clusterversion.ClusterVersion) error { + if from == to { + // Nothing to do here. + return nil + } + // TODO(irfansharif): Should we inject every ctx here with specific labels // for each migration, so they log distinctly? ctx = logtags.AddTag(ctx, "migration-mgr", nil) + log.Infof(ctx, "migrating cluster from %s to %s", from, to) // TODO(irfansharif): We'll need to acquire a lease here and refresh it // throughout during the migration to ensure mutual exclusion. @@ -242,9 +247,9 @@ func (m *Manager) MigrateTo(ctx context.Context, targetV roachpb.Version) error // defining migrations is that they'd only care about introducing the next // version key within pkg/clusterversion, and registering a corresponding // migration for it here. - var vs = []roachpb.Version{targetV} + var clusterVersions = []clusterversion.ClusterVersion{to} - for _, version := range vs { + for _, clusterVersion := range clusterVersions { h := &Helper{Manager: m} // Push out the version gate to every node in the cluster. Each node @@ -255,7 +260,9 @@ func (m *Manager) MigrateTo(ctx context.Context, targetV roachpb.Version) error { // First sanity check that we'll actually be able to perform the // cluster version bump, cluster-wide. - req := &serverpb.ValidateTargetClusterVersionRequest{Version: &version} + req := &serverpb.ValidateTargetClusterVersionRequest{ + ClusterVersion: &clusterVersion, + } err := h.EveryNode(ctx, "validate-cv", func(ctx context.Context, client serverpb.MigrationClient) error { _, err := client.ValidateTargetClusterVersion(ctx, req) return err @@ -265,7 +272,9 @@ func (m *Manager) MigrateTo(ctx context.Context, targetV roachpb.Version) error } } { - req := &serverpb.BumpClusterVersionRequest{Version: &version} + req := &serverpb.BumpClusterVersionRequest{ + ClusterVersion: &clusterVersion, + } err := h.EveryNode(ctx, "bump-cv", func(ctx context.Context, client serverpb.MigrationClient) error { _, err := client.BumpClusterVersion(ctx, req) return err @@ -280,7 +289,7 @@ func (m *Manager) MigrateTo(ctx context.Context, targetV roachpb.Version) error // TODO(irfansharif): We'll want to be able to override which migration // is retrieved here within tests. We could make the registry be a part // of the manager, and all tests to provide their own. - _ = Registry[version] + _ = Registry[clusterVersion] } return nil diff --git a/pkg/migration/migrations.go b/pkg/migration/migrations.go index cf3941ea0d53..e3b0be47ed53 100644 --- a/pkg/migration/migrations.go +++ b/pkg/migration/migrations.go @@ -10,12 +10,12 @@ package migration -import "github.com/cockroachdb/cockroach/pkg/roachpb" +import "github.com/cockroachdb/cockroach/pkg/clusterversion" -// Registry defines the global mapping between a version, and the associated -// migration. The migration is only executed after a cluster-wide bump of the -// version gate. -var Registry = make(map[roachpb.Version]Migration) +// Registry defines the global mapping between a cluster version, and the +// associated migration. The migration is only executed after a cluster-wide +// bump of the version gate. +var Registry = make(map[clusterversion.ClusterVersion]Migration) func init() { // TODO(irfansharif): We'll want to register individual migrations with diff --git a/pkg/server/migration.go b/pkg/server/migration.go index 513cf243693a..1690fc401cf3 100644 --- a/pkg/server/migration.go +++ b/pkg/server/migration.go @@ -14,7 +14,6 @@ import ( "context" "fmt" - "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/kv/kvserver" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/util/log" @@ -40,22 +39,22 @@ var _ serverpb.MigrationServer = &migrationServer{} func (m *migrationServer) ValidateTargetClusterVersion( ctx context.Context, req *serverpb.ValidateTargetClusterVersionRequest, ) (*serverpb.ValidateTargetClusterVersionResponse, error) { - targetVersion := *req.Version + targetCV := req.ClusterVersion versionSetting := m.server.ClusterSettings().Version // We're validating the following: // // node's minimum supported version <= target version <= node's binary version - if targetVersion.Less(versionSetting.BinaryMinSupportedVersion()) { - msg := fmt.Sprintf("target version %s less than binary's min supported version %s", - targetVersion, versionSetting.BinaryMinSupportedVersion()) + if targetCV.Less(versionSetting.BinaryMinSupportedVersion()) { + msg := fmt.Sprintf("target cluster version %s less than binary's min supported version %s", + targetCV, versionSetting.BinaryMinSupportedVersion()) log.Warningf(ctx, "%s", msg) return nil, errors.Newf("%s", redact.Safe(msg)) } - if versionSetting.BinaryVersion().Less(targetVersion) { - msg := fmt.Sprintf("binary version %s less than target version %s", - versionSetting.BinaryVersion(), targetVersion) + if versionSetting.BinaryVersion().Less(targetCV.Version) { + msg := fmt.Sprintf("binary version %s less than target cluster version %s", + versionSetting.BinaryVersion(), targetCV) log.Warningf(ctx, "%s", msg) return nil, errors.Newf("%s", redact.Safe(msg)) } @@ -82,10 +81,10 @@ func (m *migrationServer) BumpClusterVersion( return nil, err } - newCV := clusterversion.ClusterVersion{Version: *req.Version} + newCV := *req.ClusterVersion if err := func() error { - if !prevCV.Version.Less(*req.Version) { + if !prevCV.Less(newCV.Version) { // Nothing to do. return nil } diff --git a/pkg/server/migration_test.go b/pkg/server/migration_test.go index e5643a1bb614..0056a4d8985e 100644 --- a/pkg/server/migration_test.go +++ b/pkg/server/migration_test.go @@ -15,6 +15,7 @@ import ( "testing" "github.com/cockroachdb/cockroach/pkg/base" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -29,36 +30,39 @@ func TestValidateTargetClusterVersion(t *testing.T) { v := func(major, minor int32) roachpb.Version { return roachpb.Version{Major: major, Minor: minor} } + cv := func(major, minor int32) clusterversion.ClusterVersion { + return clusterversion.ClusterVersion{Version: v(major, minor)} + } var tests = []struct { binaryVersion roachpb.Version binaryMinSupportedVersion roachpb.Version - targetVersion roachpb.Version + targetClusterVersion clusterversion.ClusterVersion expErrMatch string // empty if expecting a nil error }{ { binaryVersion: v(20, 2), binaryMinSupportedVersion: v(20, 1), - targetVersion: v(20, 1), + targetClusterVersion: cv(20, 1), expErrMatch: "", }, { binaryVersion: v(20, 2), binaryMinSupportedVersion: v(20, 1), - targetVersion: v(20, 2), + targetClusterVersion: cv(20, 2), expErrMatch: "", }, { binaryVersion: v(20, 2), binaryMinSupportedVersion: v(20, 1), - targetVersion: v(21, 1), - expErrMatch: "binary version.*less than target version", + targetClusterVersion: cv(21, 1), + expErrMatch: "binary version.*less than target cluster version", }, { binaryVersion: v(20, 2), binaryMinSupportedVersion: v(20, 1), - targetVersion: v(19, 2), - expErrMatch: "target version.*less than binary's min supported version", + targetClusterVersion: cv(19, 2), + expErrMatch: "target cluster version.*less than binary's min supported version", }, } @@ -82,7 +86,7 @@ func TestValidateTargetClusterVersion(t *testing.T) { migrationServer := s.MigrationServer().(*migrationServer) req := &serverpb.ValidateTargetClusterVersionRequest{ - Version: &test.targetVersion, + ClusterVersion: &test.targetClusterVersion, } _, err := migrationServer.ValidateTargetClusterVersion(context.Background(), req) if !testutils.IsError(err, test.expErrMatch) { diff --git a/pkg/server/server_sql.go b/pkg/server/server_sql.go index 962bc97d51b8..d8ed7906e785 100644 --- a/pkg/server/server_sql.go +++ b/pkg/server/server_sql.go @@ -649,8 +649,8 @@ func newSQLServer(ctx context.Context, cfg sqlServerArgs) (*sqlServer, error) { cfg.circularInternalExecutor, cfg.db, ) - execCfg.VersionUpgradeHook = func(ctx context.Context, targetV roachpb.Version) error { - return migrationMgr.MigrateTo(ctx, targetV) + execCfg.VersionUpgradeHook = func(ctx context.Context, from, to clusterversion.ClusterVersion) error { + return migrationMgr.Migrate(ctx, from, to) } } diff --git a/pkg/server/serverpb/BUILD.bazel b/pkg/server/serverpb/BUILD.bazel index 5b4e3351ba0a..f06b0ed0e583 100644 --- a/pkg/server/serverpb/BUILD.bazel +++ b/pkg/server/serverpb/BUILD.bazel @@ -18,6 +18,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/build", + "//pkg/clusterversion", "//pkg/config/zonepb", "//pkg/gossip", "//pkg/jobs/jobspb", diff --git a/pkg/server/serverpb/migration.pb.go b/pkg/server/serverpb/migration.pb.go index 4bcdaab18c07..76f178fb6d27 100644 --- a/pkg/server/serverpb/migration.pb.go +++ b/pkg/server/serverpb/migration.pb.go @@ -6,7 +6,7 @@ package serverpb import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" -import roachpb "github.com/cockroachdb/cockroach/pkg/roachpb" +import clusterversion "github.com/cockroachdb/cockroach/pkg/clusterversion" import ( context "context" @@ -29,14 +29,14 @@ const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package // ValidateTargetClusterVersion is used to verify that the target node is // running a binary that's able to support the specified cluster version. type ValidateTargetClusterVersionRequest struct { - Version *roachpb.Version `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` + ClusterVersion *clusterversion.ClusterVersion `protobuf:"bytes,1,opt,name=cluster_version,json=clusterVersion,proto3" json:"cluster_version,omitempty"` } func (m *ValidateTargetClusterVersionRequest) Reset() { *m = ValidateTargetClusterVersionRequest{} } func (m *ValidateTargetClusterVersionRequest) String() string { return proto.CompactTextString(m) } func (*ValidateTargetClusterVersionRequest) ProtoMessage() {} func (*ValidateTargetClusterVersionRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_migration_37957468907239c5, []int{0} + return fileDescriptor_migration_23f3ba74c87bf5d5, []int{0} } func (m *ValidateTargetClusterVersionRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -70,7 +70,7 @@ func (m *ValidateTargetClusterVersionResponse) Reset() { *m = ValidateTa func (m *ValidateTargetClusterVersionResponse) String() string { return proto.CompactTextString(m) } func (*ValidateTargetClusterVersionResponse) ProtoMessage() {} func (*ValidateTargetClusterVersionResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_migration_37957468907239c5, []int{1} + return fileDescriptor_migration_23f3ba74c87bf5d5, []int{1} } func (m *ValidateTargetClusterVersionResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -98,14 +98,14 @@ var xxx_messageInfo_ValidateTargetClusterVersionResponse proto.InternalMessageIn // BumpClusterVersionRequest is used to inform a given node of a cluster version // bump. type BumpClusterVersionRequest struct { - Version *roachpb.Version `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` + ClusterVersion *clusterversion.ClusterVersion `protobuf:"bytes,1,opt,name=cluster_version,json=clusterVersion,proto3" json:"cluster_version,omitempty"` } func (m *BumpClusterVersionRequest) Reset() { *m = BumpClusterVersionRequest{} } func (m *BumpClusterVersionRequest) String() string { return proto.CompactTextString(m) } func (*BumpClusterVersionRequest) ProtoMessage() {} func (*BumpClusterVersionRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_migration_37957468907239c5, []int{2} + return fileDescriptor_migration_23f3ba74c87bf5d5, []int{2} } func (m *BumpClusterVersionRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -138,7 +138,7 @@ func (m *BumpClusterVersionResponse) Reset() { *m = BumpClusterVersionRe func (m *BumpClusterVersionResponse) String() string { return proto.CompactTextString(m) } func (*BumpClusterVersionResponse) ProtoMessage() {} func (*BumpClusterVersionResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_migration_37957468907239c5, []int{3} + return fileDescriptor_migration_23f3ba74c87bf5d5, []int{3} } func (m *BumpClusterVersionResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -388,11 +388,11 @@ func (m *ValidateTargetClusterVersionRequest) MarshalTo(dAtA []byte) (int, error _ = i var l int _ = l - if m.Version != nil { + if m.ClusterVersion != nil { dAtA[i] = 0xa i++ - i = encodeVarintMigration(dAtA, i, uint64(m.Version.Size())) - n1, err := m.Version.MarshalTo(dAtA[i:]) + i = encodeVarintMigration(dAtA, i, uint64(m.ClusterVersion.Size())) + n1, err := m.ClusterVersion.MarshalTo(dAtA[i:]) if err != nil { return 0, err } @@ -434,11 +434,11 @@ func (m *BumpClusterVersionRequest) MarshalTo(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Version != nil { + if m.ClusterVersion != nil { dAtA[i] = 0xa i++ - i = encodeVarintMigration(dAtA, i, uint64(m.Version.Size())) - n2, err := m.Version.MarshalTo(dAtA[i:]) + i = encodeVarintMigration(dAtA, i, uint64(m.ClusterVersion.Size())) + n2, err := m.ClusterVersion.MarshalTo(dAtA[i:]) if err != nil { return 0, err } @@ -480,8 +480,8 @@ func (m *ValidateTargetClusterVersionRequest) Size() (n int) { } var l int _ = l - if m.Version != nil { - l = m.Version.Size() + if m.ClusterVersion != nil { + l = m.ClusterVersion.Size() n += 1 + l + sovMigration(uint64(l)) } return n @@ -502,8 +502,8 @@ func (m *BumpClusterVersionRequest) Size() (n int) { } var l int _ = l - if m.Version != nil { - l = m.Version.Size() + if m.ClusterVersion != nil { + l = m.ClusterVersion.Size() n += 1 + l + sovMigration(uint64(l)) } return n @@ -562,7 +562,7 @@ func (m *ValidateTargetClusterVersionRequest) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ClusterVersion", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -586,10 +586,10 @@ func (m *ValidateTargetClusterVersionRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Version == nil { - m.Version = &roachpb.Version{} + if m.ClusterVersion == nil { + m.ClusterVersion = &clusterversion.ClusterVersion{} } - if err := m.Version.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.ClusterVersion.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -695,7 +695,7 @@ func (m *BumpClusterVersionRequest) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ClusterVersion", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -719,10 +719,10 @@ func (m *BumpClusterVersionRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Version == nil { - m.Version = &roachpb.Version{} + if m.ClusterVersion == nil { + m.ClusterVersion = &clusterversion.ClusterVersion{} } - if err := m.Version.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.ClusterVersion.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -903,27 +903,27 @@ var ( ) func init() { - proto.RegisterFile("server/serverpb/migration.proto", fileDescriptor_migration_37957468907239c5) + proto.RegisterFile("server/serverpb/migration.proto", fileDescriptor_migration_23f3ba74c87bf5d5) } -var fileDescriptor_migration_37957468907239c5 = []byte{ - // 279 bytes of a gzipped FileDescriptorProto +var fileDescriptor_migration_23f3ba74c87bf5d5 = []byte{ + // 278 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2f, 0x4e, 0x2d, 0x2a, 0x4b, 0x2d, 0xd2, 0x87, 0x50, 0x05, 0x49, 0xfa, 0xb9, 0x99, 0xe9, 0x45, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x92, 0xc9, 0xf9, 0xc9, 0xd9, 0x45, 0xf9, 0x89, - 0xc9, 0x19, 0x7a, 0x10, 0x35, 0x7a, 0x30, 0xa5, 0x52, 0x62, 0x60, 0x61, 0x90, 0x9e, 0xd4, 0x92, - 0xc4, 0x94, 0xc4, 0x92, 0x44, 0x88, 0x16, 0xa5, 0x68, 0x2e, 0xe5, 0xb0, 0xc4, 0x9c, 0xcc, 0x94, - 0xc4, 0x92, 0xd4, 0x90, 0xc4, 0xa2, 0xf4, 0xd4, 0x12, 0xe7, 0x9c, 0xd2, 0xe2, 0x92, 0xd4, 0xa2, - 0xb0, 0xd4, 0xa2, 0xe2, 0xcc, 0xfc, 0xbc, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0x21, 0x13, - 0x2e, 0xf6, 0x32, 0x88, 0x88, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x94, 0x1e, 0xc2, 0x2e, - 0xa8, 0xd1, 0x7a, 0x30, 0x3d, 0x30, 0xa5, 0x4a, 0x6a, 0x5c, 0x2a, 0xf8, 0x0d, 0x2f, 0x2e, 0xc8, - 0xcf, 0x2b, 0x4e, 0x55, 0x0a, 0xe4, 0x92, 0x74, 0x2a, 0xcd, 0x2d, 0xa0, 0xa6, 0xd5, 0x32, 0x5c, - 0x52, 0xd8, 0x8c, 0x84, 0x58, 0x68, 0xb4, 0x95, 0x89, 0x8b, 0xd3, 0x17, 0x16, 0x78, 0x42, 0x0b, - 0x19, 0xb9, 0x64, 0xf0, 0xb9, 0x53, 0xc8, 0x4e, 0x0f, 0x67, 0xc0, 0xea, 0x11, 0x11, 0x7a, 0x52, - 0xf6, 0x64, 0xeb, 0x87, 0x06, 0x10, 0x83, 0x50, 0x33, 0x23, 0x97, 0x10, 0xa6, 0x87, 0x84, 0x4c, - 0xf0, 0x98, 0x8c, 0x33, 0x48, 0xa5, 0x4c, 0x49, 0xd4, 0x05, 0x73, 0x85, 0x93, 0xd6, 0x89, 0x87, - 0x72, 0x0c, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0x78, 0xe3, 0x91, 0x1c, 0xe3, 0x83, - 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, - 0x14, 0x07, 0xcc, 0xa0, 0x24, 0x36, 0x70, 0x02, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xf8, - 0x76, 0x3a, 0x9f, 0xb6, 0x02, 0x00, 0x00, + 0xc9, 0x19, 0x7a, 0x10, 0x35, 0x7a, 0x30, 0xa5, 0x52, 0x2a, 0xc9, 0x39, 0xa5, 0xc5, 0x25, 0x60, + 0x5e, 0x71, 0x66, 0x7e, 0x9e, 0x3e, 0x94, 0x1b, 0x0f, 0xe5, 0x43, 0x0c, 0x50, 0xaa, 0xe0, 0x52, + 0x0e, 0x4b, 0xcc, 0xc9, 0x4c, 0x49, 0x2c, 0x49, 0x0d, 0x49, 0x2c, 0x4a, 0x4f, 0x2d, 0x71, 0x86, + 0x28, 0x0b, 0x83, 0xa8, 0x0a, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x11, 0x0a, 0xe4, 0xe2, 0x47, + 0xd3, 0x2f, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0xa4, 0xa1, 0x87, 0x70, 0x01, 0xaa, 0x85, 0x7a, + 0x68, 0x26, 0xf1, 0x25, 0xa3, 0xf0, 0x95, 0xd4, 0xb8, 0x54, 0xf0, 0xdb, 0x5c, 0x5c, 0x90, 0x9f, + 0x57, 0x9c, 0xaa, 0x94, 0xc7, 0x25, 0xe9, 0x54, 0x9a, 0x5b, 0x40, 0x37, 0x77, 0xc9, 0x70, 0x49, + 0x61, 0xb3, 0x0f, 0xe2, 0x1a, 0xa3, 0xad, 0x4c, 0x5c, 0x9c, 0xbe, 0xb0, 0x48, 0x10, 0x5a, 0xc8, + 0xc8, 0x25, 0x83, 0xcf, 0x13, 0x42, 0x76, 0x7a, 0x38, 0x23, 0x48, 0x8f, 0x88, 0x70, 0x97, 0xb2, + 0x27, 0x5b, 0x3f, 0x34, 0xf4, 0x18, 0x84, 0x9a, 0x19, 0xb9, 0x84, 0x30, 0x3d, 0x24, 0x64, 0x82, + 0xc7, 0x64, 0x9c, 0xe1, 0x2d, 0x65, 0x4a, 0xa2, 0x2e, 0x98, 0x2b, 0x9c, 0xb4, 0x4e, 0x3c, 0x94, + 0x63, 0x38, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x1b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, + 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, + 0x38, 0x60, 0x06, 0x25, 0xb1, 0x81, 0x93, 0xa6, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x08, 0xa5, + 0xf0, 0xc3, 0xfe, 0x02, 0x00, 0x00, } diff --git a/pkg/server/serverpb/migration.proto b/pkg/server/serverpb/migration.proto index 590ed76a6a64..34ff08feb849 100644 --- a/pkg/server/serverpb/migration.proto +++ b/pkg/server/serverpb/migration.proto @@ -12,12 +12,12 @@ syntax = "proto3"; package cockroach.server.serverpb; option go_package = "serverpb"; -import "roachpb/metadata.proto"; +import "clusterversion/cluster_version.proto"; // ValidateTargetClusterVersion is used to verify that the target node is // running a binary that's able to support the specified cluster version. message ValidateTargetClusterVersionRequest { - roachpb.Version version = 1; + clusterversion.ClusterVersion cluster_version = 1; } // ValidateTargetClusterVersionResponse is the response to a @@ -28,7 +28,7 @@ message ValidateTargetClusterVersionResponse { // BumpClusterVersionRequest is used to inform a given node of a cluster version // bump. message BumpClusterVersionRequest { - roachpb.Version version = 1; + clusterversion.ClusterVersion cluster_version = 1; } // BumpClusterVersionResponse is the response to an BumpClusterVersionRequest. diff --git a/pkg/server/version_cluster_test.go b/pkg/server/version_cluster_test.go index 99fc0c44480f..f751e95773fe 100644 --- a/pkg/server/version_cluster_test.go +++ b/pkg/server/version_cluster_test.go @@ -445,7 +445,7 @@ func TestClusterVersionMixedVersionTooOld(t *testing.T) { return err } - if !testutils.IsError(err, fmt.Sprintf("binary version %s less than target version %s", v0s, v1s)) { + if !testutils.IsError(err, fmt.Sprintf("binary version %s less than target cluster version %s", v0s, v1s)) { t.Fatal(i, err) } return nil diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go index d5432f8a89a0..0e067069bcaa 100644 --- a/pkg/sql/exec_util.go +++ b/pkg/sql/exec_util.go @@ -24,6 +24,7 @@ import ( "github.com/cockroachdb/apd/v2" "github.com/cockroachdb/cockroach/pkg/base" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/config" "github.com/cockroachdb/cockroach/pkg/config/zonepb" "github.com/cockroachdb/cockroach/pkg/gossip" @@ -740,7 +741,7 @@ type ExecutorConfig struct { // VersionUpgradeHook is called after validating a `SET CLUSTER SETTING // version` but before executing it. It can carry out arbitrary migrations // that allow us to eventually remove legacy code. - VersionUpgradeHook func(ctx context.Context, to roachpb.Version) error + VersionUpgradeHook func(ctx context.Context, from, to clusterversion.ClusterVersion) error } // Organization returns the value of cluster.organization. diff --git a/pkg/sql/set_cluster_setting.go b/pkg/sql/set_cluster_setting.go index d2029d28a248..2811ce56e9d3 100644 --- a/pkg/sql/set_cluster_setting.go +++ b/pkg/sql/set_cluster_setting.go @@ -36,6 +36,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util/humanizeutil" "github.com/cockroachdb/cockroach/pkg/util/log" + "github.com/cockroachdb/cockroach/pkg/util/protoutil" "github.com/cockroachdb/cockroach/pkg/util/retry" "github.com/cockroachdb/errors" "github.com/cockroachdb/errors/hintdetail" @@ -51,7 +52,7 @@ type setClusterSettingNode struct { // versionUpgradeHook is called after validating a `SET CLUSTER SETTING // version` but before executing it. It can carry out arbitrary migrations // that allow us to eventually remove legacy code. - versionUpgradeHook func(ctx context.Context, to roachpb.Version) error + versionUpgradeHook func(ctx context.Context, from, to clusterversion.ClusterVersion) error } func checkPrivilegesForSetting(ctx context.Context, p *planner, name string, action string) error { @@ -244,12 +245,20 @@ func (n *setClusterSettingNode) startExec(params runParams) error { } if isSetVersion { + var from, to clusterversion.ClusterVersion + + fromVersionVal := []byte(string(*prev.(*tree.DString))) + if err := protoutil.Unmarshal(fromVersionVal, &from); err != nil { + return err + } + + targetVersionStr := string(*value.(*tree.DString)) + to.Version = roachpb.MustParseVersion(targetVersionStr) + // toSettingString already validated the input, and checked to // see that we are allowed to transition. Let's call into our // upgrade hook to run migrations, if any. - versionStr := string(*value.(*tree.DString)) - targetVersion := roachpb.MustParseVersion(versionStr) - if err := n.versionUpgradeHook(ctx, targetVersion); err != nil { + if err := n.versionUpgradeHook(ctx, from, to); err != nil { return err } }