Skip to content

Commit

Permalink
clusterversion: split ClusterVersion out of pkg/settings/cluster
Browse files Browse the repository at this point in the history
We split off ClusterVersion out of pkg/settings/cluster into a dedicated
pkg/clusterversion. This is to pave the way for cockroachdb#39182 where we
introduce long running version migration infrastructure.

Release note: None

Co-authored-by: Daniel Harrison <daniel.harrison@gmail.com>
Co-authored-by: irfan sharif <irfanmahmoudsharif@gmail.com>
  • Loading branch information
danhhz and irfansharif committed Feb 26, 2020
1 parent 869d96f commit 40e696f
Show file tree
Hide file tree
Showing 56 changed files with 246 additions and 207 deletions.
4 changes: 2 additions & 2 deletions pkg/ccl/gssapiccl/gssapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion pkg/ccl/importccl/import_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/cli/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package cluster
package clusterversion

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package cluster
package clusterversion

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/config/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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, ""}
}(),

Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/rpc/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/rpc/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/rpc/nodedialer/nodedialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -268,7 +269,7 @@ func newTestServer(
if useHeartbeat {
hb = &heartbeatService{
clock: clock,
serverVersion: cluster.BinaryServerVersion,
serverVersion: clusterversion.BinaryServerVersion,
}
rpc.RegisterHeartbeatServer(s, hb)
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/server/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 40e696f

Please sign in to comment.