Skip to content

Commit

Permalink
use nil error
Browse files Browse the repository at this point in the history
  • Loading branch information
GMHDBJD committed Nov 25, 2022
1 parent 4453b50 commit 6ed8b7c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dm/relay/binlog_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const (
chanSize = 1024
)

var nilErr error

// BinlogWriter is a binlog event writer which writes binlog events to a file.
// Open/Write/Close cannot be called concurrently.
type BinlogWriter struct {
Expand Down Expand Up @@ -91,13 +93,13 @@ func (w *BinlogWriter) run() {
}

if w.file == nil {
w.err.CompareAndSwap(nil, terror.ErrRelayWriterNotOpened.Delegate(errors.New("file not opened")))
w.err.CompareAndSwap(nilErr, terror.ErrRelayWriterNotOpened.Delegate(errors.New("file not opened")))
errOccurs = true
return
}
n, err := w.file.Write(buf.Bytes())
if err != nil {
w.err.CompareAndSwap(nil, terror.ErrBinlogWriterWriteDataLen.Delegate(err, n))
w.err.CompareAndSwap(nilErr, terror.ErrBinlogWriterWriteDataLen.Delegate(err, n))
errOccurs = true
return
}
Expand Down Expand Up @@ -168,7 +170,7 @@ func (w *BinlogWriter) Close() error {
w.logger.Error("fail to flush buffered data", zap.String("component", "file writer"), zap.Error(err))
}
if err := w.file.Close(); err != nil {
w.err.CompareAndSwap(nil, err)
w.err.CompareAndSwap(nilErr, err)
}
}

Expand All @@ -178,7 +180,7 @@ func (w *BinlogWriter) Close() error {
w.uuid.Store("")
w.filename.Store("")
w.input = nil
return w.err.Swap(nil)
return w.err.Swap(nilErr)
}

func (w *BinlogWriter) Write(rawData []byte) error {
Expand Down

0 comments on commit 6ed8b7c

Please sign in to comment.