Skip to content

Commit

Permalink
server: Use server version to decide if to downgrade has finished
Browse files Browse the repository at this point in the history
  • Loading branch information
serathius committed Oct 8, 2021
1 parent d9d0b12 commit bade01e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion server/etcdserver/version/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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),
Expand Down
20 changes: 19 additions & 1 deletion server/etcdserver/version/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit bade01e

Please sign in to comment.