Skip to content
Merged
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
6 changes: 2 additions & 4 deletions canal/canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Canal struct {
includeTableRegex []*regexp.Regexp
excludeTableRegex []*regexp.Regexp

delay *uint32
delay atomic.Uint32

ctx context.Context
cancel context.CancelFunc
Expand Down Expand Up @@ -85,8 +85,6 @@ func NewCanal(cfg *Config) (*Canal, error) {
}
c.master = &masterInfo{logger: c.cfg.Logger}

c.delay = new(uint32)

var err error

if err = c.prepareDumper(); err != nil {
Expand Down Expand Up @@ -195,7 +193,7 @@ func (c *Canal) prepareDumper() error {
}

func (c *Canal) GetDelay() uint32 {
return atomic.LoadUint32(c.delay)
return c.delay.Load()
}

// Run will first try to dump all data from MySQL master `mysqldump`,
Expand Down
3 changes: 1 addition & 2 deletions canal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package canal

import (
"log/slog"
"sync/atomic"
"time"

"github.com/go-mysql-org/go-mysql/mysql"
Expand Down Expand Up @@ -259,7 +258,7 @@ func (c *Canal) updateReplicationDelay(ev *replication.BinlogEvent) {
if now >= ev.Header.Timestamp {
newDelay = now - ev.Header.Timestamp
}
atomic.StoreUint32(c.delay, newDelay)
c.delay.Store(newDelay)
}

func (c *Canal) handleRowsEvent(e *replication.BinlogEvent) error {
Expand Down
8 changes: 4 additions & 4 deletions replication/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type BinlogParser struct {
timestampStringLocation *time.Location

// used to start/stop processing
stopProcessing uint32
stopProcessing atomic.Bool

useDecimal bool
useFloatWithTrailingZero bool
Expand All @@ -54,11 +54,11 @@ func NewBinlogParser() *BinlogParser {
}

func (p *BinlogParser) Stop() {
atomic.StoreUint32(&p.stopProcessing, 1)
p.stopProcessing.Store(true)
}

func (p *BinlogParser) Resume() {
atomic.StoreUint32(&p.stopProcessing, 0)
p.stopProcessing.Store(false)
}

func (p *BinlogParser) Reset() {
Expand Down Expand Up @@ -166,7 +166,7 @@ func (p *BinlogParser) parseSingleEvent(r io.Reader, onEvent OnEventFunc) (bool,
}

func (p *BinlogParser) ParseReader(r io.Reader, onEvent OnEventFunc) error {
for atomic.LoadUint32(&p.stopProcessing) != 1 {
for !p.stopProcessing.Load() {
done, err := p.parseSingleEvent(r, onEvent)
if err != nil {
if err == errMissingTableMapEvent {
Expand Down
Loading