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

reparo: include filename into the mismatch errors #1266

Draft
wants to merge 1 commit into
base: release-6.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pkg/binlogfile/binlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import (

var (
// ErrFileContentCorruption represents file or directory's content is curruption for some season
ErrFileContentCorruption = errors.New("binlogger: content is corruption")
ErrFileContentCorruption = errors.NewNoStackError("binlogger: content is corruption")

// ErrCRCMismatch is the error represents crc don't match
ErrCRCMismatch = errors.New("binlogger: crc mismatch")
ErrCRCMismatch = errors.NewNoStackError("binlogger: crc mismatch")

// ErrMagicMismatch is the error represents magic don't match
ErrMagicMismatch = errors.New("binlogger: magic mismatch")
ErrMagicMismatch = errors.NewNoStackError("binlogger: magic mismatch")

crcTable = crc32.MakeTable(crc32.Castagnoli)

Expand Down Expand Up @@ -297,15 +297,16 @@ func (b *binlogger) Walk(ctx context.Context, from binlog.Pos, sendBinlog func(e
payload, offset, err = decoder.Decode()

if err != nil {
errCause := errors.Cause(err)
// if this is the current file we are writing,
// may contain a partial write entity in the file end
// we treat is as io.EOF and will return nil
if err == io.ErrUnexpectedEOF && isLastFile {
if errCause == io.ErrUnexpectedEOF && isLastFile {
err = io.EOF
}

// seek next binlog and report metrics
if err == ErrCRCMismatch || err == ErrMagicMismatch {
if errCause == ErrCRCMismatch || errCause == ErrMagicMismatch {
corruptionBinlogCounter.Add(1)
log.Error("decode binlog failed %v", zap.Reflect("position", from), zap.Error(err))
// offset + 1 to skip magic code of current binlog
Expand Down
2 changes: 1 addition & 1 deletion pkg/binlogfile/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (d *decoder) Decode() (payload []byte, offset int64, err error) {
// CheckMagic check weather the magicNum is right
func CheckMagic(mgicNum uint32) error {
if mgicNum != magic {
return ErrMagicMismatch
return errors.Annotatef(ErrMagicMismatch, "expected magic %d got %d", magic, mgicNum)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion reparo/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func getFirstBinlogCommitTS(filename string) (int64, error) {
return 0, nil
}
if err != nil {
return 0, errors.Annotatef(err, "decode binlog error")
return 0, errors.Annotatef(err, "decode binlog error from file %s", filename)
}

return binlog.CommitTs, nil
Expand Down
2 changes: 1 addition & 1 deletion reparo/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ func (r *dirPbReader) read() (binlog *pb.Binlog, err error) {
continue
}

return nil, errors.Annotate(err, "decode failed")
return nil, errors.Annotatef(err, "decode failed from file %s", r.files[r.idx-1])
}
}