mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Replace all etcd versions with the centralized definitions
We have already defined all the constant etcd versions in the centralized place api/version/version.go. So we should replace all the versions with the centralized definitions.
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coreos/go-semver/semver"
|
||||
"go.etcd.io/etcd/api/v3/version"
|
||||
"go.etcd.io/etcd/server/v3/storage/backend"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
@@ -102,7 +103,7 @@ func (s migrationStep) unsafeExecute(lg *zap.Logger, tx backend.BatchTx) error {
|
||||
return err
|
||||
}
|
||||
// Storage version is available since v3.6, downgrading target v3.5 should clean this field.
|
||||
if !s.target.LessThan(V3_6) {
|
||||
if !s.target.LessThan(version.V3_6) {
|
||||
UnsafeSetStorageVersion(tx, &s.target)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -21,15 +21,12 @@ import (
|
||||
|
||||
"github.com/coreos/go-semver/semver"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.etcd.io/etcd/api/v3/version"
|
||||
"go.etcd.io/etcd/server/v3/storage/backend"
|
||||
betesting "go.etcd.io/etcd/server/v3/storage/backend/testing"
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
||||
var (
|
||||
V4_0 = semver.Version{Major: 4, Minor: 0}
|
||||
)
|
||||
|
||||
func TestNewPlan(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
@@ -42,25 +39,25 @@ func TestNewPlan(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Update v3.5 to v3.6 should work",
|
||||
current: V3_5,
|
||||
target: V3_6,
|
||||
current: version.V3_5,
|
||||
target: version.V3_6,
|
||||
},
|
||||
{
|
||||
name: "Downgrade v3.6 to v3.5 should fail as downgrades are not yet supported",
|
||||
current: V3_6,
|
||||
target: V3_5,
|
||||
current: version.V3_6,
|
||||
target: version.V3_5,
|
||||
},
|
||||
{
|
||||
name: "Upgrade v3.6 to v3.7 should fail as v3.7 is unknown",
|
||||
current: V3_6,
|
||||
target: V3_7,
|
||||
current: version.V3_6,
|
||||
target: version.V3_7,
|
||||
expectError: true,
|
||||
expectErrorMsg: `version "3.7.0" is not supported`,
|
||||
},
|
||||
{
|
||||
name: "Upgrade v3.6 to v4.0 as major version changes are unsupported",
|
||||
current: V3_6,
|
||||
target: V4_0,
|
||||
current: version.V3_6,
|
||||
target: version.V4_0,
|
||||
expectError: true,
|
||||
expectErrorMsg: "changing major storage version is not supported",
|
||||
},
|
||||
@@ -152,7 +149,7 @@ func TestMigrationStepExecute(t *testing.T) {
|
||||
{
|
||||
name: "Downgrade below to below v3.6 doesn't leave storage version as it was not supported then",
|
||||
currentVersion: semver.Version{Major: 3, Minor: 6},
|
||||
changes: schemaChanges[V3_6],
|
||||
changes: schemaChanges[version.V3_6],
|
||||
isUpgrade: false,
|
||||
expectVersion: nil,
|
||||
},
|
||||
|
||||
@@ -24,11 +24,6 @@ import (
|
||||
"go.etcd.io/etcd/server/v3/storage/backend"
|
||||
)
|
||||
|
||||
var (
|
||||
V3_5 = semver.Version{Major: 3, Minor: 5}
|
||||
V3_6 = semver.Version{Major: 3, Minor: 6}
|
||||
)
|
||||
|
||||
// Validate checks provided backend to confirm that schema used is supported.
|
||||
func Validate(lg *zap.Logger, tx backend.ReadTx) error {
|
||||
tx.Lock()
|
||||
@@ -108,7 +103,7 @@ func UnsafeDetectSchemaVersion(lg *zap.Logger, tx backend.ReadTx) (v semver.Vers
|
||||
if term == 0 {
|
||||
return v, fmt.Errorf("missing term information")
|
||||
}
|
||||
return V3_5, nil
|
||||
return version.V3_5, nil
|
||||
}
|
||||
|
||||
func schemaChangesForVersion(v semver.Version, isUpgrade bool) ([]schemaChange, error) {
|
||||
@@ -132,7 +127,7 @@ var (
|
||||
// schemaChanges list changes that were introduced in a particular version.
|
||||
// schema was introduced in v3.6 as so its changes were not tracked before.
|
||||
schemaChanges = map[semver.Version][]schemaChange{
|
||||
V3_6: {
|
||||
version.V3_6: {
|
||||
addNewField(Meta, MetaStorageVersionName, emptyStorageVersion),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.etcd.io/etcd/api/v3/etcdserverpb"
|
||||
"go.etcd.io/etcd/api/v3/membershippb"
|
||||
"go.etcd.io/etcd/api/v3/version"
|
||||
"go.etcd.io/etcd/raft/v3/raftpb"
|
||||
"go.etcd.io/etcd/server/v3/storage/backend"
|
||||
betesting "go.etcd.io/etcd/server/v3/storage/backend/testing"
|
||||
@@ -30,11 +31,6 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
V3_4 = semver.Version{Major: 3, Minor: 4}
|
||||
V3_7 = semver.Version{Major: 3, Minor: 7}
|
||||
)
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
@@ -48,23 +44,23 @@ func TestValidate(t *testing.T) {
|
||||
// For storage to be considered v3.5 it have both confstate and term key set.
|
||||
{
|
||||
name: `V3.4 schema is correct`,
|
||||
version: V3_4,
|
||||
version: version.V3_4,
|
||||
},
|
||||
{
|
||||
name: `V3.5 schema without confstate and term fields is correct`,
|
||||
version: V3_5,
|
||||
version: version.V3_5,
|
||||
overrideKeys: func(tx backend.BatchTx) {},
|
||||
},
|
||||
{
|
||||
name: `V3.5 schema without term field is correct`,
|
||||
version: V3_5,
|
||||
version: version.V3_5,
|
||||
overrideKeys: func(tx backend.BatchTx) {
|
||||
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: `V3.5 schema with all fields is correct`,
|
||||
version: V3_5,
|
||||
version: version.V3_5,
|
||||
overrideKeys: func(tx backend.BatchTx) {
|
||||
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||
UnsafeUpdateConsistentIndex(tx, 1, 1)
|
||||
@@ -72,11 +68,11 @@ func TestValidate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: `V3.6 schema is correct`,
|
||||
version: V3_6,
|
||||
version: version.V3_6,
|
||||
},
|
||||
{
|
||||
name: `V3.7 schema is unknown and should return error`,
|
||||
version: V3_7,
|
||||
version: version.V3_7,
|
||||
expectError: true,
|
||||
expectErrorMsg: `version "3.7.0" is not supported`,
|
||||
},
|
||||
@@ -116,68 +112,68 @@ func TestMigrate(t *testing.T) {
|
||||
// For storage to be considered v3.5 it have both confstate and term key set.
|
||||
{
|
||||
name: `Upgrading v3.5 to v3.6 should be rejected if confstate is not set`,
|
||||
version: V3_5,
|
||||
version: version.V3_5,
|
||||
overrideKeys: func(tx backend.BatchTx) {},
|
||||
targetVersion: V3_6,
|
||||
targetVersion: version.V3_6,
|
||||
expectVersion: nil,
|
||||
expectError: true,
|
||||
expectErrorMsg: `cannot detect storage schema version: missing confstate information`,
|
||||
},
|
||||
{
|
||||
name: `Upgrading v3.5 to v3.6 should be rejected if term is not set`,
|
||||
version: V3_5,
|
||||
version: version.V3_5,
|
||||
overrideKeys: func(tx backend.BatchTx) {
|
||||
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||
},
|
||||
targetVersion: V3_6,
|
||||
targetVersion: version.V3_6,
|
||||
expectVersion: nil,
|
||||
expectError: true,
|
||||
expectErrorMsg: `cannot detect storage schema version: missing term information`,
|
||||
},
|
||||
{
|
||||
name: `Upgrading v3.5 to v3.6 should succeed; all required fields are set`,
|
||||
version: V3_5,
|
||||
targetVersion: V3_6,
|
||||
expectVersion: &V3_6,
|
||||
version: version.V3_5,
|
||||
targetVersion: version.V3_6,
|
||||
expectVersion: &version.V3_6,
|
||||
},
|
||||
{
|
||||
name: `Migrate on same v3.5 version passes and doesn't set storage version'`,
|
||||
version: V3_5,
|
||||
targetVersion: V3_5,
|
||||
version: version.V3_5,
|
||||
targetVersion: version.V3_5,
|
||||
expectVersion: nil,
|
||||
},
|
||||
{
|
||||
name: `Migrate on same v3.6 version passes`,
|
||||
version: V3_6,
|
||||
targetVersion: V3_6,
|
||||
expectVersion: &V3_6,
|
||||
version: version.V3_6,
|
||||
targetVersion: version.V3_6,
|
||||
expectVersion: &version.V3_6,
|
||||
},
|
||||
{
|
||||
name: `Migrate on same v3.7 version passes`,
|
||||
version: V3_7,
|
||||
targetVersion: V3_7,
|
||||
expectVersion: &V3_7,
|
||||
version: version.V3_7,
|
||||
targetVersion: version.V3_7,
|
||||
expectVersion: &version.V3_7,
|
||||
},
|
||||
{
|
||||
name: "Upgrading 3.6 to v3.7 is not supported",
|
||||
version: V3_6,
|
||||
targetVersion: V3_7,
|
||||
expectVersion: &V3_6,
|
||||
version: version.V3_6,
|
||||
targetVersion: version.V3_7,
|
||||
expectVersion: &version.V3_6,
|
||||
expectError: true,
|
||||
expectErrorMsg: `cannot create migration plan: version "3.7.0" is not supported`,
|
||||
},
|
||||
{
|
||||
name: "Downgrading v3.7 to v3.6 is not supported",
|
||||
version: V3_7,
|
||||
targetVersion: V3_6,
|
||||
expectVersion: &V3_7,
|
||||
version: version.V3_7,
|
||||
targetVersion: version.V3_6,
|
||||
expectVersion: &version.V3_7,
|
||||
expectError: true,
|
||||
expectErrorMsg: `cannot create migration plan: version "3.7.0" is not supported`,
|
||||
},
|
||||
{
|
||||
name: "Downgrading v3.6 to v3.5 works as there are no v3.6 wal entries",
|
||||
version: V3_6,
|
||||
targetVersion: V3_5,
|
||||
version: version.V3_6,
|
||||
targetVersion: version.V3_5,
|
||||
walEntries: []etcdserverpb.InternalRaftRequest{
|
||||
{Range: &etcdserverpb.RangeRequest{Key: []byte("\x00"), RangeEnd: []byte("\xff")}},
|
||||
},
|
||||
@@ -185,19 +181,19 @@ func TestMigrate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Downgrading v3.6 to v3.5 fails if there are newer WAL entries",
|
||||
version: V3_6,
|
||||
targetVersion: V3_5,
|
||||
version: version.V3_6,
|
||||
targetVersion: version.V3_5,
|
||||
walEntries: []etcdserverpb.InternalRaftRequest{
|
||||
{ClusterVersionSet: &membershippb.ClusterVersionSetRequest{Ver: "3.6.0"}},
|
||||
},
|
||||
expectVersion: &V3_6,
|
||||
expectVersion: &version.V3_6,
|
||||
expectError: true,
|
||||
expectErrorMsg: "cannot downgrade storage, WAL contains newer entries",
|
||||
},
|
||||
{
|
||||
name: "Downgrading v3.5 to v3.4 is not supported as schema was introduced in v3.6",
|
||||
version: V3_5,
|
||||
targetVersion: V3_4,
|
||||
version: version.V3_5,
|
||||
targetVersion: version.V3_4,
|
||||
expectVersion: nil,
|
||||
expectError: true,
|
||||
expectErrorMsg: `cannot create migration plan: version "3.5.0" is not supported`,
|
||||
@@ -236,7 +232,7 @@ func TestMigrateIsReversible(t *testing.T) {
|
||||
state map[string]string
|
||||
}{
|
||||
{
|
||||
initialVersion: V3_5,
|
||||
initialVersion: version.V3_5,
|
||||
state: map[string]string{
|
||||
"confState": `{"auto_leave":false}`,
|
||||
"consistent_index": "\x00\x00\x00\x00\x00\x00\x00\x01",
|
||||
@@ -244,7 +240,7 @@ func TestMigrateIsReversible(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
initialVersion: V3_6,
|
||||
initialVersion: version.V3_6,
|
||||
state: map[string]string{
|
||||
"confState": `{"auto_leave":false}`,
|
||||
"consistent_index": "\x00\x00\x00\x00\x00\x00\x00\x01",
|
||||
@@ -297,7 +293,7 @@ func TestMigrateIsReversible(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func setupBackendData(t *testing.T, version semver.Version, overrideKeys func(tx backend.BatchTx)) string {
|
||||
func setupBackendData(t *testing.T, ver semver.Version, overrideKeys func(tx backend.BatchTx)) string {
|
||||
t.Helper()
|
||||
be, tmpPath := betesting.NewTmpBackend(t, time.Microsecond, 10)
|
||||
tx := be.BatchTx()
|
||||
@@ -309,19 +305,19 @@ func setupBackendData(t *testing.T, version semver.Version, overrideKeys func(tx
|
||||
if overrideKeys != nil {
|
||||
overrideKeys(tx)
|
||||
} else {
|
||||
switch version {
|
||||
case V3_4:
|
||||
case V3_5:
|
||||
switch ver {
|
||||
case version.V3_4:
|
||||
case version.V3_5:
|
||||
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||
UnsafeUpdateConsistentIndex(tx, 1, 1)
|
||||
case V3_6:
|
||||
case version.V3_6:
|
||||
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||
UnsafeUpdateConsistentIndex(tx, 1, 1)
|
||||
UnsafeSetStorageVersion(tx, &V3_6)
|
||||
case V3_7:
|
||||
UnsafeSetStorageVersion(tx, &version.V3_6)
|
||||
case version.V3_7:
|
||||
MustUnsafeSaveConfStateToBackend(zap.NewNop(), tx, &raftpb.ConfState{})
|
||||
UnsafeUpdateConsistentIndex(tx, 1, 1)
|
||||
UnsafeSetStorageVersion(tx, &V3_7)
|
||||
UnsafeSetStorageVersion(tx, &version.V3_7)
|
||||
tx.UnsafePut(Meta, []byte("future-key"), []byte(""))
|
||||
default:
|
||||
t.Fatalf("Unsupported storage version")
|
||||
|
||||
Reference in New Issue
Block a user