Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
br: error log optimization (#29640)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengou1 authored Dec 21, 2021
1 parent 042b349 commit a6be9a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,13 @@ func (bc *Client) BackupRanges(
elctx := logutil.ContextWithField(ectx, logutil.RedactAny("range-sn", id))
err := bc.BackupRange(elctx, sk, ek, req, metaWriter, progressCallBack)
if err != nil {
return errors.Trace(err)
// The error due to context cancel, stack trace is meaningless, the stack shall be suspended (also clear)
if errors.Cause(err) == context.Canceled {
return errors.SuspendStack(err)
} else {
return errors.Trace(err)
}

}
return nil
})
Expand Down
11 changes: 10 additions & 1 deletion pkg/summary/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
package summary

import (
"context"
"strings"
"sync"
"time"

"github.com/docker/go-units"
berror "github.com/pingcap/errors"
"github.com/pingcap/log"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -188,9 +190,16 @@ func (tc *logCollector) Summary(name string) {
}

if len(tc.failureReasons) != 0 || !tc.successStatus {
var canceledUnits int
for unitName, reason := range tc.failureReasons {
logFields = append(logFields, zap.String("unit-name", unitName), zap.Error(reason))
if berror.Cause(reason) != context.Canceled {
logFields = append(logFields, zap.String("unit-name", unitName), zap.Error(reason))
} else {
canceledUnits++
}
}
// only print total number of cancel unit
log.Info("units canceled", zap.Int("cancel-unit", canceledUnits))
tc.log(name+" failed summary", logFields...)
return
}
Expand Down

0 comments on commit a6be9a9

Please sign in to comment.