Skip to content

Commit

Permalink
left reserved space in sqlBuf (#19494)
Browse files Browse the repository at this point in the history
left reserved space in sqlBuf

Approved by: @daviszhen
  • Loading branch information
ck89119 authored Oct 21, 2024
1 parent 741ba00 commit ae6d32f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/cdc/sinker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
const (
// DefaultMaxAllowedPacket of mysql is 64 MB
DefaultMaxAllowedPacket uint64 = 64 * 1024 * 1024
SqlBufReserved = 128
DefaultRetryTimes = -1
DefaultRetryDuration = 30 * time.Minute

Expand Down Expand Up @@ -470,7 +471,7 @@ func (s *mysqlSinker) appendSqlBuf(ctx context.Context, rowType RowType) (err er
}

// when len(sql) == max_allowed_packet, mysql will return error, so add equal here
if len(s.sqlBuf)+commaLen+len(s.rowBuf)+parLen >= cap(s.sqlBuf) {
if len(s.sqlBuf)+commaLen+len(s.rowBuf)+parLen+SqlBufReserved > cap(s.sqlBuf) {
if rowType == DeleteRow {
s.sqlBuf = appendByte(s.sqlBuf, ')')
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cdc/sinker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func Test_mysqlSinker_appendSqlBuf(t *testing.T) {

s := &mysqlSinker{
mysql: sink,
sqlBuf: make([]byte, 0, len(tsDeletePrefix)+len("delete")+2),
sqlBuf: make([]byte, 0, len(tsDeletePrefix)+len("delete")+2+SqlBufReserved),
tsInsertPrefix: []byte(tsInsertPrefix),
tsDeletePrefix: []byte(tsDeletePrefix),
preRowType: NoOp,
Expand Down

0 comments on commit ae6d32f

Please sign in to comment.