From 40e696f2ddabf67913882f4687fe50ec36344317 Mon Sep 17 00:00:00 2001 From: Daniel Harrison Date: Thu, 30 Jan 2020 12:57:43 -0800 Subject: [PATCH] clusterversion: split ClusterVersion out of pkg/settings/cluster We split off ClusterVersion out of pkg/settings/cluster into a dedicated pkg/clusterversion. This is to pave the way for #39182 where we introduce long running version migration infrastructure. Release note: None Co-authored-by: Daniel Harrison Co-authored-by: irfan sharif --- pkg/ccl/gssapiccl/gssapi.go | 4 +- pkg/ccl/importccl/import_stmt.go | 3 +- pkg/cli/context.go | 4 +- .../cluster_version.pb.go | 40 +++++++++---------- .../cluster_version.proto | 2 +- .../clusterversion.go} | 2 +- .../cockroach_versions.go | 2 +- .../cockroach_versions_test.go | 2 +- .../keyed_versions.go | 2 +- .../cluster => clusterversion}/testutils.go | 2 +- .../versionkey_string.go | 2 +- pkg/config/system_test.go | 12 +++--- pkg/rpc/context_test.go | 3 +- pkg/rpc/heartbeat.go | 3 +- pkg/rpc/nodedialer/nodedialer_test.go | 3 +- pkg/server/node.go | 11 ++--- pkg/server/node_test.go | 17 ++++---- pkg/server/server.go | 13 +++--- pkg/server/testserver.go | 4 +- pkg/server/updates_test.go | 3 +- pkg/server/version_cluster_test.go | 13 +++--- pkg/settings/cluster/settings.go | 37 ++++++++--------- pkg/sql/alter_table.go | 3 +- pkg/sql/alter_user.go | 5 ++- pkg/sql/backfill.go | 3 +- pkg/sql/create_index.go | 3 +- pkg/sql/create_table.go | 9 +++-- pkg/sql/descriptor.go | 3 +- pkg/sql/drop_index.go | 3 +- pkg/sql/pgwire/auth_methods.go | 12 +++--- pkg/sql/pgwire/hba_conf.go | 11 ++--- pkg/sql/plan.go | 3 +- pkg/sql/rowexec/backfiller.go | 3 +- pkg/sql/sqlbase/metadata.go | 7 ++-- pkg/sql/sqlbase/namespace.go | 3 +- pkg/sql/sqlbase/structured.go | 3 +- pkg/sql/tests/system_table_test.go | 6 +-- pkg/sqlmigrations/migrations.go | 25 ++++++------ pkg/storage/batcheval/cmd_add_sstable.go | 4 +- pkg/storage/batcheval/cmd_end_transaction.go | 3 +- pkg/storage/batcheval/cmd_recompute_stats.go | 3 +- pkg/storage/bulk/sst_batcher.go | 7 ++-- pkg/storage/client_split_test.go | 4 +- pkg/storage/client_test.go | 17 ++++---- pkg/storage/engine/mvcc.go | 4 +- .../replica_application_state_machine.go | 4 +- pkg/storage/replica_command.go | 9 +++-- pkg/storage/replica_proposal.go | 5 ++- pkg/storage/replica_test.go | 9 +++-- pkg/storage/replicate_queue.go | 3 +- pkg/storage/store.go | 9 +++-- pkg/storage/store_bootstrap.go | 4 +- pkg/storage/store_test.go | 15 +++---- pkg/storage/stores.go | 30 +++++++------- pkg/storage/stores_test.go | 28 ++++++------- .../localtestcluster/local_test_cluster.go | 9 +++-- 56 files changed, 246 insertions(+), 207 deletions(-) rename pkg/{settings/cluster => clusterversion}/cluster_version.pb.go (81%) rename pkg/{settings/cluster => clusterversion}/cluster_version.proto (96%) rename pkg/{settings/cluster/cluster_version.go => clusterversion/clusterversion.go} (97%) rename pkg/{settings/cluster => clusterversion}/cockroach_versions.go (99%) rename pkg/{settings/cluster => clusterversion}/cockroach_versions_test.go (96%) rename pkg/{settings/cluster => clusterversion}/keyed_versions.go (99%) rename pkg/{settings/cluster => clusterversion}/testutils.go (96%) rename pkg/{settings/cluster => clusterversion}/versionkey_string.go (98%) diff --git a/pkg/ccl/gssapiccl/gssapi.go b/pkg/ccl/gssapiccl/gssapi.go index c2c993e1da2a..8dd3bfe5fb5b 100644 --- a/pkg/ccl/gssapiccl/gssapi.go +++ b/pkg/ccl/gssapiccl/gssapi.go @@ -21,8 +21,8 @@ import ( "unsafe" "github.com/cockroachdb/cockroach/pkg/ccl/utilccl" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/security" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/pgwire" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/hba" @@ -190,5 +190,5 @@ func checkEntry(entry hba.Entry) error { } func init() { - pgwire.RegisterAuthMethod("gss", authGSS, cluster.Version19_1, hba.ConnHostSSL, checkEntry) + pgwire.RegisterAuthMethod("gss", authGSS, clusterversion.Version19_1, hba.ConnHostSSL, checkEntry) } diff --git a/pkg/ccl/importccl/import_stmt.go b/pkg/ccl/importccl/import_stmt.go index f6164af3da1f..ed8c75f599f8 100644 --- a/pkg/ccl/importccl/import_stmt.go +++ b/pkg/ccl/importccl/import_stmt.go @@ -17,6 +17,7 @@ import ( "strings" "github.com/cockroachdb/cockroach/pkg/ccl/backupccl" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" @@ -151,7 +152,7 @@ func importPlanHook( return nil, nil, nil, false, nil } - if !cluster.Version.IsActive(ctx, p.ExecCfg().Settings, cluster.VersionPartitionedBackup) { + if !cluster.Version.IsActive(ctx, p.ExecCfg().Settings, clusterversion.VersionPartitionedBackup) { return nil, nil, nil, false, errors.Errorf("IMPORT requires a cluster fully upgraded to version >= 19.2") } diff --git a/pkg/cli/context.go b/pkg/cli/context.go index 94dcacaca973..e89f62841d90 100644 --- a/pkg/cli/context.go +++ b/pkg/cli/context.go @@ -17,6 +17,7 @@ import ( "time" "github.com/cockroachdb/cockroach/pkg/base" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/config/zonepb" "github.com/cockroachdb/cockroach/pkg/server" "github.com/cockroachdb/cockroach/pkg/settings" @@ -33,7 +34,8 @@ import ( // parameters for CLI utilities (other than `cockroach start`, which // constructs a proper server.Config for the newly created server). var serverCfg = func() server.Config { - st := cluster.MakeClusterSettings(cluster.BinaryMinimumSupportedVersion, cluster.BinaryServerVersion) + st := cluster.MakeClusterSettings( + clusterversion.BinaryMinimumSupportedVersion, clusterversion.BinaryServerVersion) settings.SetCanonicalValuesContainer(&st.SV) s := server.MakeConfig(context.Background(), st) diff --git a/pkg/settings/cluster/cluster_version.pb.go b/pkg/clusterversion/cluster_version.pb.go similarity index 81% rename from pkg/settings/cluster/cluster_version.pb.go rename to pkg/clusterversion/cluster_version.pb.go index 1cdb2658d2fe..db5acb056b8c 100644 --- a/pkg/settings/cluster/cluster_version.pb.go +++ b/pkg/clusterversion/cluster_version.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: settings/cluster/cluster_version.proto +// source: clusterversion/cluster_version.proto -package cluster +package clusterversion import proto "github.com/gogo/protobuf/proto" import fmt "fmt" @@ -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_6bb8528e3c56dcd8, []int{0} + return fileDescriptor_cluster_version_3f03e67a33fb82fb, []int{0} } func (m *ClusterVersion) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -306,23 +306,23 @@ var ( ) func init() { - proto.RegisterFile("settings/cluster/cluster_version.proto", fileDescriptor_cluster_version_6bb8528e3c56dcd8) + proto.RegisterFile("clusterversion/cluster_version.proto", fileDescriptor_cluster_version_3f03e67a33fb82fb) } -var fileDescriptor_cluster_version_6bb8528e3c56dcd8 = []byte{ - // 216 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2b, 0x4e, 0x2d, 0x29, - 0xc9, 0xcc, 0x4b, 0x2f, 0xd6, 0x4f, 0xce, 0x29, 0x2d, 0x2e, 0x49, 0x2d, 0x82, 0xd1, 0xf1, 0x65, - 0xa9, 0x45, 0xc5, 0x99, 0xf9, 0x79, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x7c, 0xc9, 0xf9, - 0xc9, 0xd9, 0x45, 0xf9, 0x89, 0xc9, 0x19, 0x7a, 0x49, 0x89, 0xc5, 0xa9, 0x52, 0x62, 0x60, 0x76, - 0x41, 0x92, 0x7e, 0x6e, 0x6a, 0x49, 0x62, 0x4a, 0x62, 0x49, 0x22, 0x44, 0x9d, 0x94, 0x48, 0x7a, - 0x7e, 0x7a, 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x44, 0x95, 0x32, 0xb9, 0xf8, 0x9c, 0x21, 0xc6, - 0x86, 0x41, 0x4c, 0x15, 0xf2, 0xe6, 0xe2, 0x4b, 0x4c, 0x2e, 0xc9, 0x2c, 0x4b, 0x85, 0xd9, 0x23, - 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xa5, 0x87, 0xb0, 0x08, 0x6a, 0x85, 0x1e, 0x54, 0x8f, - 0x13, 0xc7, 0x89, 0x7b, 0xf2, 0x0c, 0x17, 0xee, 0xc9, 0x33, 0x06, 0xf1, 0x42, 0xf4, 0x42, 0x25, - 0xac, 0x58, 0x66, 0x2c, 0x90, 0x67, 0xf0, 0x62, 0xe1, 0x60, 0x14, 0x60, 0x72, 0xd2, 0x3c, 0xf1, - 0x50, 0x8e, 0xe1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x6f, 0x3c, 0x92, 0x63, 0x7c, - 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, - 0x88, 0x62, 0x87, 0xfa, 0x30, 0x89, 0x0d, 0xec, 0x38, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x45, 0xdc, 0x17, 0x61, 0x04, 0x01, 0x00, 0x00, +var fileDescriptor_cluster_version_3f03e67a33fb82fb = []byte{ + // 210 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, 0x99, 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, 0x2c, 0x33, 0x16, 0xc8, 0x33, + 0x78, 0xb1, 0x70, 0x30, 0x0a, 0x30, 0x39, 0x19, 0x9c, 0x78, 0x28, 0xc7, 0x70, 0xe2, 0x91, 0x1c, + 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x37, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, + 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xf1, 0xa1, 0x7a, 0x38, 0x89, + 0x0d, 0xec, 0x46, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc3, 0x5f, 0x63, 0x79, 0x09, 0x01, + 0x00, 0x00, } diff --git a/pkg/settings/cluster/cluster_version.proto b/pkg/clusterversion/cluster_version.proto similarity index 96% rename from pkg/settings/cluster/cluster_version.proto rename to pkg/clusterversion/cluster_version.proto index 9353a01cd8aa..d238be0aff4e 100644 --- a/pkg/settings/cluster/cluster_version.proto +++ b/pkg/clusterversion/cluster_version.proto @@ -10,7 +10,7 @@ syntax = "proto3"; package cockroach.base; -option go_package = "cluster"; +option go_package = "clusterversion"; import "roachpb/metadata.proto"; import "gogoproto/gogo.proto"; diff --git a/pkg/settings/cluster/cluster_version.go b/pkg/clusterversion/clusterversion.go similarity index 97% rename from pkg/settings/cluster/cluster_version.go rename to pkg/clusterversion/clusterversion.go index a726f42f9709..31836a0c39ca 100644 --- a/pkg/settings/cluster/cluster_version.go +++ b/pkg/clusterversion/clusterversion.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package cluster +package clusterversion import "github.com/cockroachdb/cockroach/pkg/roachpb" diff --git a/pkg/settings/cluster/cockroach_versions.go b/pkg/clusterversion/cockroach_versions.go similarity index 99% rename from pkg/settings/cluster/cockroach_versions.go rename to pkg/clusterversion/cockroach_versions.go index aa545ca521cf..e803c9f6915b 100644 --- a/pkg/settings/cluster/cockroach_versions.go +++ b/pkg/clusterversion/cockroach_versions.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package cluster +package clusterversion import "github.com/cockroachdb/cockroach/pkg/roachpb" diff --git a/pkg/settings/cluster/cockroach_versions_test.go b/pkg/clusterversion/cockroach_versions_test.go similarity index 96% rename from pkg/settings/cluster/cockroach_versions_test.go rename to pkg/clusterversion/cockroach_versions_test.go index 3aa7c6fd0882..9ec4409cb53f 100644 --- a/pkg/settings/cluster/cockroach_versions_test.go +++ b/pkg/clusterversion/cockroach_versions_test.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package cluster +package clusterversion import ( "testing" diff --git a/pkg/settings/cluster/keyed_versions.go b/pkg/clusterversion/keyed_versions.go similarity index 99% rename from pkg/settings/cluster/keyed_versions.go rename to pkg/clusterversion/keyed_versions.go index 586844f8353b..c037db9dfeae 100644 --- a/pkg/settings/cluster/keyed_versions.go +++ b/pkg/clusterversion/keyed_versions.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package cluster +package clusterversion import ( "context" diff --git a/pkg/settings/cluster/testutils.go b/pkg/clusterversion/testutils.go similarity index 96% rename from pkg/settings/cluster/testutils.go rename to pkg/clusterversion/testutils.go index a9b248de1e17..e493c4502503 100644 --- a/pkg/settings/cluster/testutils.go +++ b/pkg/clusterversion/testutils.go @@ -8,7 +8,7 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package cluster +package clusterversion // TestingClusterVersion is a ClusterVersion that tests can use when they don't // want to go through a Settings object. diff --git a/pkg/settings/cluster/versionkey_string.go b/pkg/clusterversion/versionkey_string.go similarity index 98% rename from pkg/settings/cluster/versionkey_string.go rename to pkg/clusterversion/versionkey_string.go index d9d32871258d..a848ff664649 100644 --- a/pkg/settings/cluster/versionkey_string.go +++ b/pkg/clusterversion/versionkey_string.go @@ -1,6 +1,6 @@ // Code generated by "stringer -type=VersionKey"; DO NOT EDIT. -package cluster +package clusterversion import "strconv" diff --git a/pkg/config/system_test.go b/pkg/config/system_test.go index 2ce89bbc3ef2..2b289fdef9a6 100644 --- a/pkg/config/system_test.go +++ b/pkg/config/system_test.go @@ -14,11 +14,11 @@ import ( "sort" "testing" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/config" "github.com/cockroachdb/cockroach/pkg/config/zonepb" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/util/encoding" @@ -165,7 +165,7 @@ func TestGetLargestID(t *testing.T) { ms := sqlbase.MakeMetadataSchema(zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef()) descIDs := ms.DescriptorIDs() maxDescID := descIDs[len(descIDs)-1] - kvs, _ /* splits */ := ms.GetInitialValues(cluster.TestingClusterVersion) + kvs, _ /* splits */ := ms.GetInitialValues(clusterversion.TestingClusterVersion) return testCase{kvs, uint32(maxDescID), 0, ""} }(), @@ -258,7 +258,7 @@ func TestComputeSplitKeySystemRanges(t *testing.T) { } cfg := config.NewSystemConfig(zonepb.DefaultZoneConfigRef()) - kvs, _ /* splits */ := sqlbase.MakeMetadataSchema(cfg.DefaultZoneConfig, zonepb.DefaultSystemZoneConfigRef()).GetInitialValues(cluster.TestingClusterVersion) + kvs, _ /* splits */ := sqlbase.MakeMetadataSchema(cfg.DefaultZoneConfig, zonepb.DefaultSystemZoneConfigRef()).GetInitialValues(clusterversion.TestingClusterVersion) cfg.SystemConfigEntries = config.SystemConfigEntries{ Values: kvs, } @@ -290,9 +290,9 @@ func TestComputeSplitKeyTableIDs(t *testing.T) { schema := sqlbase.MakeMetadataSchema(zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef()) // Real system tables only. - baseSql, _ /* splits */ := schema.GetInitialValues(cluster.TestingClusterVersion) + baseSql, _ /* splits */ := schema.GetInitialValues(clusterversion.TestingClusterVersion) // Real system tables plus some user stuff. - kvs, _ /* splits */ := schema.GetInitialValues(cluster.TestingClusterVersion) + kvs, _ /* splits */ := schema.GetInitialValues(clusterversion.TestingClusterVersion) userSQL := append(kvs, descriptor(start), descriptor(start+1), descriptor(start+5)) // Real system tables and partitioned user tables. var subzoneSQL = make([]roachpb.KeyValue, len(userSQL)) @@ -434,7 +434,7 @@ func TestGetZoneConfigForKey(t *testing.T) { }() cfg := config.NewSystemConfig(zonepb.DefaultZoneConfigRef()) - kvs, _ /* splits */ := sqlbase.MakeMetadataSchema(cfg.DefaultZoneConfig, zonepb.DefaultSystemZoneConfigRef()).GetInitialValues(cluster.TestingClusterVersion) + kvs, _ /* splits */ := sqlbase.MakeMetadataSchema(cfg.DefaultZoneConfig, zonepb.DefaultSystemZoneConfigRef()).GetInitialValues(clusterversion.TestingClusterVersion) cfg.SystemConfigEntries = config.SystemConfigEntries{ Values: kvs, } diff --git a/pkg/rpc/context_test.go b/pkg/rpc/context_test.go index 0b799f661fd3..1307b24b47fb 100644 --- a/pkg/rpc/context_test.go +++ b/pkg/rpc/context_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/testutils" @@ -1403,7 +1404,7 @@ func TestVersionCheckBidirectional(t *testing.T) { defer leaktest.AfterTest(t)() v1 := roachpb.Version{Major: 1} - v2 := cluster.BinaryServerVersion + v2 := clusterversion.BinaryServerVersion testData := []struct { name string diff --git a/pkg/rpc/heartbeat.go b/pkg/rpc/heartbeat.go index 7cd66487c105..772bc70e215c 100644 --- a/pkg/rpc/heartbeat.go +++ b/pkg/rpc/heartbeat.go @@ -16,6 +16,7 @@ import ( "time" "github.com/cockroachdb/cockroach/pkg/base" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/util/hlc" @@ -79,7 +80,7 @@ func checkClusterName(clusterName string, peerName string) error { func checkVersion(ctx context.Context, st *cluster.Settings, peerVersion roachpb.Version) error { activeVersion := cluster.Version.ActiveVersionOrEmpty(ctx, st) - if activeVersion == (cluster.ClusterVersion{}) { + if activeVersion == (clusterversion.ClusterVersion{}) { // Cluster version has not yet been determined. return nil } diff --git a/pkg/rpc/nodedialer/nodedialer_test.go b/pkg/rpc/nodedialer/nodedialer_test.go index c2ef8278b4a5..0c96f196f2c9 100644 --- a/pkg/rpc/nodedialer/nodedialer_test.go +++ b/pkg/rpc/nodedialer/nodedialer_test.go @@ -20,6 +20,7 @@ import ( "time" circuit "github.com/cockroachdb/circuitbreaker" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/rpc" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -268,7 +269,7 @@ func newTestServer( if useHeartbeat { hb = &heartbeatService{ clock: clock, - serverVersion: cluster.BinaryServerVersion, + serverVersion: clusterversion.BinaryServerVersion, } rpc.RegisterHeartbeatServer(s, hb) } diff --git a/pkg/server/node.go b/pkg/server/node.go index a6d2750ad6bb..d03476f2f78d 100644 --- a/pkg/server/node.go +++ b/pkg/server/node.go @@ -19,6 +19,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/build" + "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" @@ -203,7 +204,7 @@ func GetBootstrapSchema( func bootstrapCluster( ctx context.Context, engines []engine.Engine, - bootstrapVersion cluster.ClusterVersion, + bootstrapVersion clusterversion.ClusterVersion, defaultZoneConfig *zonepb.ZoneConfig, defaultSystemZoneConfig *zonepb.ZoneConfig, ) (uuid.UUID, error) { @@ -306,7 +307,7 @@ func (n *Node) AnnotateCtxWithSpan( func (n *Node) bootstrapCluster( ctx context.Context, engines []engine.Engine, - bootstrapVersion cluster.ClusterVersion, + bootstrapVersion clusterversion.ClusterVersion, defaultZoneConfig *zonepb.ZoneConfig, defaultSystemZoneConfig *zonepb.ZoneConfig, ) error { @@ -324,7 +325,7 @@ func (n *Node) bootstrapCluster( return nil } -func (n *Node) onClusterVersionChange(ctx context.Context, cv cluster.ClusterVersion) { +func (n *Node) onClusterVersionChange(ctx context.Context, cv clusterversion.ClusterVersion) { if err := n.stores.OnClusterVersionChange(ctx, cv); err != nil { log.Fatal(ctx, errors.Wrapf(err, "updating cluster version to %v", cv)) } @@ -342,7 +343,7 @@ func (n *Node) start( clusterName string, attrs roachpb.Attributes, locality roachpb.Locality, - cv cluster.ClusterVersion, + cv clusterversion.ClusterVersion, localityAddress []roachpb.LocalityAddress, nodeDescriptorCallback func(descriptor roachpb.NodeDescriptor), ) error { @@ -546,7 +547,7 @@ func (n *Node) addStore(store *storage.Store) { if err != nil { log.Fatal(context.TODO(), err) } - if cv == (cluster.ClusterVersion{}) { + if cv == (clusterversion.ClusterVersion{}) { // The store should have had a version written to it during the store // bootstrap process. log.Fatal(context.TODO(), "attempting to add a store without a version") diff --git a/pkg/server/node_test.go b/pkg/server/node_test.go index 5f37794bd856..cdaf137a7078 100644 --- a/pkg/server/node_test.go +++ b/pkg/server/node_test.go @@ -21,6 +21,7 @@ import ( "time" "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" @@ -209,7 +210,7 @@ func TestBootstrapCluster(t *testing.T) { e := engine.NewDefaultInMem() defer e.Close() if _, err := bootstrapCluster( - ctx, []engine.Engine{e}, cluster.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), + ctx, []engine.Engine{e}, clusterversion.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), ); err != nil { t.Fatal(err) } @@ -237,7 +238,7 @@ func TestBootstrapCluster(t *testing.T) { } // Add the initial keys for sql. - kvs, tableSplits := GetBootstrapSchema(zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef()).GetInitialValues(cluster.TestingClusterVersion) + kvs, tableSplits := GetBootstrapSchema(zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef()).GetInitialValues(clusterversion.TestingClusterVersion) for _, kv := range kvs { expectedKeys = append(expectedKeys, kv.Key) } @@ -264,7 +265,7 @@ func TestBootstrapNewStore(t *testing.T) { ctx := context.Background() e := engine.NewDefaultInMem() if _, err := bootstrapCluster( - ctx, []engine.Engine{e}, cluster.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), + ctx, []engine.Engine{e}, clusterversion.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), ); err != nil { t.Fatal(err) } @@ -319,7 +320,7 @@ func TestNodeJoin(t *testing.T) { engineStopper.AddCloser(e) if _, err := bootstrapCluster( - ctx, []engine.Engine{e}, cluster.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), + ctx, []engine.Engine{e}, clusterversion.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), ); err != nil { t.Fatal(err) } @@ -390,7 +391,7 @@ func TestCorruptedClusterID(t *testing.T) { defer e.Close() if _, err := bootstrapCluster( - ctx, []engine.Engine{e}, cluster.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), + ctx, []engine.Engine{e}, clusterversion.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), ); err != nil { t.Fatal(err) } @@ -412,8 +413,8 @@ func TestCorruptedClusterID(t *testing.T) { defer stopper.Stop(ctx) bootstrappedEngines, newEngines, cv, err := inspectEngines( ctx, engines, - cluster.BinaryMinimumSupportedVersion, - cluster.BinaryServerVersion, + clusterversion.BinaryMinimumSupportedVersion, + clusterversion.BinaryServerVersion, node.clusterID) if err != nil { t.Fatal(err) @@ -736,7 +737,7 @@ func TestStartNodeWithLocality(t *testing.T) { e := engine.NewDefaultInMem() defer e.Close() if _, err := bootstrapCluster( - ctx, []engine.Engine{e}, cluster.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), + ctx, []engine.Engine{e}, clusterversion.TestingClusterVersion, zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef(), ); err != nil { t.Fatal(err) } diff --git a/pkg/server/server.go b/pkg/server/server.go index 3bf7ad3f362c..378d370de085 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -32,6 +32,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/blobs" "github.com/cockroachdb/cockroach/pkg/blobs/blobspb" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/gossip" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/jobs" @@ -925,7 +926,7 @@ func inspectEngines( ) ( bootstrappedEngines []engine.Engine, emptyEngines []engine.Engine, - _ cluster.ClusterVersion, + _ clusterversion.ClusterVersion, _ error, ) { for _, engine := range engines { @@ -934,14 +935,14 @@ func inspectEngines( emptyEngines = append(emptyEngines, engine) continue } else if err != nil { - return nil, nil, cluster.ClusterVersion{}, err + return nil, nil, clusterversion.ClusterVersion{}, err } clusterID := clusterIDContainer.Get() if storeIdent.ClusterID != uuid.Nil { if clusterID == uuid.Nil { clusterIDContainer.Set(ctx, storeIdent.ClusterID) } else if storeIdent.ClusterID != clusterID { - return nil, nil, cluster.ClusterVersion{}, + return nil, nil, clusterversion.ClusterVersion{}, errors.Errorf("conflicting store cluster IDs: %s, %s", storeIdent.ClusterID, clusterID) } } @@ -950,7 +951,7 @@ func inspectEngines( cv, err := storage.SynthesizeClusterVersionFromEngines(ctx, bootstrappedEngines, minVersion, serverVersion) if err != nil { - return nil, nil, cluster.ClusterVersion{}, err + return nil, nil, clusterversion.ClusterVersion{}, err } return bootstrappedEngines, emptyEngines, cv, nil } @@ -2017,7 +2018,7 @@ func (s *Server) startServeSQL( } func (s *Server) bootstrapVersion() roachpb.Version { - v := cluster.BinaryServerVersion + v := clusterversion.BinaryServerVersion if knobs := s.cfg.TestingKnobs.Server; knobs != nil { if ov := knobs.(*TestingKnobs).BootstrapVersionOverride; ov != (roachpb.Version{}) { v = ov @@ -2028,7 +2029,7 @@ func (s *Server) bootstrapVersion() roachpb.Version { func (s *Server) bootstrapCluster(ctx context.Context, bootstrapVersion roachpb.Version) error { if err := s.node.bootstrapCluster( - ctx, s.engines, cluster.ClusterVersion{Version: bootstrapVersion}, + ctx, s.engines, clusterversion.ClusterVersion{Version: bootstrapVersion}, &s.cfg.DefaultZoneConfig, &s.cfg.DefaultSystemZoneConfig, ); err != nil { return err diff --git a/pkg/server/testserver.go b/pkg/server/testserver.go index fcfd14c15c8b..c74787dcbd1c 100644 --- a/pkg/server/testserver.go +++ b/pkg/server/testserver.go @@ -23,6 +23,7 @@ import ( "github.com/cenkalti/backoff" circuit "github.com/cockroachdb/circuitbreaker" "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" @@ -104,7 +105,8 @@ func makeTestConfig(st *cluster.Settings) Config { func makeTestConfigFromParams(params base.TestServerArgs) Config { st := params.Settings if params.Settings == nil { - st = cluster.MakeClusterSettings(cluster.BinaryMinimumSupportedVersion, cluster.BinaryServerVersion) + st = cluster.MakeClusterSettings( + clusterversion.BinaryMinimumSupportedVersion, clusterversion.BinaryServerVersion) } st.ExternalIODir = params.ExternalIODir cfg := makeTestConfig(st) diff --git a/pkg/server/updates_test.go b/pkg/server/updates_test.go index 633250171ff7..8f80e4befed9 100644 --- a/pkg/server/updates_test.go +++ b/pkg/server/updates_test.go @@ -26,6 +26,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/build" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/config/zonepb" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" @@ -757,7 +758,7 @@ func TestReportUsage(t *testing.T) { "diagnostics.reporting.enabled": "true", "diagnostics.reporting.send_crash_reports": "false", "server.time_until_store_dead": "1m30s", - "version": cluster.BinaryServerVersion.String(), + "version": clusterversion.BinaryServerVersion.String(), "cluster.secret": "", } { if got, ok := r.last.AlteredSettings[key]; !ok { diff --git a/pkg/server/version_cluster_test.go b/pkg/server/version_cluster_test.go index b3e80366b551..ca94c957d203 100644 --- a/pkg/server/version_cluster_test.go +++ b/pkg/server/version_cluster_test.go @@ -20,6 +20,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" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -55,7 +56,7 @@ func (th *testClusterWithHelpers) getVersionFromSelect(i int) string { } th.Fatalf("%d: %s (%T)", i, err, err) } - var v cluster.ClusterVersion + var v clusterversion.ClusterVersion if err := protoutil.Unmarshal([]byte(version), &v); err != nil { th.Fatalf("%d: %s", i, err) } @@ -166,7 +167,7 @@ func prev(version roachpb.Version) roachpb.Version { func TestClusterVersionPersistedOnJoin(t *testing.T) { defer leaktest.AfterTest(t)() - var newVersion = cluster.BinaryServerVersion + var newVersion = clusterversion.BinaryServerVersion var oldVersion = prev(newVersion) // Starts 3 nodes that have cluster versions set to be oldVersion and @@ -205,7 +206,7 @@ func TestClusterVersionUpgrade(t *testing.T) { defer leaktest.AfterTest(t)() ctx := context.Background() - var newVersion = cluster.BinaryServerVersion + var newVersion = clusterversion.BinaryServerVersion var oldVersion = prev(newVersion) knobs := base.TestingKnobs{ @@ -346,7 +347,7 @@ func TestAllVersionsAgree(t *testing.T) { TestCluster: tcRaw, } - exp := cluster.BinaryServerVersion.String() + exp := clusterversion.BinaryServerVersion.String() // The node bootstrapping the cluster starts at BinaryServerVersion, the // others start at MinimumSupportedVersion and it takes them a gossip update @@ -371,8 +372,8 @@ func TestAllVersionsAgree(t *testing.T) { // equal the MinSupportedVersion to avoid rot in tests using this (as we retire // old versions). func v0v1() (roachpb.Version, roachpb.Version) { - v1 := cluster.BinaryMinimumSupportedVersion - v0 := cluster.BinaryMinimumSupportedVersion + v1 := clusterversion.BinaryMinimumSupportedVersion + v0 := clusterversion.BinaryMinimumSupportedVersion if v0.Minor > 0 { v0.Minor-- } else { diff --git a/pkg/settings/cluster/settings.go b/pkg/settings/cluster/settings.go index e6dc72727522..793f4bb428bd 100644 --- a/pkg/settings/cluster/settings.go +++ b/pkg/settings/cluster/settings.go @@ -14,6 +14,7 @@ import ( "context" "sync/atomic" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings" "github.com/cockroachdb/cockroach/pkg/util/envutil" @@ -57,7 +58,7 @@ type Settings struct { beforeClusterVersionChangeMu struct { syncutil.Mutex // Callback to be called when the cluster version is about to be updated. - cb func(ctx context.Context, newVersion ClusterVersion) + cb func(ctx context.Context, newVersion clusterversion.ClusterVersion) } } @@ -166,7 +167,7 @@ var preserveDowngradeVersion = func() *settings.StringSetting { // MakeTestingClusterSettings returns a Settings object that has had its version // initialized to BinaryServerVersion. func MakeTestingClusterSettings() *Settings { - return MakeTestingClusterSettingsWithVersion(BinaryServerVersion, BinaryServerVersion) + return MakeTestingClusterSettingsWithVersion(clusterversion.BinaryServerVersion, clusterversion.BinaryServerVersion) } // MakeTestingClusterSettingsWithVersion returns a Settings object that has had @@ -239,7 +240,7 @@ func (cv clusterVersionSetting) BinaryMinSupportedVersion(st *Settings) roachpb. func (cv clusterVersionSetting) Initialize( ctx context.Context, version roachpb.Version, st *Settings, ) error { - if ver := cv.ActiveVersionOrEmpty(ctx, st); ver != (ClusterVersion{}) { + if ver := cv.ActiveVersionOrEmpty(ctx, st); ver != (clusterversion.ClusterVersion{}) { // Allow initializing a second time as long as it's setting the version to // what it was already set. This is useful in tests that use // MakeTestingClusterSettings() which initializes the version, and the @@ -255,7 +256,7 @@ func (cv clusterVersionSetting) Initialize( } // Return the serialized form of the new version. - newV := ClusterVersion{Version: version} + newV := clusterversion.ClusterVersion{Version: version} encoded, err := protoutil.Marshal(&newV) if err != nil { return err @@ -268,9 +269,9 @@ func (cv clusterVersionSetting) Initialize( // cluster version the caller may assume is in effect. // // ActiveVersion fatals if the version has not been initialized. -func (cv *clusterVersionSetting) ActiveVersion(ctx context.Context, st *Settings) ClusterVersion { +func (cv *clusterVersionSetting) ActiveVersion(ctx context.Context, st *Settings) clusterversion.ClusterVersion { ver := cv.ActiveVersionOrEmpty(ctx, st) - if ver == (ClusterVersion{}) { + if ver == (clusterversion.ClusterVersion{}) { log.Fatalf(ctx, "version not initialized") } return ver @@ -280,12 +281,12 @@ func (cv *clusterVersionSetting) ActiveVersion(ctx context.Context, st *Settings // the active version was not initialized. func (cv *clusterVersionSetting) ActiveVersionOrEmpty( ctx context.Context, st *Settings, -) ClusterVersion { +) clusterversion.ClusterVersion { encoded := cv.GetInternal(&st.SV) if encoded == nil { - return ClusterVersion{} + return clusterversion.ClusterVersion{} } - var curVer ClusterVersion + var curVer clusterversion.ClusterVersion if err := protoutil.Unmarshal(encoded.([]byte), &curVer); err != nil { log.Fatal(ctx, err) } @@ -318,7 +319,7 @@ func (cv *clusterVersionSetting) ActiveVersionOrEmpty( // latest active version, node2 is aware that the sending node has, and it will // too, eventually. func (cv *clusterVersionSetting) IsActive( - ctx context.Context, st *Settings, versionKey VersionKey, + ctx context.Context, st *Settings, versionKey clusterversion.VersionKey, ) bool { return cv.ActiveVersion(ctx, st).IsActive(versionKey) } @@ -327,7 +328,7 @@ func (cv *clusterVersionSetting) IsActive( func (cv clusterVersionSetting) BeforeChange( ctx context.Context, encodedVal []byte, sv *settings.Values, ) { - var clusterVersion ClusterVersion + var clusterVersion clusterversion.ClusterVersion if err := protoutil.Unmarshal(encodedVal, &clusterVersion); err != nil { log.Fatalf(ctx, "failed to unmarshall version: %s", err) } @@ -347,7 +348,7 @@ func (cv clusterVersionSetting) BeforeChange( // // The callback can be set at most once. func (cv clusterVersionSetting) SetBeforeChange( - ctx context.Context, st *Settings, cb func(ctx context.Context, newVersion ClusterVersion), + ctx context.Context, st *Settings, cb func(ctx context.Context, newVersion clusterversion.ClusterVersion), ) { st.beforeClusterVersionChangeMu.Lock() defer st.beforeClusterVersionChangeMu.Unlock() @@ -359,7 +360,7 @@ func (cv clusterVersionSetting) SetBeforeChange( // Decode is part of the StateMachineSettingImpl interface. func (cv clusterVersionSetting) Decode(val []byte) (interface{}, error) { - var clusterVersion ClusterVersion + var clusterVersion clusterversion.ClusterVersion if err := protoutil.Unmarshal(val, &clusterVersion); err != nil { return "", err } @@ -372,7 +373,7 @@ func (cv clusterVersionSetting) DecodeToString(val []byte) (string, error) { if err != nil { return "", err } - return clusterVersion.(ClusterVersion).Version.String(), nil + return clusterVersion.(clusterversion.ClusterVersion).Version.String(), nil } // ValidateLogical is part of the StateMachineSettingImpl interface. @@ -387,7 +388,7 @@ func (cv clusterVersionSetting) ValidateLogical( return nil, err } - var oldV ClusterVersion + var oldV clusterversion.ClusterVersion if err := protoutil.Unmarshal(curRawProto, &oldV); err != nil { return nil, err } @@ -407,7 +408,7 @@ func (cv clusterVersionSetting) ValidateLogical( } // Return the serialized form of the new version. - newV := ClusterVersion{Version: newVersion} + newV := clusterversion.ClusterVersion{Version: newVersion} return protoutil.Marshal(&newV) } @@ -425,7 +426,7 @@ func (cv clusterVersionSetting) ValidateGossipUpdate( } }() - var ver ClusterVersion + var ver clusterversion.ClusterVersion if err := protoutil.Unmarshal(rawProto, &ver); err != nil { return err } @@ -454,5 +455,5 @@ func (cv clusterVersionSetting) validateSupportedVersionInner( // SettingsListDefault is part of the StateMachineSettingImpl interface. func (cv clusterVersionSetting) SettingsListDefault() string { - return BinaryServerVersion.String() + return clusterversion.BinaryServerVersion.String() } diff --git a/pkg/sql/alter_table.go b/pkg/sql/alter_table.go index 9ab1bb522dce..778c4d0c2a87 100644 --- a/pkg/sql/alter_table.go +++ b/pkg/sql/alter_table.go @@ -16,6 +16,7 @@ import ( gojson "encoding/json" "fmt" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -326,7 +327,7 @@ func (n *alterTableNode) startExec(params runParams) error { case *tree.AlterTableAlterPrimaryKey: // Make sure that all nodes in the cluster are able to perform primary key changes before proceeding. version := cluster.Version.ActiveVersionOrEmpty(params.ctx, params.p.ExecCfg().Settings) - if !version.IsActive(cluster.VersionPrimaryKeyChanges) { + if !version.IsActive(clusterversion.VersionPrimaryKeyChanges) { return pgerror.Newf(pgcode.FeatureNotSupported, "all nodes are not the correct version for primary key changes") } diff --git a/pkg/sql/alter_user.go b/pkg/sql/alter_user.go index a5f8e22291ef..aae515ae839e 100644 --- a/pkg/sql/alter_user.go +++ b/pkg/sql/alter_user.go @@ -13,6 +13,7 @@ package sql import ( "context" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/security" "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -67,10 +68,10 @@ func (n *alterUserSetPasswordNode) startExec(params runParams) error { // TODO(knz): Remove in 20.2. if normalizedUsername == security.RootUser && len(hashedPassword) > 0 && - !cluster.Version.IsActive(params.ctx, params.EvalContext().Settings, cluster.VersionRootPassword) { + !cluster.Version.IsActive(params.ctx, params.EvalContext().Settings, clusterversion.VersionRootPassword) { return pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, `setting a root password requires all nodes to be upgraded to %s`, - cluster.VersionByKey(cluster.VersionRootPassword), + clusterversion.VersionByKey(clusterversion.VersionRootPassword), ) } diff --git a/pkg/sql/backfill.go b/pkg/sql/backfill.go index ff7057b71621..ecf91b5d5f89 100644 --- a/pkg/sql/backfill.go +++ b/pkg/sql/backfill.go @@ -16,6 +16,7 @@ import ( "sort" "time" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" @@ -783,7 +784,7 @@ func (sc *SchemaChanger) distBackfill( targetSpans []roachpb.Span, ) error { inMemoryStatusEnabled := cluster.Version.IsActive( - ctx, sc.execCfg.Settings, cluster.VersionAtomicChangeReplicasTrigger) + ctx, sc.execCfg.Settings, clusterversion.VersionAtomicChangeReplicasTrigger) duration := checkpointInterval if sc.testingKnobs.WriteCheckpointInterval > 0 { duration = sc.testingKnobs.WriteCheckpointInterval diff --git a/pkg/sql/create_index.go b/pkg/sql/create_index.go index fe9da184de7f..b234d53b8a06 100644 --- a/pkg/sql/create_index.go +++ b/pkg/sql/create_index.go @@ -13,6 +13,7 @@ package sql import ( "context" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" @@ -296,7 +297,7 @@ func (n *createIndexNode) startExec(params runParams) error { // If all nodes in the cluster know how to handle secondary indexes with column families, // write the new version into the index descriptor. encodingVersion := sqlbase.BaseIndexFormatVersion - if cluster.Version.IsActive(params.ctx, params.p.EvalContext().Settings, cluster.VersionSecondaryIndexColumnFamilies) { + if cluster.Version.IsActive(params.ctx, params.p.EvalContext().Settings, clusterversion.VersionSecondaryIndexColumnFamilies) { encodingVersion = sqlbase.SecondaryIndexFamilyFormatVersion } indexDesc.Version = encodingVersion diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index d031e4bcd7c6..834f236d64d5 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -20,6 +20,7 @@ import ( "strconv" "strings" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/server/telemetry" @@ -1184,8 +1185,8 @@ func MakeTableDesc( // before the version has been initialized, leading to a panic. There are also // cases where this function is called in tests where st is nil. if st != nil { - if version := cluster.Version.ActiveVersionOrEmpty(ctx, st); version != (cluster.ClusterVersion{}) && - version.IsActive(cluster.VersionSecondaryIndexColumnFamilies) { + if version := cluster.Version.ActiveVersionOrEmpty(ctx, st); version != (clusterversion.ClusterVersion{}) && + version.IsActive(clusterversion.VersionSecondaryIndexColumnFamilies) { indexEncodingVersion = sqlbase.SecondaryIndexFamilyFormatVersion } } @@ -1460,8 +1461,8 @@ func MakeTableDesc( // If any nodes are not at version VersionPrimaryKeyColumnsOutOfFamilyZero, then return an error // if a primary key column is not in column family 0. if st != nil { - if version := cluster.Version.ActiveVersionOrEmpty(ctx, st); version != (cluster.ClusterVersion{}) && - !version.IsActive(cluster.VersionPrimaryKeyColumnsOutOfFamilyZero) { + if version := cluster.Version.ActiveVersionOrEmpty(ctx, st); version != (clusterversion.ClusterVersion{}) && + !version.IsActive(clusterversion.VersionPrimaryKeyColumnsOutOfFamilyZero) { var colsInFamZero util.FastIntSet for _, colID := range desc.Families[0].ColumnIDs { colsInFamZero.Add(int(colID)) diff --git a/pkg/sql/descriptor.go b/pkg/sql/descriptor.go index 7f4c069cc834..99662caa98ce 100644 --- a/pkg/sql/descriptor.go +++ b/pkg/sql/descriptor.go @@ -13,6 +13,7 @@ package sql import ( "context" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" @@ -77,7 +78,7 @@ func (p *planner) createDatabase( // TODO(solon): This conditional can be removed in 20.2. Every database // is created with a public schema for cluster version >= 20.1, so we can remove // the `shouldCreatePublicSchema` logic as well. - if !cluster.Version.IsActive(ctx, p.ExecCfg().Settings, cluster.VersionNamespaceTableWithSchemas) { + if !cluster.Version.IsActive(ctx, p.ExecCfg().Settings, clusterversion.VersionNamespaceTableWithSchemas) { shouldCreatePublicSchema = false } diff --git a/pkg/sql/drop_index.go b/pkg/sql/drop_index.go index ae624b850c59..ad80019f174c 100644 --- a/pkg/sql/drop_index.go +++ b/pkg/sql/drop_index.go @@ -15,6 +15,7 @@ import ( "fmt" "strings" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -301,7 +302,7 @@ func (p *planner) dropIndexByName( // If we aren't at the cluster version where we have removed explicit foreign key IDs // from the foreign key descriptors, fall back to the existing drop index logic. // That means we pretend that we can never find replacements for any indexes. - if !cluster.Version.IsActive(ctx, p.ExecCfg().Settings, cluster.VersionNoExplicitForeignKeyIndexIDs) { + if !cluster.Version.IsActive(ctx, p.ExecCfg().Settings, clusterversion.VersionNoExplicitForeignKeyIndexIDs) { indexHasReplacementCandidate = func(func(*sqlbase.IndexDescriptor) bool) bool { return false } diff --git a/pkg/sql/pgwire/auth_methods.go b/pkg/sql/pgwire/auth_methods.go index 773faf179c6d..70f9c92cb0d7 100644 --- a/pkg/sql/pgwire/auth_methods.go +++ b/pkg/sql/pgwire/auth_methods.go @@ -16,8 +16,8 @@ import ( "crypto/tls" "fmt" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/security" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/hba" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" @@ -40,26 +40,26 @@ func loadDefaultMethods() { // // Care should be taken by administrators to only accept this auth // method over secure connections, e.g. those encrypted using SSL. - RegisterAuthMethod("password", authPassword, cluster.Version19_1, hba.ConnAny, nil) + RegisterAuthMethod("password", authPassword, clusterversion.Version19_1, hba.ConnAny, nil) // The "cert" method requires a valid client certificate for the // user attempting to connect. // // This method is only usable over SSL connections. - RegisterAuthMethod("cert", authCert, cluster.Version19_1, hba.ConnHostSSL, nil) + RegisterAuthMethod("cert", authCert, clusterversion.Version19_1, hba.ConnHostSSL, nil) // The "cert-password" method requires either a valid client // certificate for the connecting user, or, if no cert is provided, // a cleartext password. - RegisterAuthMethod("cert-password", authCertPassword, cluster.Version19_1, hba.ConnAny, nil) + RegisterAuthMethod("cert-password", authCertPassword, clusterversion.Version19_1, hba.ConnAny, nil) // The "reject" method rejects any connection attempt that matches // the current rule. - RegisterAuthMethod("reject", authReject, cluster.VersionAuthLocalAndTrustRejectMethods, hba.ConnAny, nil) + RegisterAuthMethod("reject", authReject, clusterversion.VersionAuthLocalAndTrustRejectMethods, hba.ConnAny, nil) // The "trust" method accepts any connection attempt that matches // the current rule. - RegisterAuthMethod("trust", authTrust, cluster.VersionAuthLocalAndTrustRejectMethods, hba.ConnAny, nil) + RegisterAuthMethod("trust", authTrust, clusterversion.VersionAuthLocalAndTrustRejectMethods, hba.ConnAny, nil) } diff --git a/pkg/sql/pgwire/hba_conf.go b/pkg/sql/pgwire/hba_conf.go index 1a4891e092a1..f5f138621cd5 100644 --- a/pkg/sql/pgwire/hba_conf.go +++ b/pkg/sql/pgwire/hba_conf.go @@ -18,6 +18,7 @@ import ( "sort" "strings" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/security" "github.com/cockroachdb/cockroach/pkg/settings" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -144,10 +145,10 @@ func checkHBASyntaxBeforeUpdatingSetting(values *settings.Values, s string) erro case hba.ConnHostAny: case hba.ConnLocal: if st != nil && - !cluster.Version.IsActive(context.TODO(), st, cluster.VersionAuthLocalAndTrustRejectMethods) { + !cluster.Version.IsActive(context.TODO(), st, clusterversion.VersionAuthLocalAndTrustRejectMethods) { return pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, `authentication rule type 'local' requires all nodes to be upgraded to %s`, - cluster.VersionByKey(cluster.VersionAuthLocalAndTrustRejectMethods), + clusterversion.VersionByKey(clusterversion.VersionAuthLocalAndTrustRejectMethods), ) } default: @@ -194,7 +195,7 @@ func checkHBASyntaxBeforeUpdatingSetting(values *settings.Values, s string) erro return pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, `authentication method '%s' requires all nodes to be upgraded to %s`, entry.Method.Value, - cluster.VersionByKey(method.minReqVersion)) + clusterversion.VersionByKey(method.minReqVersion)) } // Run the per-method validation. if check := hbaCheckHBAEntries[entry.Method.Value]; check != nil { @@ -308,7 +309,7 @@ func (s *Server) GetAuthenticationConfiguration() *hba.Conf { func RegisterAuthMethod( method string, fn AuthMethod, - minReqVersion cluster.VersionKey, + minReqVersion clusterversion.VersionKey, validConnTypes hba.ConnType, checkEntry CheckHBAEntry, ) { @@ -336,7 +337,7 @@ var ( type authMethodEntry struct { methodInfo - minReqVersion cluster.VersionKey + minReqVersion clusterversion.VersionKey } type methodInfo struct { diff --git a/pkg/sql/plan.go b/pkg/sql/plan.go index 8540408b2a70..6e43e673c78e 100644 --- a/pkg/sql/plan.go +++ b/pkg/sql/plan.go @@ -13,6 +13,7 @@ package sql import ( "context" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -70,7 +71,7 @@ func (r *runParams) creationTimeForNewTableDescriptor() hlc.Timestamp { // upon reading use the MVCC timestamp to populate the values. var ts hlc.Timestamp if !cluster.Version.IsActive( - r.ctx, r.ExecCfg().Settings, cluster.VersionTableDescModificationTimeFromMVCC, + r.ctx, r.ExecCfg().Settings, clusterversion.VersionTableDescModificationTimeFromMVCC, ) { ts = r.p.txn.CommitTimestamp() } diff --git a/pkg/sql/rowexec/backfiller.go b/pkg/sql/rowexec/backfiller.go index 4aff7b8254d5..20e82fab199c 100644 --- a/pkg/sql/rowexec/backfiller.go +++ b/pkg/sql/rowexec/backfiller.go @@ -15,6 +15,7 @@ import ( "fmt" "github.com/cockroachdb/cockroach/pkg/internal/client" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" "github.com/cockroachdb/cockroach/pkg/roachpb" @@ -137,7 +138,7 @@ func (b *backfiller) doRun(ctx context.Context) *execinfrapb.ProducerMetadata { return &execinfrapb.ProducerMetadata{Err: err} } st := b.flowCtx.Cfg.Settings - if !cluster.Version.IsActive(ctx, st, cluster.VersionAtomicChangeReplicasTrigger) { + if !cluster.Version.IsActive(ctx, st, clusterversion.VersionAtomicChangeReplicasTrigger) { // There is a node of older version which could be the coordinator. // So we communicate the finished work by writing to the jobs row. err = WriteResumeSpan(ctx, diff --git a/pkg/sql/sqlbase/metadata.go b/pkg/sql/sqlbase/metadata.go index ceb39113a391..0165ea277d62 100644 --- a/pkg/sql/sqlbase/metadata.go +++ b/pkg/sql/sqlbase/metadata.go @@ -21,6 +21,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/protoutil" + "github.com/cockroachdb/cockroach/pkg/clusterversion" ) var _ DescriptorProto = &DatabaseDescriptor{} @@ -123,7 +124,7 @@ func (ms MetadataSchema) SystemDescriptorCount() int { // in the schema. Also returns a list of split points (a split for each SQL // table descriptor part of the initial values). Both returned sets are sorted. func (ms MetadataSchema) GetInitialValues( - bootstrapVersion cluster.ClusterVersion, + bootstrapVersion clusterversion.ClusterVersion, ) ([]roachpb.KeyValue, []roachpb.RKey) { var ret []roachpb.KeyValue var splits []roachpb.RKey @@ -146,7 +147,7 @@ func (ms MetadataSchema) GetInitialValues( // TODO(solon): This if/else can be removed in 20.2, as there will be no // need to support the deprecated namespace table. - if bootstrapVersion.IsActive(cluster.VersionNamespaceTableWithSchemas) { + if bootstrapVersion.IsActive(clusterversion.VersionNamespaceTableWithSchemas) { if parentID != keys.RootNamespaceID { ret = append(ret, roachpb.KeyValue{ Key: NewPublicTableKey(parentID, desc.GetName()).Key(), @@ -255,7 +256,7 @@ func LookupSystemTableDescriptorID( } if settings != nil && - !cluster.Version.IsActive(ctx, settings, cluster.VersionNamespaceTableWithSchemas) && + !cluster.Version.IsActive(ctx, settings, clusterversion.VersionNamespaceTableWithSchemas) && tableName == NamespaceTable.Name { return DeprecatedNamespaceTable.ID } diff --git a/pkg/sql/sqlbase/namespace.go b/pkg/sql/sqlbase/namespace.go index 19767504ac05..d7959cb01c46 100644 --- a/pkg/sql/sqlbase/namespace.go +++ b/pkg/sql/sqlbase/namespace.go @@ -13,6 +13,7 @@ package sqlbase import ( "context" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -118,7 +119,7 @@ func MakeObjectNameKey( ctx context.Context, settings *cluster.Settings, parentID ID, parentSchemaID ID, name string, ) DescriptorKey { // TODO(solon): This if condition can be removed in 20.2 - if !cluster.Version.IsActive(ctx, settings, cluster.VersionNamespaceTableWithSchemas) { + if !cluster.Version.IsActive(ctx, settings, clusterversion.VersionNamespaceTableWithSchemas) { return NewDeprecatedTableKey(parentID, name) } var key DescriptorKey diff --git a/pkg/sql/sqlbase/structured.go b/pkg/sql/sqlbase/structured.go index 62f55bf0e1dd..6ae9fee7911a 100644 --- a/pkg/sql/sqlbase/structured.go +++ b/pkg/sql/sqlbase/structured.go @@ -34,6 +34,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/protoutil" "github.com/cockroachdb/errors" + "github.com/cockroachdb/cockroach/pkg/clusterversion" ) // ID, ColumnID, FamilyID, and IndexID are all uint32, but are each given a @@ -1542,7 +1543,7 @@ func (desc *MutableTableDescriptor) MaybeIncrementVersion( // // TODO(ajwerner): remove this check in 20.1. var modTime hlc.Timestamp - if !cluster.Version.IsActive(ctx, settings, cluster.VersionTableDescModificationTimeFromMVCC) { + if !cluster.Version.IsActive(ctx, settings, clusterversion.VersionTableDescModificationTimeFromMVCC) { modTime = txn.CommitTimestamp() } desc.ModificationTime = modTime diff --git a/pkg/sql/tests/system_table_test.go b/pkg/sql/tests/system_table_test.go index 13b83cddeba2..c73be7ea9f5b 100644 --- a/pkg/sql/tests/system_table_test.go +++ b/pkg/sql/tests/system_table_test.go @@ -15,10 +15,10 @@ import ( "strings" "testing" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/config/zonepb" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/privilege" "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" @@ -33,7 +33,7 @@ func TestInitialKeys(t *testing.T) { const nonDescKeys = 10 ms := sqlbase.MakeMetadataSchema(zonepb.DefaultZoneConfigRef(), zonepb.DefaultSystemZoneConfigRef()) - kv, _ /* splits */ := ms.GetInitialValues(cluster.TestingClusterVersion) + kv, _ /* splits */ := ms.GetInitialValues(clusterversion.TestingClusterVersion) expected := nonDescKeys + keysPerDesc*ms.SystemDescriptorCount() if actual := len(kv); actual != expected { t.Fatalf("Wrong number of initial sql kv pairs: %d, wanted %d", actual, expected) @@ -52,7 +52,7 @@ func TestInitialKeys(t *testing.T) { t.Fatal(err) } ms.AddDescriptor(keys.SystemDatabaseID, &desc) - kv, _ /* splits */ = ms.GetInitialValues(cluster.TestingClusterVersion) + kv, _ /* splits */ = ms.GetInitialValues(clusterversion.TestingClusterVersion) expected = nonDescKeys + keysPerDesc*ms.SystemDescriptorCount() if actual := len(kv); actual != expected { t.Fatalf("Wrong number of initial sql kv pairs: %d, wanted %d", actual, expected) diff --git a/pkg/sqlmigrations/migrations.go b/pkg/sqlmigrations/migrations.go index 6972485e55a4..088e076071d8 100644 --- a/pkg/sqlmigrations/migrations.go +++ b/pkg/sqlmigrations/migrations.go @@ -17,6 +17,7 @@ import ( "time" "github.com/cockroachdb/cockroach/pkg/base" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/config/zonepb" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/keys" @@ -192,35 +193,35 @@ var backwardCompatibleMigrations = []migrationDescriptor{ name: "create system.comment table", workFn: createCommentTable, // This migration has been introduced some time before 19.2. - includedInBootstrap: cluster.VersionByKey(cluster.Version19_2), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.Version19_2), newDescriptorIDs: staticIDs(keys.CommentsTableID), }, { name: "create system.replication_constraint_stats table", workFn: createReplicationConstraintStatsTable, // This migration has been introduced some time before 19.2. - includedInBootstrap: cluster.VersionByKey(cluster.Version19_2), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.Version19_2), newDescriptorIDs: staticIDs(keys.ReplicationConstraintStatsTableID), }, { name: "create system.replication_critical_localities table", workFn: createReplicationCriticalLocalitiesTable, // This migration has been introduced some time before 19.2. - includedInBootstrap: cluster.VersionByKey(cluster.Version19_2), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.Version19_2), newDescriptorIDs: staticIDs(keys.ReplicationCriticalLocalitiesTableID), }, { name: "create system.reports_meta table", workFn: createReportsMetaTable, // This migration has been introduced some time before 19.2. - includedInBootstrap: cluster.VersionByKey(cluster.Version19_2), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.Version19_2), newDescriptorIDs: staticIDs(keys.ReportsMetaTableID), }, { name: "create system.replication_stats table", workFn: createReplicationStatsTable, // This migration has been introduced some time before 19.2. - includedInBootstrap: cluster.VersionByKey(cluster.Version19_2), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.Version19_2), newDescriptorIDs: staticIDs(keys.ReplicationStatsTableID), }, { @@ -237,7 +238,7 @@ var backwardCompatibleMigrations = []migrationDescriptor{ { // Introduced in v19.2. name: "change reports fields from timestamp to timestamptz", - includedInBootstrap: cluster.VersionByKey(cluster.Version19_2), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.Version19_2), workFn: func(ctx context.Context, r runner) error { // Note that these particular schema changes are idempotent. if _, err := r.sqlExecutor.ExecEx(ctx, "update-reports-meta-generated", nil, /* txn */ @@ -265,7 +266,7 @@ var backwardCompatibleMigrations = []migrationDescriptor{ // TODO(ajwerner): Bake this migration into v20.2. name: "create system.protected_ts_meta table", workFn: createProtectedTimestampsMetaTable, - includedInBootstrap: cluster.VersionByKey(cluster.VersionProtectedTimestamps), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.VersionProtectedTimestamps), newDescriptorIDs: staticIDs(keys.ProtectedTimestampsMetaTableID), }, { @@ -273,21 +274,21 @@ var backwardCompatibleMigrations = []migrationDescriptor{ // TODO(ajwerner): Bake this migration into v20.2. name: "create system.protected_ts_records table", workFn: createProtectedTimestampsRecordsTable, - includedInBootstrap: cluster.VersionByKey(cluster.VersionProtectedTimestamps), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.VersionProtectedTimestamps), newDescriptorIDs: staticIDs(keys.ProtectedTimestampsRecordsTableID), }, { // Introduced in v20.1. name: "create new system.namespace table", workFn: createNewSystemNamespaceDescriptor, - includedInBootstrap: cluster.VersionByKey(cluster.VersionNamespaceTableWithSchemas), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.VersionNamespaceTableWithSchemas), newDescriptorIDs: staticIDs(keys.NamespaceTableID), }, { // Introduced in v20.1. name: "migrate system.namespace_deprecated entries into system.namespace", workFn: migrateSystemNamespace, - includedInBootstrap: cluster.VersionByKey(cluster.VersionNamespaceTableWithSchemas), + includedInBootstrap: clusterversion.VersionByKey(clusterversion.VersionNamespaceTableWithSchemas), }, { // Introduced in v20.1., @@ -857,10 +858,10 @@ func populateVersionSetting(ctx context.Context, r runner) error { if v == (roachpb.Version{}) { // The cluster was bootstrapped at v1.0 (or even earlier), so just use // the MinSupportedVersion of the binary. - v = cluster.BinaryMinimumSupportedVersion + v = clusterversion.BinaryMinimumSupportedVersion } - b, err := protoutil.Marshal(&cluster.ClusterVersion{Version: v}) + b, err := protoutil.Marshal(&clusterversion.ClusterVersion{Version: v}) if err != nil { return errors.Wrap(err, "while marshaling version") } diff --git a/pkg/storage/batcheval/cmd_add_sstable.go b/pkg/storage/batcheval/cmd_add_sstable.go index 8a775045492d..51d81c92a746 100644 --- a/pkg/storage/batcheval/cmd_add_sstable.go +++ b/pkg/storage/batcheval/cmd_add_sstable.go @@ -13,9 +13,9 @@ package batcheval import ( "context" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/storage/batcheval/result" "github.com/cockroachdb/cockroach/pkg/storage/engine" "github.com/cockroachdb/cockroach/pkg/storage/engine/enginepb" @@ -173,7 +173,7 @@ func EvalAddSSTable( stats.Subtract(skippedKVStats) stats.ContainsEstimates = 0 } else { - _ = cluster.VersionContainsEstimatesCounter // see for info on ContainsEstimates migration + _ = clusterversion.VersionContainsEstimatesCounter // see for info on ContainsEstimates migration stats.ContainsEstimates++ } diff --git a/pkg/storage/batcheval/cmd_end_transaction.go b/pkg/storage/batcheval/cmd_end_transaction.go index 52e6cd369fea..5641080aa954 100644 --- a/pkg/storage/batcheval/cmd_end_transaction.go +++ b/pkg/storage/batcheval/cmd_end_transaction.go @@ -17,6 +17,7 @@ import ( "math" "sync/atomic" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -1032,7 +1033,7 @@ func splitTriggerHelper( } deltaPostSplitLeft := h.DeltaPostSplitLeft() - if !cluster.Version.IsActive(ctx, rec.ClusterSettings(), cluster.VersionContainsEstimatesCounter) { + if !cluster.Version.IsActive(ctx, rec.ClusterSettings(), clusterversion.VersionContainsEstimatesCounter) { deltaPostSplitLeft.ContainsEstimates = 0 } return deltaPostSplitLeft, pd, nil diff --git a/pkg/storage/batcheval/cmd_recompute_stats.go b/pkg/storage/batcheval/cmd_recompute_stats.go index 2cd75069d26e..9b649e681c49 100644 --- a/pkg/storage/batcheval/cmd_recompute_stats.go +++ b/pkg/storage/batcheval/cmd_recompute_stats.go @@ -13,6 +13,7 @@ package batcheval import ( "context" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -99,7 +100,7 @@ func RecomputeStats( // stats for timeseries ranges (which go cold and the approximate stats are // wildly overcounting) and this is paced by the consistency checker, but it // means some extra engine churn. - if !cluster.Version.IsActive(ctx, cArgs.EvalCtx.ClusterSettings(), cluster.VersionContainsEstimatesCounter) { + if !cluster.Version.IsActive(ctx, cArgs.EvalCtx.ClusterSettings(), clusterversion.VersionContainsEstimatesCounter) { // We are running with the older version of MVCCStats.ContainsEstimates // which was a boolean, so we should keep it in {0,1} and not reset it // to avoid racing with another command that sets it to true. diff --git a/pkg/storage/bulk/sst_batcher.go b/pkg/storage/bulk/sst_batcher.go index aad5964b554a..b98d69f579c7 100644 --- a/pkg/storage/bulk/sst_batcher.go +++ b/pkg/storage/bulk/sst_batcher.go @@ -15,6 +15,7 @@ import ( "context" "time" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/roachpb" @@ -180,7 +181,7 @@ func (b *SSTBatcher) Reset(ctx context.Context) error { // Create "Ingestion" SSTs in the newer RocksDBv2 format only if all nodes // in the cluster can support it. Until then, for backward compatibility, // create SSTs in the leveldb format ("backup" ones). - if cluster.Version.IsActive(ctx, b.settings, cluster.VersionStart20_1) { + if cluster.Version.IsActive(ctx, b.settings, clusterversion.VersionStart20_1) { b.sstWriter = engine.MakeIngestionSSTWriter(b.sstFile) } else { b.sstWriter = engine.MakeBackupSSTWriter(b.sstFile) @@ -480,7 +481,7 @@ func createSplitSSTable( ) (*sstSpan, *sstSpan, error) { sstFile := &engine.MemFile{} var w engine.SSTWriter - if cluster.Version.IsActive(ctx, settings, cluster.VersionStart20_1) { + if cluster.Version.IsActive(ctx, settings, clusterversion.VersionStart20_1) { w = engine.MakeIngestionSSTWriter(sstFile) } else { w = engine.MakeBackupSSTWriter(sstFile) @@ -514,7 +515,7 @@ func createSplitSSTable( disallowShadowing: disallowShadowing, } *sstFile = engine.MemFile{} - if cluster.Version.IsActive(ctx, settings, cluster.VersionStart20_1) { + if cluster.Version.IsActive(ctx, settings, clusterversion.VersionStart20_1) { w = engine.MakeIngestionSSTWriter(sstFile) } else { w = engine.MakeBackupSSTWriter(sstFile) diff --git a/pkg/storage/client_split_test.go b/pkg/storage/client_split_test.go index 395f00cc9bb5..eb91aea4aca1 100644 --- a/pkg/storage/client_split_test.go +++ b/pkg/storage/client_split_test.go @@ -24,6 +24,7 @@ import ( "time" "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" @@ -33,7 +34,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/rpc" "github.com/cockroachdb/cockroach/pkg/server" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" "github.com/cockroachdb/cockroach/pkg/storage" "github.com/cockroachdb/cockroach/pkg/storage/abortspan" @@ -1292,7 +1292,7 @@ func TestStoreRangeSystemSplits(t *testing.T) { return err } descTablePrefix := keys.MakeTablePrefix(keys.DescriptorTableID) - kvs, _ /* splits */ := schema.GetInitialValues(cluster.TestingClusterVersion) + kvs, _ /* splits */ := schema.GetInitialValues(clusterversion.TestingClusterVersion) for _, kv := range kvs { if !bytes.HasPrefix(kv.Key, descTablePrefix) { continue diff --git a/pkg/storage/client_test.go b/pkg/storage/client_test.go index e9fb57e387f5..dc9af6baaa65 100644 --- a/pkg/storage/client_test.go +++ b/pkg/storage/client_test.go @@ -32,6 +32,7 @@ import ( "github.com/cenkalti/backoff" circuit "github.com/cockroachdb/circuitbreaker" "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" @@ -142,7 +143,7 @@ func createTestStoreWithOpts( storeCfg.ScanMaxIdleTime = 1 * time.Second stores := storage.NewStores( ac, storeCfg.Clock, - cluster.BinaryMinimumSupportedVersion, cluster.BinaryServerVersion) + clusterversion.BinaryMinimumSupportedVersion, clusterversion.BinaryServerVersion) if err := storeCfg.Gossip.SetNodeDescriptor(nodeDesc); err != nil { t.Fatal(err) @@ -178,7 +179,7 @@ func createTestStoreWithOpts( if !opts.dontBootstrap { if err := storage.InitEngine( ctx, eng, roachpb.StoreIdent{NodeID: 1, StoreID: 1}, - cluster.ClusterVersion{Version: cluster.BinaryServerVersion}, + clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion}, ); err != nil { t.Fatal(err) } @@ -187,7 +188,7 @@ func createTestStoreWithOpts( if !opts.dontBootstrap { var kvs []roachpb.KeyValue var splits []roachpb.RKey - bootstrapVersion := cluster.ClusterVersion{Version: cluster.BinaryServerVersion} + bootstrapVersion := clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion} kvs, tableSplits := sqlbase.MakeMetadataSchema(storeCfg.DefaultZoneConfig, storeCfg.DefaultSystemZoneConfig).GetInitialValues(bootstrapVersion) if !opts.dontCreateSystemRanges { splits = config.StaticSplits() @@ -200,7 +201,7 @@ func createTestStoreWithOpts( ctx, eng, kvs, /* initialValues */ - cluster.BinaryServerVersion, + clusterversion.BinaryServerVersion, 1 /* numStores */, splits, storeCfg.Clock.PhysicalNow()) if err != nil { t.Fatal(err) @@ -862,7 +863,7 @@ func (m *multiTestContext) addStore(idx int) { NodeID: roachpb.NodeID(idx + 1), StoreID: roachpb.StoreID(idx + 1), }, - cluster.ClusterVersion{Version: cluster.BinaryServerVersion}, + clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion}, ); err != nil { m.t.Fatal(err) } @@ -870,7 +871,7 @@ func (m *multiTestContext) addStore(idx int) { if needBootstrap && idx == 0 { // Bootstrap the initial range on the first engine. var splits []roachpb.RKey - bootstrapVersion := cluster.ClusterVersion{Version: cluster.BinaryServerVersion} + bootstrapVersion := clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion} kvs, tableSplits := sqlbase.MakeMetadataSchema(cfg.DefaultZoneConfig, cfg.DefaultSystemZoneConfig).GetInitialValues(bootstrapVersion) if !m.startWithSingleRange { splits = config.StaticSplits() @@ -883,7 +884,7 @@ func (m *multiTestContext) addStore(idx int) { ctx, eng, kvs, /* initialValues */ - cluster.BinaryServerVersion, + clusterversion.BinaryServerVersion, len(m.engines), splits, cfg.Clock.PhysicalNow()) if err != nil { m.t.Fatal(err) @@ -895,7 +896,7 @@ func (m *multiTestContext) addStore(idx int) { } sender := storage.NewStores(ambient, clock, - cluster.BinaryMinimumSupportedVersion, cluster.BinaryServerVersion, + clusterversion.BinaryMinimumSupportedVersion, clusterversion.BinaryServerVersion, ) sender.AddStore(store) perReplicaServer := storage.MakeServer(&roachpb.NodeDescriptor{NodeID: nodeID}, sender) diff --git a/pkg/storage/engine/mvcc.go b/pkg/storage/engine/mvcc.go index 3beda21be4f2..abc96423aec6 100644 --- a/pkg/storage/engine/mvcc.go +++ b/pkg/storage/engine/mvcc.go @@ -22,7 +22,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/storage/engine/enginepb" "github.com/cockroachdb/cockroach/pkg/util/encoding" "github.com/cockroachdb/cockroach/pkg/util/hlc" @@ -219,7 +219,7 @@ func updateStatsOnMerge(key roachpb.Key, valSize, nowNanos int64) enginepb.MVCCS sys := isSysLocal(key) ms.AgeTo(nowNanos) - _ = cluster.VersionContainsEstimatesCounter // see for info on ContainsEstimates migration + _ = clusterversion.VersionContainsEstimatesCounter // see for info on ContainsEstimates migration ms.ContainsEstimates = 1 if sys { diff --git a/pkg/storage/replica_application_state_machine.go b/pkg/storage/replica_application_state_machine.go index b2f51965b1d3..f9b4dcc0900b 100644 --- a/pkg/storage/replica_application_state_machine.go +++ b/pkg/storage/replica_application_state_machine.go @@ -15,8 +15,8 @@ import ( "fmt" "time" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/roachpb" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/storage/apply" "github.com/cockroachdb/cockroach/pkg/storage/engine" "github.com/cockroachdb/cockroach/pkg/storage/engine/enginepb" @@ -757,7 +757,7 @@ func (b *replicaAppBatch) stageTrivialReplicatedEvalResult( // has used the old cluster version: it's when the incoming // ContainsEstimates is 1. If so, we need to assume that an old node is processing // the same commands (as `true + true = true`), so make sure that `1 + 1 = 1`. - _ = cluster.VersionContainsEstimatesCounter // see for info on ContainsEstimates migration + _ = clusterversion.VersionContainsEstimatesCounter // see for info on ContainsEstimates migration deltaStats := res.Delta.ToStats() if deltaStats.ContainsEstimates == 1 && b.state.Stats.ContainsEstimates == 1 { deltaStats.ContainsEstimates = 0 diff --git a/pkg/storage/replica_command.go b/pkg/storage/replica_command.go index 14cc322e9de5..3aeda4b4a9de 100644 --- a/pkg/storage/replica_command.go +++ b/pkg/storage/replica_command.go @@ -20,6 +20,7 @@ import ( "time" "github.com/cockroachdb/cockroach/pkg/base" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" @@ -954,7 +955,7 @@ func (r *Replica) ChangeReplicas( // We execute the change serially if we're not allowed to run atomic // replication changes or if that was explicitly disabled. st := r.ClusterSettings() - unroll := !cluster.Version.IsActive(ctx, st, cluster.VersionAtomicChangeReplicas) || + unroll := !cluster.Version.IsActive(ctx, st, clusterversion.VersionAtomicChangeReplicas) || !UseAtomicReplicationChanges.Get(&st.SV) if unroll { @@ -1299,7 +1300,7 @@ func (r *Replica) atomicReplicationChange( } } - canUseDemotion := cluster.Version.IsActive(ctx, r.store.ClusterSettings(), cluster.VersionChangeReplicasDemotion) + canUseDemotion := cluster.Version.IsActive(ctx, r.store.ClusterSettings(), clusterversion.VersionChangeReplicasDemotion) for _, target := range chgs.Removals() { typ := internalChangeTypeRemove if rDesc, ok := desc.GetReplicaDescriptor(target.StoreID); ok && rDesc.GetType() == roachpb.VOTER_FULL && canUseDemotion { @@ -1514,7 +1515,7 @@ func prepareChangeReplicasTrigger( var crt *roachpb.ChangeReplicasTrigger if !cluster.Version.IsActive( - ctx, store.ClusterSettings(), cluster.VersionAtomicChangeReplicasTrigger, + ctx, store.ClusterSettings(), clusterversion.VersionAtomicChangeReplicasTrigger, ) { var deprecatedChangeType roachpb.ReplicaChangeType var deprecatedRepDesc roachpb.ReplicaDescriptor @@ -2019,7 +2020,7 @@ func (s *Store) AdminRelocateRange( ctx context.Context, rangeDesc roachpb.RangeDescriptor, targets []roachpb.ReplicationTarget, ) error { useAtomic := cluster.Version.IsActive( - ctx, s.ClusterSettings(), cluster.VersionAtomicChangeReplicas) + ctx, s.ClusterSettings(), clusterversion.VersionAtomicChangeReplicas) if useAtomic { // AdminChangeReplicas will only allow atomic replication changes when // this magic flag is set because we changed the corresponding request diff --git a/pkg/storage/replica_proposal.go b/pkg/storage/replica_proposal.go index 7ee1d053b6cb..66df5c4e3236 100644 --- a/pkg/storage/replica_proposal.go +++ b/pkg/storage/replica_proposal.go @@ -21,6 +21,7 @@ import ( "unsafe" "github.com/cockroachdb/cockroach/pkg/base" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -762,8 +763,8 @@ func (r *Replica) evaluateProposal( res.Replicated.Timestamp = ba.Timestamp res.Replicated.Delta = ms.ToStatsDelta() - _ = cluster.VersionContainsEstimatesCounter // see for info on ContainsEstimates migration - if cluster.Version.IsActive(ctx, r.ClusterSettings(), cluster.VersionContainsEstimatesCounter) { + _ = clusterversion.VersionContainsEstimatesCounter // see for info on ContainsEstimates migration + if cluster.Version.IsActive(ctx, r.ClusterSettings(), clusterversion.VersionContainsEstimatesCounter) { // Encode that this command (and any that follow) uses regular arithmetic for ContainsEstimates // by making sure ContainsEstimates is > 1. // This will be interpreted during command application. diff --git a/pkg/storage/replica_test.go b/pkg/storage/replica_test.go index df89dd6a87c9..0e19a25b2c06 100644 --- a/pkg/storage/replica_test.go +++ b/pkg/storage/replica_test.go @@ -28,6 +28,7 @@ import ( "time" "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" @@ -216,7 +217,7 @@ func (tc *testContext) StartWithStoreConfigAndVersion( } ctx := context.Background() if tc.store == nil { - cv := cluster.ClusterVersion{Version: bootstrapVersion} + cv := clusterversion.ClusterVersion{Version: bootstrapVersion} cfg.Gossip = tc.gossip cfg.Transport = tc.transport cfg.StorePool = NewTestStorePool(cfg) @@ -12114,7 +12115,7 @@ func TestReplicateQueueProcessOne(t *testing.T) { func TestContainsEstimatesClampProposal(t *testing.T) { defer leaktest.AfterTest(t)() - _ = cluster.VersionContainsEstimatesCounter // see for details on the ContainsEstimates migration + _ = clusterversion.VersionContainsEstimatesCounter // see for details on the ContainsEstimates migration someRequestToProposal := func(tc *testContext, ctx context.Context) *ProposalData { cmdIDKey := storagebase.CmdIDKey("some-cmdid-key") @@ -12138,7 +12139,7 @@ func TestContainsEstimatesClampProposal(t *testing.T) { stopper := stop.NewStopper() defer stopper.Stop(ctx) cfg := TestStoreConfig(nil) - version := cluster.VersionByKey(cluster.VersionContainsEstimatesCounter - 1) + version := clusterversion.VersionByKey(clusterversion.VersionContainsEstimatesCounter - 1) cfg.Settings = cluster.MakeClusterSettings(version, version) var tc testContext tc.StartWithStoreConfigAndVersion(t, stopper, cfg, version) @@ -12175,7 +12176,7 @@ func TestContainsEstimatesClampProposal(t *testing.T) { func TestContainsEstimatesClampApplication(t *testing.T) { defer leaktest.AfterTest(t)() - _ = cluster.VersionContainsEstimatesCounter // see for details on the ContainsEstimates migration + _ = clusterversion.VersionContainsEstimatesCounter // see for details on the ContainsEstimates migration ctx := context.Background() stopper := stop.NewStopper() diff --git a/pkg/storage/replicate_queue.go b/pkg/storage/replicate_queue.go index 96faf97622c3..22e0c72dca3a 100644 --- a/pkg/storage/replicate_queue.go +++ b/pkg/storage/replicate_queue.go @@ -18,6 +18,7 @@ import ( "time" "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" @@ -446,7 +447,7 @@ func (rq *replicateQueue) addOrReplace( removeIdx = -1 } st := rq.store.cfg.Settings - if !cluster.Version.IsActive(ctx, st, cluster.VersionAtomicChangeReplicas) { + if !cluster.Version.IsActive(ctx, st, clusterversion.VersionAtomicChangeReplicas) { // If we can't swap yet, don't. removeIdx = -1 } diff --git a/pkg/storage/store.go b/pkg/storage/store.go index 18296b763c12..3f96f220c171 100644 --- a/pkg/storage/store.go +++ b/pkg/storage/store.go @@ -26,6 +26,7 @@ import ( "unsafe" "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" @@ -2526,20 +2527,20 @@ func (s *Store) ManuallyEnqueue( // GetClusterVersion reads the the cluster version from the store-local version // key. Returns an empty version if the key is not found. -func (s *Store) GetClusterVersion(ctx context.Context) (cluster.ClusterVersion, error) { +func (s *Store) GetClusterVersion(ctx context.Context) (clusterversion.ClusterVersion, error) { return ReadClusterVersion(ctx, s.engine) } // WriteClusterVersion writes the given cluster version to the store-local cluster version key. func WriteClusterVersion( - ctx context.Context, writer engine.ReadWriter, cv cluster.ClusterVersion, + ctx context.Context, writer engine.ReadWriter, cv clusterversion.ClusterVersion, ) error { return engine.MVCCPutProto(ctx, writer, nil, keys.StoreClusterVersionKey(), hlc.Timestamp{}, nil, &cv) } // ReadClusterVersion reads the the cluster version from the store-local version key. -func ReadClusterVersion(ctx context.Context, reader engine.Reader) (cluster.ClusterVersion, error) { - var cv cluster.ClusterVersion +func ReadClusterVersion(ctx context.Context, reader engine.Reader) (clusterversion.ClusterVersion, error) { + var cv clusterversion.ClusterVersion _, err := engine.MVCCGetProto(ctx, reader, keys.StoreClusterVersionKey(), hlc.Timestamp{}, &cv, engine.MVCCGetOptions{}) return cv, err diff --git a/pkg/storage/store_bootstrap.go b/pkg/storage/store_bootstrap.go index 6964027e3047..6961ed0d4f96 100644 --- a/pkg/storage/store_bootstrap.go +++ b/pkg/storage/store_bootstrap.go @@ -13,9 +13,9 @@ package storage import ( "context" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/storage/engine" "github.com/cockroachdb/cockroach/pkg/storage/engine/enginepb" "github.com/cockroachdb/cockroach/pkg/storage/rditer" @@ -32,7 +32,7 @@ import ( // should be completely empty. It returns an error if called on a // non-empty engine. func InitEngine( - ctx context.Context, eng engine.Engine, ident roachpb.StoreIdent, cv cluster.ClusterVersion, + ctx context.Context, eng engine.Engine, ident roachpb.StoreIdent, cv clusterversion.ClusterVersion, ) error { exIdent, err := ReadStoreIdent(ctx, eng) if err == nil { diff --git a/pkg/storage/store_test.go b/pkg/storage/store_test.go index 1d2f259279bc..26175febc174 100644 --- a/pkg/storage/store_test.go +++ b/pkg/storage/store_test.go @@ -24,6 +24,7 @@ import ( "time" "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" @@ -234,12 +235,12 @@ func createTestStoreWithoutStart( factory.setStore(store) if err := InitEngine( context.TODO(), eng, roachpb.StoreIdent{NodeID: 1, StoreID: 1}, - cluster.ClusterVersion{Version: cluster.BinaryServerVersion}, + clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion}, ); err != nil { t.Fatal(err) } var splits []roachpb.RKey - bootstrapVersion := cluster.ClusterVersion{Version: cluster.BinaryServerVersion} + bootstrapVersion := clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion} kvs, tableSplits := sqlbase.MakeMetadataSchema(cfg.DefaultZoneConfig, cfg.DefaultSystemZoneConfig).GetInitialValues(bootstrapVersion) if opts.createSystemRanges { splits = config.StaticSplits() @@ -250,7 +251,7 @@ func createTestStoreWithoutStart( } if err := WriteInitialClusterData( context.TODO(), eng, kvs, /* initialValues */ - cluster.BinaryServerVersion, + clusterversion.BinaryServerVersion, 1 /* numStores */, splits, cfg.Clock.PhysicalNow(), ); err != nil { t.Fatal(err) @@ -441,7 +442,7 @@ func TestStoreInitAndBootstrap(t *testing.T) { // Bootstrap with a fake ident. if err := InitEngine( ctx, eng, testIdent, - cluster.ClusterVersion{Version: cluster.BinaryServerVersion}, + clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion}, ); err != nil { t.Fatalf("error bootstrapping store: %+v", err) } @@ -456,7 +457,7 @@ func TestStoreInitAndBootstrap(t *testing.T) { // Bootstrap the system ranges. var splits []roachpb.RKey - bootstrapVersion := cluster.ClusterVersion{Version: cluster.BinaryServerVersion} + bootstrapVersion := clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion} kvs, tableSplits := sqlbase.MakeMetadataSchema(cfg.DefaultZoneConfig, cfg.DefaultSystemZoneConfig).GetInitialValues(bootstrapVersion) splits = config.StaticSplits() splits = append(splits, tableSplits...) @@ -465,7 +466,7 @@ func TestStoreInitAndBootstrap(t *testing.T) { }) if err := WriteInitialClusterData( - ctx, eng, kvs /* initialValues */, cluster.BinaryServerVersion, + ctx, eng, kvs /* initialValues */, clusterversion.BinaryServerVersion, 1 /* numStores */, splits, cfg.Clock.PhysicalNow(), ); err != nil { t.Errorf("failure to create first range: %+v", err) @@ -523,7 +524,7 @@ func TestBootstrapOfNonEmptyStore(t *testing.T) { // Bootstrap should fail on non-empty engine. switch err := errors.Cause(InitEngine( ctx, eng, testIdent, - cluster.ClusterVersion{Version: cluster.BinaryServerVersion}, + clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion}, )); err.(type) { case *NotBootstrappedError: default: diff --git a/pkg/storage/stores.go b/pkg/storage/stores.go index c184b476df94..4e15c6d922e2 100644 --- a/pkg/storage/stores.go +++ b/pkg/storage/stores.go @@ -15,11 +15,11 @@ import ( "fmt" "unsafe" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/gossip" "github.com/cockroachdb/cockroach/pkg/internal/client" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/storage/engine" "github.com/cockroachdb/cockroach/pkg/util/hlc" "github.com/cockroachdb/cockroach/pkg/util/log" @@ -273,11 +273,11 @@ func (ls *Stores) updateBootstrapInfoLocked(bi *gossip.BootstrapInfo) error { // engine, falling back to the zero value. func ReadVersionFromEngineOrZero( ctx context.Context, e engine.Engine, -) (cluster.ClusterVersion, error) { - var cv cluster.ClusterVersion +) (clusterversion.ClusterVersion, error) { + var cv clusterversion.ClusterVersion cv, err := ReadClusterVersion(ctx, e) if err != nil { - return cluster.ClusterVersion{}, err + return clusterversion.ClusterVersion{}, err } return cv, nil } @@ -285,7 +285,7 @@ func ReadVersionFromEngineOrZero( // WriteClusterVersionToEngines writes the given version to the given engines, // without any sanity checks. func WriteClusterVersionToEngines( - ctx context.Context, engines []engine.Engine, cv cluster.ClusterVersion, + ctx context.Context, engines []engine.Engine, cv clusterversion.ClusterVersion, ) error { for _, eng := range engines { if err := WriteClusterVersion(ctx, eng, cv); err != nil { @@ -308,7 +308,7 @@ func WriteClusterVersionToEngines( // returned if any engine has a higher version. func SynthesizeClusterVersionFromEngines( ctx context.Context, engines []engine.Engine, minSupportedVersion, serverVersion roachpb.Version, -) (cluster.ClusterVersion, error) { +) (clusterversion.ClusterVersion, error) { // Find the most recent bootstrap info. type originVersion struct { roachpb.Version @@ -327,10 +327,10 @@ func SynthesizeClusterVersionFromEngines( // constraints, which at the latest the second loop will achieve // (because then minStoreVersion don't change any more). for _, eng := range engines { - var cv cluster.ClusterVersion + var cv clusterversion.ClusterVersion cv, err := ReadVersionFromEngineOrZero(ctx, eng) if err != nil { - return cluster.ClusterVersion{}, err + return clusterversion.ClusterVersion{}, err } if cv.Version == (roachpb.Version{}) { // This is needed when a node first joins an existing cluster, in @@ -342,7 +342,7 @@ func SynthesizeClusterVersionFromEngines( // Avoid running a binary with a store that is too new. For example, // restarting into 1.1 after having upgraded to 1.2 doesn't work. if serverVersion.Less(cv.Version) { - return cluster.ClusterVersion{}, errors.Errorf( + return clusterversion.ClusterVersion{}, errors.Errorf( "cockroach version v%s is incompatible with data in store %s; use version v%s or later", serverVersion, eng, cv.Version) } @@ -362,7 +362,7 @@ func SynthesizeClusterVersionFromEngines( minStoreVersion.Version = minSupportedVersion } - cv := cluster.ClusterVersion{ + cv := clusterversion.ClusterVersion{ Version: minStoreVersion.Version, } log.Eventf(ctx, "read ClusterVersion %+v", cv) @@ -379,7 +379,7 @@ func SynthesizeClusterVersionFromEngines( // may not yet have picked up the final versions we're actually planning // to use. if minStoreVersion.Version.Less(minSupportedVersion) { - return cluster.ClusterVersion{}, errors.Errorf("store %s, last used with cockroach version v%s, "+ + return clusterversion.ClusterVersion{}, errors.Errorf("store %s, last used with cockroach version v%s, "+ "is too old for running version v%s (which requires data from v%s or later)", minStoreVersion.origin, minStoreVersion.Version, serverVersion, minSupportedVersion) } @@ -398,7 +398,7 @@ func SynthesizeClusterVersionFromEngines( // Version. // // If there aren't any stores, returns the minimum supported version of the binary. -func (ls *Stores) SynthesizeClusterVersion(ctx context.Context) (cluster.ClusterVersion, error) { +func (ls *Stores) SynthesizeClusterVersion(ctx context.Context) (clusterversion.ClusterVersion, error) { var engines []engine.Engine ls.storeMap.Range(func(_ int64, v unsafe.Pointer) bool { engines = append(engines, (*Store)(v).engine) @@ -406,7 +406,7 @@ func (ls *Stores) SynthesizeClusterVersion(ctx context.Context) (cluster.Cluster }) cv, err := SynthesizeClusterVersionFromEngines(ctx, engines, ls.minSupportedVersion, ls.serverVersion) if err != nil { - return cluster.ClusterVersion{}, err + return clusterversion.ClusterVersion{}, err } return cv, nil } @@ -416,7 +416,7 @@ func (ls *Stores) SynthesizeClusterVersion(ctx context.Context) (cluster.Cluster // error encountered writing to the stores. // // WriteClusterVersion makes no attempt to validate the supplied version. -func (ls *Stores) WriteClusterVersion(ctx context.Context, cv cluster.ClusterVersion) error { +func (ls *Stores) WriteClusterVersion(ctx context.Context, cv clusterversion.ClusterVersion) error { // Update all stores. engines := ls.engines() ls.storeMap.Range(func(_ int64, v unsafe.Pointer) bool { @@ -438,7 +438,7 @@ func (ls *Stores) engines() []engine.Engine { // OnClusterVersionChange is invoked when the running node receives a notification // indicating that the cluster version has changed. It checks the currently persisted // version and updates if it is older than the provided update. -func (ls *Stores) OnClusterVersionChange(ctx context.Context, cv cluster.ClusterVersion) error { +func (ls *Stores) OnClusterVersionChange(ctx context.Context, cv clusterversion.ClusterVersion) error { // Grab a lock to make sure that there aren't two interleaved invocations of // this method that result in clobbering of an update. ls.mu.Lock() diff --git a/pkg/storage/stores_test.go b/pkg/storage/stores_test.go index 92a0e52b04ab..79e3881d70ee 100644 --- a/pkg/storage/stores_test.go +++ b/pkg/storage/stores_test.go @@ -17,9 +17,9 @@ import ( "testing" "time" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/gossip" "github.com/cockroachdb/cockroach/pkg/roachpb" - "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/storage/engine" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/util" @@ -31,7 +31,7 @@ import ( ) func newStores(ambientCtx log.AmbientContext, clock *hlc.Clock) *Stores { - return NewStores(ambientCtx, clock, cluster.BinaryMinimumSupportedVersion, cluster.BinaryServerVersion) + return NewStores(ambientCtx, clock, clusterversion.BinaryMinimumSupportedVersion, clusterversion.BinaryServerVersion) } func TestStoresAddStore(t *testing.T) { @@ -354,7 +354,7 @@ func TestStoresClusterVersionWriteSynthesize(t *testing.T) { if initialCV, err := ls0.SynthesizeClusterVersion(ctx); err != nil { t.Fatal(err) } else { - expCV := cluster.ClusterVersion{ + expCV := clusterversion.ClusterVersion{ Version: v1_0, } if !reflect.DeepEqual(initialCV, expCV) { @@ -378,7 +378,7 @@ func TestStoresClusterVersionWriteSynthesize(t *testing.T) { if initialCV, err := ls0.SynthesizeClusterVersion(ctx); err != nil { t.Fatal(err) } else { - expCV := cluster.ClusterVersion{ + expCV := clusterversion.ClusterVersion{ Version: v1_0, } if !reflect.DeepEqual(initialCV, expCV) { @@ -390,7 +390,7 @@ func TestStoresClusterVersionWriteSynthesize(t *testing.T) { // Bump a version to something more modern (but supported by this binary). // Note that there's still only one store. { - cv := cluster.ClusterVersion{ + cv := clusterversion.ClusterVersion{ Version: versionB, } if err := ls0.WriteClusterVersion(ctx, cv); err != nil { @@ -415,7 +415,7 @@ func TestStoresClusterVersionWriteSynthesize(t *testing.T) { ls01.AddStore(stores[0]) ls01.AddStore(stores[1]) - expCV := cluster.ClusterVersion{ + expCV := clusterversion.ClusterVersion{ Version: v1_0, } if cv, err := ls01.SynthesizeClusterVersion(ctx); err != nil { @@ -437,7 +437,7 @@ func TestStoresClusterVersionWriteSynthesize(t *testing.T) { } // Write an updated Version to both stores. - cv := cluster.ClusterVersion{ + cv := clusterversion.ClusterVersion{ Version: versionB, } if err := ls01.WriteClusterVersion(ctx, cv); err != nil { @@ -446,7 +446,7 @@ func TestStoresClusterVersionWriteSynthesize(t *testing.T) { } // Third node comes along, for now it's alone. It has a lower use version. - cv := cluster.ClusterVersion{ + cv := clusterversion.ClusterVersion{ Version: versionA, } @@ -465,7 +465,7 @@ func TestStoresClusterVersionWriteSynthesize(t *testing.T) { // Reading across all stores, we expect to pick up the lowest useVersion both // from the third store. - expCV := cluster.ClusterVersion{ + expCV := clusterversion.ClusterVersion{ Version: versionA, } if cv, err := ls012.SynthesizeClusterVersion(ctx); err != nil { @@ -486,9 +486,9 @@ func TestStoresClusterVersionIncompatible(t *testing.T) { vOneDashOne := roachpb.Version{Major: 1, Unstable: 1} vOne := roachpb.Version{Major: 1} - type testFn func(*cluster.ClusterVersion, *Stores) string + type testFn func(*clusterversion.ClusterVersion, *Stores) string for name, setter := range map[string]testFn{ - "StoreTooNew": func(cv *cluster.ClusterVersion, ls *Stores) string { + "StoreTooNew": func(cv *clusterversion.ClusterVersion, ls *Stores) string { // This is what the running node requires from its stores. ls.minSupportedVersion = vOne // This is what the node is running. @@ -497,7 +497,7 @@ func TestStoresClusterVersionIncompatible(t *testing.T) { cv.Version = roachpb.Version{Major: 9} return `cockroach version v1\.0-1 is incompatible with data in store =; use version v9\.0 or later` }, - "StoreTooOldVersion": func(cv *cluster.ClusterVersion, ls *Stores) string { + "StoreTooOldVersion": func(cv *clusterversion.ClusterVersion, ls *Stores) string { // This is what the running node requires from its stores. ls.minSupportedVersion = roachpb.Version{Major: 5} // This is what the node is running. @@ -506,7 +506,7 @@ func TestStoresClusterVersionIncompatible(t *testing.T) { cv.Version = roachpb.Version{Major: 4} return `store =, last used with cockroach version v4\.0, is too old for running version v9\.0 \(which requires data from v5\.0 or later\)` }, - "StoreTooOldMinVersion": func(cv *cluster.ClusterVersion, ls *Stores) string { + "StoreTooOldMinVersion": func(cv *clusterversion.ClusterVersion, ls *Stores) string { // Like the previous test case, but this time cv.MinimumVersion is the culprit. ls.minSupportedVersion = roachpb.Version{Major: 5} ls.serverVersion = roachpb.Version{Major: 9} @@ -519,7 +519,7 @@ func TestStoresClusterVersionIncompatible(t *testing.T) { defer stopper.Stop(ctx) ls.AddStore(stores[0]) // Configure versions and write. - var cv cluster.ClusterVersion + var cv clusterversion.ClusterVersion expErr := setter(&cv, ls) if err := ls.WriteClusterVersion(ctx, cv); err != nil { t.Fatal(err) diff --git a/pkg/testutils/localtestcluster/local_test_cluster.go b/pkg/testutils/localtestcluster/local_test_cluster.go index 8b5c91dc331d..df5411831157 100644 --- a/pkg/testutils/localtestcluster/local_test_cluster.go +++ b/pkg/testutils/localtestcluster/local_test_cluster.go @@ -17,6 +17,7 @@ import ( "time" "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" @@ -121,7 +122,7 @@ func (ltc *LocalTestCluster) Start(t testing.TB, baseCtx *base.Config, initFacto engine.DefaultStorageEngine, roachpb.Attributes{}, 50<<20) ltc.Stopper.AddCloser(ltc.Eng) - ltc.Stores = storage.NewStores(ambient, ltc.Clock, cluster.BinaryMinimumSupportedVersion, cluster.BinaryServerVersion) + ltc.Stores = storage.NewStores(ambient, ltc.Clock, clusterversion.BinaryMinimumSupportedVersion, clusterversion.BinaryServerVersion) factory := initFactory(cfg.Settings, nodeDesc, ambient.Tracer, ltc.Clock, ltc.Latency, ltc.Stores, ltc.Stopper, ltc.Gossip) if ltc.DBContext == nil { @@ -172,7 +173,7 @@ func (ltc *LocalTestCluster) Start(t testing.TB, baseCtx *base.Config, initFacto if err := storage.InitEngine( ctx, ltc.Eng, roachpb.StoreIdent{NodeID: nodeID, StoreID: 1}, - cluster.ClusterVersion{Version: cluster.BinaryServerVersion}, + clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion}, ); err != nil { t.Fatalf("unable to start local test cluster: %s", err) } @@ -183,7 +184,7 @@ func (ltc *LocalTestCluster) Start(t testing.TB, baseCtx *base.Config, initFacto if !ltc.DontCreateSystemRanges { schema := sqlbase.MakeMetadataSchema(cfg.DefaultZoneConfig, cfg.DefaultSystemZoneConfig) var tableSplits []roachpb.RKey - bootstrapVersion := cluster.ClusterVersion{Version: cluster.BinaryServerVersion} + bootstrapVersion := clusterversion.ClusterVersion{Version: clusterversion.BinaryServerVersion} initialValues, tableSplits = schema.GetInitialValues(bootstrapVersion) splits = append(config.StaticSplits(), tableSplits...) sort.Slice(splits, func(i, j int) bool { @@ -195,7 +196,7 @@ func (ltc *LocalTestCluster) Start(t testing.TB, baseCtx *base.Config, initFacto ctx, ltc.Eng, initialValues, - cluster.BinaryServerVersion, + clusterversion.BinaryServerVersion, 1, /* numStores */ splits, ltc.Clock.PhysicalNow(),