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

Add EventCacheCount as member of BinlogSyncerConfig to limit streamer's event channel size #830

Merged
merged 5 commits into from
Oct 12, 2023
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
10 changes: 9 additions & 1 deletion replication/binlogstreamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,17 @@ func (s *BinlogStreamer) closeWithError(err error) {
}

func NewBinlogStreamer() *BinlogStreamer {
return NewBinlogStreamerWithChanSize(10240)
}

func NewBinlogStreamerWithChanSize(chanSize int) *BinlogStreamer {
s := new(BinlogStreamer)

s.ch = make(chan *BinlogEvent, 10240)
if chanSize <= 0 {
chanSize = 10240
}

s.ch = make(chan *BinlogEvent, chanSize)
s.ech = make(chan error, 4)

return s
Expand Down
7 changes: 6 additions & 1 deletion replication/binlogsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ type BinlogSyncerConfig struct {
RowsEventDecodeFunc func(*RowsEvent, []byte) error

DiscardGTIDSet bool

EventCacheCount int
}

// BinlogSyncer syncs binlog event from server.
Expand Down Expand Up @@ -166,6 +168,9 @@ func NewBinlogSyncer(cfg BinlogSyncerConfig) *BinlogSyncer {
dialer := &net.Dialer{}
cfg.Dialer = dialer.DialContext
}
if cfg.EventCacheCount == 0 {
cfg.EventCacheCount = 10240
}

// Clear the Password to avoid outputing it in log.
pass := cfg.Password
Expand Down Expand Up @@ -393,7 +398,7 @@ func (b *BinlogSyncer) prepare() error {
func (b *BinlogSyncer) startDumpStream() *BinlogStreamer {
b.running = true

s := NewBinlogStreamer()
s := NewBinlogStreamerWithChanSize(b.cfg.EventCacheCount)

b.wg.Add(1)
go b.onStream(s)
Expand Down