From ae6d32ffef6a529c75a0999dcf5145b2da5e7777 Mon Sep 17 00:00:00 2001 From: Kai Cao Date: Tue, 22 Oct 2024 03:11:31 +0800 Subject: [PATCH] left reserved space in sqlBuf (#19494) left reserved space in sqlBuf Approved by: @daviszhen --- pkg/cdc/sinker.go | 3 ++- pkg/cdc/sinker_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/cdc/sinker.go b/pkg/cdc/sinker.go index e889f061fc62..b1e983912c51 100644 --- a/pkg/cdc/sinker.go +++ b/pkg/cdc/sinker.go @@ -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 @@ -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, ')') } diff --git a/pkg/cdc/sinker_test.go b/pkg/cdc/sinker_test.go index f78b8a376ce2..b09b6dab3687 100644 --- a/pkg/cdc/sinker_test.go +++ b/pkg/cdc/sinker_test.go @@ -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,