Skip to content

Commit

Permalink
server: Snapshot after cluster version downgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
serathius committed Feb 14, 2022
1 parent bcadd03 commit 863ed5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
8 changes: 7 additions & 1 deletion server/etcdserver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.forceSnapshot = true
}
}

func (a *applierV3backend) ClusterMemberAttrSet(r *membershippb.ClusterMemberAttrSetRequest, shouldApplyV3 membership.ShouldApplyV3) {
Expand Down
6 changes: 5 additions & 1 deletion server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ type EtcdServer struct {
clusterVersionChanged *notify.Notifier

*AccessController
// forceSnapshot can force snapshot be triggered after apply, independent of the snapshotCount.
// Should only be set within apply code path. Used to force snapshot after cluster version downgrade.
forceSnapshot bool
}

// NewServer creates a new EtcdServer from the supplied configuration. The
Expand Down Expand Up @@ -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.forceSnapshot && ep.appliedi-ep.snapi <= s.Cfg.SnapshotCount {
return
}
s.forceSnapshot = false

lg := s.Logger()
lg.Info(
Expand Down
13 changes: 0 additions & 13 deletions tests/e2e/cluster_downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package e2e
import (
"context"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 863ed5a

Please sign in to comment.