diff --git a/server/etcdserver/apply.go b/server/etcdserver/apply.go index ca7930696c28..b6589ac53d9b 100644 --- a/server/etcdserver/apply.go +++ b/server/etcdserver/apply.go @@ -936,7 +936,13 @@ func (a *applierV3backend) RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleList } func (a *applierV3backend) ClusterVersionSet(r *membershippb.ClusterVersionSetRequest, shouldApplyV3 membership.ShouldApplyV3) { - a.s.cluster.SetVersion(semver.Must(semver.NewVersion(r.Ver)), api.UpdateCapability, shouldApplyV3) + prevVersion := a.s.Cluster().Version() + newVersion := semver.Must(semver.NewVersion(r.Ver)) + a.s.cluster.SetVersion(newVersion, api.UpdateCapability, shouldApplyV3) + // Force snapshot after cluster version downgrade. + if prevVersion != nil && newVersion.LessThan(*prevVersion) { + a.s.shouldSnapshot = true + } } func (a *applierV3backend) ClusterMemberAttrSet(r *membershippb.ClusterMemberAttrSetRequest, shouldApplyV3 membership.ShouldApplyV3) { diff --git a/server/etcdserver/server.go b/server/etcdserver/server.go index d3a7981bcc2c..57103a1e7dd1 100644 --- a/server/etcdserver/server.go +++ b/server/etcdserver/server.go @@ -291,6 +291,9 @@ type EtcdServer struct { clusterVersionChanged *notify.Notifier *AccessController + // shouldSnapshot informs if snapshot should be triggered after apply. + // Should only be set within apply. + shouldSnapshot bool } // NewServer creates a new EtcdServer from the supplied configuration. The @@ -1081,9 +1084,10 @@ func (s *EtcdServer) applyEntries(ep *etcdProgress, apply *apply) { } func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) { - if ep.appliedi-ep.snapi <= s.Cfg.SnapshotCount { + if !s.shouldSnapshot && ep.appliedi-ep.snapi <= s.Cfg.SnapshotCount { return } + s.shouldSnapshot = false lg := s.Logger() lg.Info( diff --git a/tests/e2e/cluster_downgrade_test.go b/tests/e2e/cluster_downgrade_test.go index 4769c4878ee5..78fa6ba80cc5 100644 --- a/tests/e2e/cluster_downgrade_test.go +++ b/tests/e2e/cluster_downgrade_test.go @@ -17,7 +17,6 @@ package e2e import ( "context" "fmt" - "strings" "testing" "time" @@ -66,8 +65,6 @@ func startEtcd(t *testing.T, execPath, dataDirPath string) *e2e.EtcdProcessClust ClusterSize: 1, InitialToken: "new", KeepDataDir: true, - // TODO: REMOVE snapshot override when snapshotting is automated after lowering storage versiont l - SnapshotCount: 5, }) if err != nil { t.Fatalf("could not start etcd process cluster (%v)", err) @@ -77,16 +74,6 @@ func startEtcd(t *testing.T, execPath, dataDirPath string) *e2e.EtcdProcessClust t.Fatalf("error closing etcd processes (%v)", errC) } }) - - prefixArgs := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ",")} - t.Log("Write keys to ensure wal snapshot is created so cluster version set is snapshotted") - e2e.ExecuteWithTimeout(t, 20*time.Second, func() { - for i := 0; i < 10; i++ { - if err := e2e.SpawnWithExpect(append(prefixArgs, "put", fmt.Sprintf("%d", i), "value"), "OK"); err != nil { - t.Fatal(err) - } - } - }) return epc }