Skip to content

Commit

Permalink
Update etcdserver to support DowngradeVersionTest request
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
  • Loading branch information
ahrtr committed Jan 25, 2025
1 parent 78047ed commit 82fcf8d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
19 changes: 19 additions & 0 deletions server/etcdserver/api/v3rpc/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Alarmer interface {

type Downgrader interface {
Downgrade(ctx context.Context, dr *pb.DowngradeRequest) (*pb.DowngradeResponse, error)
DowngradeVersionTest(ctx context.Context, r *pb.DowngradeVersionTestRequest) (*pb.DowngradeVersionTestResponse, error)
}

type LeaderTransferrer interface {
Expand Down Expand Up @@ -296,6 +297,16 @@ func (ms *maintenanceServer) Downgrade(ctx context.Context, r *pb.DowngradeReque
return resp, nil
}

func (ms *maintenanceServer) DowngradeVersionTest(ctx context.Context, r *pb.DowngradeVersionTestRequest) (*pb.DowngradeVersionTestResponse, error) {
resp, err := ms.d.DowngradeVersionTest(ctx, r)
if err != nil {
return nil, togRPCError(err)
}
resp.Header = &pb.ResponseHeader{}
ms.hdr.fill(resp.Header)
return resp, nil
}

type authMaintenanceServer struct {
*maintenanceServer
*AuthAdmin
Expand Down Expand Up @@ -355,3 +366,11 @@ func (ams *authMaintenanceServer) Downgrade(ctx context.Context, r *pb.Downgrade

return ams.maintenanceServer.Downgrade(ctx, r)
}

func (ams *authMaintenanceServer) DowngradeVersionTest(ctx context.Context, r *pb.DowngradeVersionTestRequest) (*pb.DowngradeVersionTestResponse, error) {
if err := ams.isPermitted(ctx); err != nil {
return nil, togRPCError(err)
}

return ams.maintenanceServer.DowngradeVersionTest(ctx, r)
}
6 changes: 5 additions & 1 deletion server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry, shouldApplyV3 membership.
}

func (s *EtcdServer) applyInternalRaftRequest(r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *apply.Result {
if r.ClusterVersionSet == nil && r.ClusterMemberAttrSet == nil && r.DowngradeInfoSet == nil {
if r.ClusterVersionSet == nil && r.ClusterMemberAttrSet == nil && r.DowngradeInfoSet == nil && r.DowngradeVersionTest == nil {
if !shouldApplyV3 {
return nil
}
Expand All @@ -2029,6 +2029,10 @@ func (s *EtcdServer) applyInternalRaftRequest(r *pb.InternalRaftRequest, shouldA
case r.DowngradeInfoSet != nil:
op = "DowngradeInfoSet" // Implemented in 3.5.x
membershipApplier.DowngradeInfoSet(r.DowngradeInfoSet, shouldApplyV3)
case r.DowngradeVersionTest != nil:
op = "DowngradeVersionTest"
// do nothing, we are good as long as a WAL record
// has already been generated for this request.
default:
s.lg.Panic("not implemented apply", zap.Stringer("raft-request", r))
return nil
Expand Down
10 changes: 10 additions & 0 deletions server/etcdserver/v3_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,16 @@ func (s *EtcdServer) downgradeEnable(ctx context.Context, r *pb.DowngradeRequest
return &resp, nil
}

// DowngradeVersionTest is for test only! We intentionally send
// a raft request so that a related WAL record can be generated.
func (s *EtcdServer) DowngradeVersionTest(ctx context.Context, r *pb.DowngradeVersionTestRequest) (*pb.DowngradeVersionTestResponse, error) {
resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{DowngradeVersionTest: r})
if err != nil {
return nil, err
}
return resp.(*pb.DowngradeVersionTestResponse), nil
}

func (s *EtcdServer) downgradeCancel(ctx context.Context) (*pb.DowngradeResponse, error) {
err := s.Version().DowngradeCancel(ctx)
if err != nil {
Expand Down

0 comments on commit 82fcf8d

Please sign in to comment.