Skip to content

Commit 2bb8fe3

Browse files
committed
Merge branch 'master' of github.com:go-mysql-org/go-mysql into fix-actual-master
Signed-off-by: lance6716 <[email protected]>
2 parents 2d7f728 + 54cc110 commit 2bb8fe3

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

canal/canal.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ func (c *Canal) prepareSyncer() error {
462462
Logger: c.cfg.Logger,
463463
Dialer: c.cfg.Dialer,
464464
Localhost: c.cfg.Localhost,
465+
EventCacheCount: c.cfg.EventCacheCount,
465466
RowsEventDecodeFunc: func(event *replication.RowsEvent, data []byte) error {
466467
pos, err := event.DecodeHeader(data)
467468
if err != nil {

canal/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ type Config struct {
107107

108108
// Set Localhost
109109
Localhost string
110+
111+
// EventCacheCount is the capacity of the BinlogStreamer internal event channel.
112+
// the default value is 10240.
113+
// if you table contain large columns, you can decrease this value to avoid OOM.
114+
EventCacheCount int
110115
}
111116

112117
func NewConfigWithFile(name string) (*Config, error) {

cmd/go-mysqldump/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func main() {
3333
os.Exit(1)
3434
}
3535

36-
if len(*ignoreTables) == 0 {
36+
if len(*ignoreTables) > 0 {
3737
subs := strings.Split(*ignoreTables, ",")
3838
for _, sub := range subs {
3939
if seps := strings.Split(sub, "."); len(seps) == 2 {

mysql/util.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ func AppendLengthEncodedInteger(b []byte, n uint64) []byte {
130130

131131
func RandomBuf(size int) []byte {
132132
buf := make([]byte, size)
133-
mrand.Seed(time.Now().UTC().UnixNano())
133+
// When this project supports golang 1.20 as a minimum, then this mrand.New(...)
134+
// line can be eliminated and the random number can be generated by simply
135+
// calling mrand.Intn()
136+
random := mrand.New(mrand.NewSource(time.Now().UTC().UnixNano()))
134137
min, max := 30, 127
135138
for i := 0; i < size; i++ {
136-
buf[i] = byte(min + mrand.Intn(max-min))
139+
buf[i] = byte(min + random.Intn(max-min))
137140
}
138141
return buf
139142
}
@@ -197,7 +200,10 @@ func PutLengthEncodedInt(n uint64) []byte {
197200
case n <= 0xffffff:
198201
return []byte{0xfd, byte(n), byte(n >> 8), byte(n >> 16)}
199202

200-
default: // n <= 0xffffffffffffffff:
203+
default:
204+
// handles case n <= 0xffffffffffffffff
205+
// using 'default' instead of 'case' to avoid static analysis error
206+
// SA4003: every value of type uint64 is <= math.MaxUint64
201207
return []byte{0xfe, byte(n), byte(n >> 8), byte(n >> 16), byte(n >> 24),
202208
byte(n >> 32), byte(n >> 40), byte(n >> 48), byte(n >> 56)}
203209
}

0 commit comments

Comments
 (0)