Skip to content

Commit

Permalink
Update etcdserver and client 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 b8e2dc6
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 2 deletions.
4 changes: 4 additions & 0 deletions client/v3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ func (mm mockMaintenance) Downgrade(ctx context.Context, action DowngradeAction,
return nil, nil
}

func (mm mockMaintenance) DowngradeVersionTest(ctx context.Context, version string) (*DowngradeVersionTestResponse, error) {
return nil, nil
}

type mockAuthServer struct {
*etcdserverpb.UnimplementedAuthServer
}
Expand Down
12 changes: 11 additions & 1 deletion client/v3/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type (
MoveLeaderResponse pb.MoveLeaderResponse
DowngradeResponse pb.DowngradeResponse

DowngradeAction pb.DowngradeRequest_DowngradeAction
DowngradeAction pb.DowngradeRequest_DowngradeAction
DowngradeVersionTestResponse pb.DowngradeVersionTestResponse
)

const (
Expand Down Expand Up @@ -87,6 +88,10 @@ type Maintenance interface {
// on the cluster version.
// Supported since etcd 3.5.
Downgrade(ctx context.Context, action DowngradeAction, version string) (*DowngradeResponse, error)

// DowngradeVersionTest is for test only! It enables users (test cases)
// to send a DowngradeVersionTestRequest to etcdserver.
DowngradeVersionTest(ctx context.Context, version string) (*DowngradeVersionTestResponse, error)
}

// SnapshotResponse is aggregated response from the snapshot stream.
Expand Down Expand Up @@ -348,3 +353,8 @@ func (m *maintenance) Downgrade(ctx context.Context, action DowngradeAction, ver
resp, err := m.remote.Downgrade(ctx, &pb.DowngradeRequest{Action: actionType, Version: version}, m.callOpts...)
return (*DowngradeResponse)(resp), ContextError(ctx, err)
}

func (m *maintenance) DowngradeVersionTest(ctx context.Context, version string) (*DowngradeVersionTestResponse, error) {
resp, err := m.remote.DowngradeVersionTest(ctx, &pb.DowngradeVersionTestRequest{Ver: version})
return (*DowngradeVersionTestResponse)(resp), ContextError(ctx, err)

Check warning on line 359 in client/v3/maintenance.go

View check run for this annotation

Codecov / codecov/patch

client/v3/maintenance.go#L357-L359

Added lines #L357 - L359 were not covered by tests
}
4 changes: 4 additions & 0 deletions client/v3/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ type retryAuthClient struct {
ac pb.AuthClient
}

func (rmc *retryMaintenanceClient) DowngradeVersionTest(ctx context.Context, in *pb.DowngradeVersionTestRequest, opts ...grpc.CallOption) (resp *pb.DowngradeVersionTestResponse, err error) {
return rmc.mc.DowngradeVersionTest(ctx, in, opts...)

Check warning on line 237 in client/v3/retry.go

View check run for this annotation

Codecov / codecov/patch

client/v3/retry.go#L236-L237

Added lines #L236 - L237 were not covered by tests
}

// RetryAuthClient implements a AuthClient.
func RetryAuthClient(c *Client) pb.AuthClient {
return &retryAuthClient{
Expand Down
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)

Check warning on line 303 in server/etcdserver/api/v3rpc/maintenance.go

View check run for this annotation

Codecov / codecov/patch

server/etcdserver/api/v3rpc/maintenance.go#L300-L303

Added lines #L300 - L303 were not covered by tests
}
resp.Header = &pb.ResponseHeader{}
ms.hdr.fill(resp.Header)
return resp, nil

Check warning on line 307 in server/etcdserver/api/v3rpc/maintenance.go

View check run for this annotation

Codecov / codecov/patch

server/etcdserver/api/v3rpc/maintenance.go#L305-L307

Added lines #L305 - L307 were not covered by tests
}

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)

Check warning on line 372 in server/etcdserver/api/v3rpc/maintenance.go

View check run for this annotation

Codecov / codecov/patch

server/etcdserver/api/v3rpc/maintenance.go#L370-L372

Added lines #L370 - L372 were not covered by tests
}

return ams.maintenanceServer.DowngradeVersionTest(ctx, r)

Check warning on line 375 in server/etcdserver/api/v3rpc/maintenance.go

View check run for this annotation

Codecov / codecov/patch

server/etcdserver/api/v3rpc/maintenance.go#L375

Added line #L375 was not covered by tests
}
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"

Check warning on line 2033 in server/etcdserver/server.go

View check run for this annotation

Codecov / codecov/patch

server/etcdserver/server.go#L2032-L2033

Added lines #L2032 - L2033 were not covered by tests
// 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

Check warning on line 1052 in server/etcdserver/v3_server.go

View check run for this annotation

Codecov / codecov/patch

server/etcdserver/v3_server.go#L1049-L1052

Added lines #L1049 - L1052 were not covered by tests
}
return resp.(*pb.DowngradeVersionTestResponse), nil

Check warning on line 1054 in server/etcdserver/v3_server.go

View check run for this annotation

Codecov / codecov/patch

server/etcdserver/v3_server.go#L1054

Added line #L1054 was not covered by tests
}

func (s *EtcdServer) downgradeCancel(ctx context.Context) (*pb.DowngradeResponse, error) {
err := s.Version().DowngradeCancel(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions server/proxy/grpcproxy/adapter/maintenance_client_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (s *mts2mtc) Downgrade(ctx context.Context, r *pb.DowngradeRequest, opts ..
return s.mts.Downgrade(ctx, r)
}

func (s *mts2mtc) DowngradeVersionTest(ctx context.Context, r *pb.DowngradeVersionTestRequest, opts ...grpc.CallOption) (*pb.DowngradeVersionTestResponse, error) {
return s.mts.DowngradeVersionTest(ctx, r)

Check warning on line 60 in server/proxy/grpcproxy/adapter/maintenance_client_adapter.go

View check run for this annotation

Codecov / codecov/patch

server/proxy/grpcproxy/adapter/maintenance_client_adapter.go#L59-L60

Added lines #L59 - L60 were not covered by tests
}

func (s *mts2mtc) Snapshot(ctx context.Context, in *pb.SnapshotRequest, opts ...grpc.CallOption) (pb.Maintenance_SnapshotClient, error) {
cs := newPipeStream(ctx, func(ss chanServerStream) error {
return s.mts.Snapshot(in, &ss2scServerStream{ss})
Expand Down
4 changes: 4 additions & 0 deletions server/proxy/grpcproxy/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ func (mp *maintenanceProxy) MoveLeader(ctx context.Context, r *pb.MoveLeaderRequ
func (mp *maintenanceProxy) Downgrade(ctx context.Context, r *pb.DowngradeRequest) (*pb.DowngradeResponse, error) {
return mp.maintenanceClient.Downgrade(ctx, r)
}

func (mp *maintenanceProxy) DowngradeVersionTest(ctx context.Context, r *pb.DowngradeVersionTestRequest) (*pb.DowngradeVersionTestResponse, error) {
return mp.maintenanceClient.DowngradeVersionTest(ctx, r)

Check warning on line 91 in server/proxy/grpcproxy/maintenance.go

View check run for this annotation

Codecov / codecov/patch

server/proxy/grpcproxy/maintenance.go#L90-L91

Added lines #L90 - L91 were not covered by tests
}

0 comments on commit b8e2dc6

Please sign in to comment.