Skip to content

Commit

Permalink
fix(server): use the correct err for internal server log (#563)
Browse files Browse the repository at this point in the history
### Motivation

use the correct error for the log.
  • Loading branch information
mattisonchao authored Nov 8, 2024
1 parent fb90db8 commit 7283e47
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions server/internal_rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ func (s *internalRpcServer) BecomeLeader(c context.Context, req *proto.BecomeLea
return nil, err
}

res, err2 := leader.BecomeLeader(c, req)
if err2 != nil {
res, err := leader.BecomeLeader(c, req)
if err != nil {
log.Warn(
"BecomeLeader failed",
slog.Any("error", err),
)
}
return res, err2
return res, err
}

func (s *internalRpcServer) AddFollower(c context.Context, req *proto.AddFollowerRequest) (*proto.AddFollowerResponse, error) {
Expand All @@ -199,14 +199,14 @@ func (s *internalRpcServer) AddFollower(c context.Context, req *proto.AddFollowe
return nil, err
}

res, err2 := leader.AddFollower(req)
if err2 != nil {
res, err := leader.AddFollower(req)
if err != nil {
log.Warn(
"AddFollower failed",
slog.Any("error", err),
)
}
return res, err2
return res, err
}

func (s *internalRpcServer) Truncate(c context.Context, req *proto.TruncateRequest) (*proto.TruncateResponse, error) {
Expand All @@ -226,12 +226,14 @@ func (s *internalRpcServer) Truncate(c context.Context, req *proto.TruncateReque
return nil, err
}

res, err2 := follower.Truncate(req)
log.Warn(
"Truncate failed",
slog.Any("error", err),
)
return res, err2
res, err := follower.Truncate(req)
if err != nil {
log.Warn(
"Truncate failed",
slog.Any("error", err),
)
}
return res, err
}

func (s *internalRpcServer) Replicate(srv proto.OxiaLogReplication_ReplicateServer) error {
Expand Down Expand Up @@ -274,14 +276,14 @@ func (s *internalRpcServer) Replicate(srv proto.OxiaLogReplication_ReplicateServ
return err
}

err2 := follower.Replicate(srv)
if err2 != nil && !errors.Is(err2, io.EOF) {
err = follower.Replicate(srv)
if err != nil && !errors.Is(err, io.EOF) {
log.Warn(
"Replicate failed",
slog.Any("error", err),
)
}
return err2
return err
}

func (s *internalRpcServer) SendSnapshot(srv proto.OxiaLogReplication_SendSnapshotServer) error {
Expand Down Expand Up @@ -326,8 +328,8 @@ func (s *internalRpcServer) SendSnapshot(srv proto.OxiaLogReplication_SendSnapsh
return err
}

err2 := follower.SendSnapshot(srv)
if err2 != nil {
err = follower.SendSnapshot(srv)
if err != nil {
s.log.Warn(
"SendSnapshot failed",
slog.Any("error", err),
Expand All @@ -336,7 +338,7 @@ func (s *internalRpcServer) SendSnapshot(srv proto.OxiaLogReplication_SendSnapsh
slog.String("peer", common.GetPeer(srv.Context())),
)
}
return err2
return err
}

func (s *internalRpcServer) GetStatus(_ context.Context, req *proto.GetStatusRequest) (*proto.GetStatusResponse, error) {
Expand Down

0 comments on commit 7283e47

Please sign in to comment.