From bade01efec6bd14b557554060d1e9065227c537b Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Wed, 6 Oct 2021 15:10:30 +0200 Subject: [PATCH] server: Use server version to decide if to downgrade has finished --- server/etcdserver/version/monitor.go | 4 +++- server/etcdserver/version/monitor_test.go | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/server/etcdserver/version/monitor.go b/server/etcdserver/version/monitor.go index d3c0a1e4945c..be19e8e9e447 100644 --- a/server/etcdserver/version/monitor.go +++ b/server/etcdserver/version/monitor.go @@ -178,11 +178,12 @@ func (m *Monitor) membersMinimalVersion() *semver.Version { // It can be used to decide the whether the cluster finishes downgrading to target version. func (m *Monitor) versionsMatchTarget(targetVersion *semver.Version) bool { vers := m.s.GetMembersVersions() + targetVersion = &semver.Version{Major: targetVersion.Major, Minor: targetVersion.Minor} for mid, ver := range vers { if ver == nil { return false } - v, err := semver.NewVersion(ver.Cluster) + v, err := semver.NewVersion(ver.Server) if err != nil { m.lg.Warn( "failed to parse server version of remote member", @@ -192,6 +193,7 @@ func (m *Monitor) versionsMatchTarget(targetVersion *semver.Version) bool { ) return false } + v = &semver.Version{Major: v.Major, Minor: v.Minor} if !targetVersion.Equal(*v) { m.lg.Warn("remotes server has mismatching etcd version", zap.String("remote-member-id", mid), diff --git a/server/etcdserver/version/monitor_test.go b/server/etcdserver/version/monitor_test.go index 342f3e9a9cff..2cefd32b0a18 100644 --- a/server/etcdserver/version/monitor_test.go +++ b/server/etcdserver/version/monitor_test.go @@ -127,7 +127,7 @@ func TestVersionMatchTarget(t *testing.T) { "When cannot parse peer version", &semver.Version{Major: 3, Minor: 4}, map[string]*version.Versions{ - "mem1": {Server: "3.4.1", Cluster: "3.4"}, + "mem1": {Server: "3.4", Cluster: "3.4.0"}, "mem2": {Server: "3.4.2-pre", Cluster: "3.4.0"}, "mem3": {Server: "3.4.2", Cluster: "3.4.0"}, }, @@ -277,6 +277,24 @@ func TestCancelDowngradeIfNeeded(t *testing.T) { "b": {Cluster: "3.6.0", Server: "3.6.2"}, }, }, + { + name: "Continue downgrade if just started", + memberVersions: map[string]*version.Versions{ + "a": {Cluster: "3.5.0", Server: "3.6.1"}, + "b": {Cluster: "3.5.0", Server: "3.6.2"}, + }, + downgrade: &DowngradeInfo{TargetVersion: "3.5.0", Enabled: true}, + expectDowngrade: &DowngradeInfo{TargetVersion: "3.5.0", Enabled: true}, + }, + { + name: "Continue downgrade if there is at least one member with not matching", + memberVersions: map[string]*version.Versions{ + "a": {Cluster: "3.5.0", Server: "3.5.1"}, + "b": {Cluster: "3.5.0", Server: "3.6.2"}, + }, + downgrade: &DowngradeInfo{TargetVersion: "3.5.0", Enabled: true}, + expectDowngrade: &DowngradeInfo{TargetVersion: "3.5.0", Enabled: true}, + }, { name: "Cancel downgrade if all members have downgraded", memberVersions: map[string]*version.Versions{