Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: refine package server error log format in RFC #2713

Closed
wants to merge 3 commits into from

Conversation

ZenoTan
Copy link
Contributor

@ZenoTan ZenoTan commented Aug 3, 2020

What problem does this PR solve?

Solve #2704

What is changed and how it works?

Check List

Tests

  • Unit test

Code changes

Side effects

Related changes

Release note

@ti-srebot ti-srebot added the contribution This PR is from a community contributor. label Aug 3, 2020
@@ -248,10 +249,10 @@ func (m *Member) CampaignLeader(lease *LeaderLease, leaseTimeout int64) error {
Then(clientv3.OpPut(leaderKey, m.memberValue, clientv3.WithLease(lease.ID))).
Commit()
if err != nil {
return errors.WithStack(err)
return errs.ErrEtcdLeaderSave.FastGenByArgs()
Copy link
Contributor

@nolouch nolouch Aug 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe return err directly, we need to know the actual error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fix it, PTAL @nolouch

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 3, 2020
@ZenoTan
Copy link
Contributor Author

ZenoTan commented Aug 5, 2020

/run-all-tests

@ZenoTan ZenoTan requested a review from nolouch August 5, 2020 07:01
@@ -223,7 +224,7 @@ func (h *Handler) RemoveScheduler(name string) error {
return err
}
if err = c.RemoveScheduler(name); err != nil {
log.Error("can not remove scheduler", zap.String("scheduler-name", name), zap.Error(err))
log.Error("can not remove scheduler", zap.Error(errs.ErrSchedulerOperation.FastGenByArgs(name)), zap.NamedError("cause", err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the error already is an RFC error? cc @rleungx

@rleungx
Copy link
Member

rleungx commented Aug 20, 2020

Please resolve the conflicts.

@rleungx rleungx mentioned this pull request Aug 21, 2020
14 tasks
@ZenoTan ZenoTan force-pushed the server branch 2 times, most recently from 199d8f0 to 1657e05 Compare August 24, 2020 04:18
@@ -1094,7 +1095,7 @@ func (s *Server) campaignLeader() {
zap.String("campaign-pd-leader-name", s.Name()),
zap.String("purpose", s.member.Leadership.Purpose))
if err := s.member.Leadership.Campaign(s.cfg.LeaderLease, s.member.GetLeaderPath(), s.member.MemberValue()); err != nil {
log.Error("campaign pd leader meet error", zap.Error(err))
log.Error("campaign pd leader meet error", errs.ZapError(errs.ErrCampaignLeader, err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this is already a RFC error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It is a local error caused by lease or etcd.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we need to wrap the third error to RFC error in member package rather than in the server package. if the error is not returned by a third-party package, just print the log directly or return the error directly.

@@ -1112,18 +1113,18 @@ func (s *Server) campaignLeader() {

log.Info("initialize the global TSO allocator")
if err := s.tsoAllocator.Initialize(); err != nil {
log.Error("failed to initialize the global TSO allocator", zap.Error(err))
log.Error("failed to initialize the global TSO allocator", errs.ZapError(errs.ErrCreateTSOStream, err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz directly use RFC error.

@@ -395,7 +396,7 @@ func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error {

region := core.RegionFromHeartbeat(request)
if region.GetLeader() == nil {
log.Error("invalid request, the leader is nil", zap.Reflect("reqeust", request))
log.Error("invalid request, the leader is nil", zap.Reflect("reqeust", request), errs.ZapError(errs.ErrHeartBeatLeaderNil, err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the err come from?

@@ -209,9 +210,9 @@ func (h *Handler) AddScheduler(name string, args ...string) error {
}
log.Info("create scheduler", zap.String("scheduler-name", s.GetName()))
if err = c.AddScheduler(s, args...); err != nil {
log.Error("can not add scheduler", zap.String("scheduler-name", s.GetName()), zap.Error(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the scheduler-name?

@@ -87,15 +88,15 @@ func (s *heartbeatStreams) run() {
if store == nil {
log.Error("failed to get store",
zap.Uint64("region-id", msg.RegionId),
zap.Uint64("store-id", storeID))
errs.ZapError(errs.ErrStoreNotFound, nil))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the store-id?

@@ -396,7 +396,7 @@ func (s *Server) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error {

region := core.RegionFromHeartbeat(request)
if region.GetLeader() == nil {
log.Error("invalid request, the leader is nil", zap.Reflect("reqeust", request), errs.ZapError(errs.ErrHeartBeatLeaderNil, err))
log.Error("invalid request, the leader is nil", zap.Reflect("reqeust", request), errs.ZapError(errs.ErrHeartBeatLeaderNil, nil))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to change the ZapError to make the cause error as an optional parameter?

Copy link
Member

@rleungx rleungx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign-off DCO. The rest LGTM

@ZenoTan ZenoTan force-pushed the server branch 5 times, most recently from 286c58f to 60facde Compare August 24, 2020 12:40
Signed-off-by: ZenoTan <zenotan1998@gmail.com>
Signed-off-by: ZenoTan <zenotan1998@gmail.com>
@rleungx
Copy link
Member

rleungx commented Aug 25, 2020

Why change the file permission?

// ZapError is used to make the log output easier.
func ZapError(err *errors.Error, causeError ...error) zap.Field {
var e interface{}
if len(causeError) == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the len > 1?

@@ -1094,7 +1095,7 @@ func (s *Server) campaignLeader() {
zap.String("campaign-pd-leader-name", s.Name()),
zap.String("purpose", s.member.Leadership.Purpose))
if err := s.member.Leadership.Campaign(s.cfg.LeaderLease, s.member.GetLeaderPath(), s.member.MemberValue()); err != nil {
log.Error("campaign pd leader meet error", zap.Error(err))
log.Error("campaign pd leader meet error", errs.ZapError(errs.ErrCampaignLeader, err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we need to wrap the third error to RFC error in member package rather than in the server package. if the error is not returned by a third-party package, just print the log directly or return the error directly.

@ZenoTan ZenoTan closed this Aug 28, 2020
@ZenoTan ZenoTan deleted the server branch August 28, 2020 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants