Skip to content

Commit ddf4675

Browse files
fix CDC invalid command batch cleanup (#26000)
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #25934 ## What this PR does / why we need it: fix CDC invalid command batch cleanup Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 506875f commit ddf4675

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

pkg/cdc/sinker_v2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ func (s *mysqlSinker2) processCommand(ctx context.Context, cmd *Command) {
353353
zap.String("table", s.dbTblInfo.String()),
354354
zap.String("command", cmd.String()),
355355
zap.Error(err))
356+
cmd.Close()
356357
s.SetError(err)
357358
return
358359
}

pkg/cdc/sinker_v2_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,29 @@ func TestMysqlSinker2_CommandProcessing(t *testing.T) {
303303

304304
sinker.ClearError()
305305
})
306+
307+
t.Run("InvalidBatchCommand_CleansUp", func(t *testing.T) {
308+
mp, err := mpool.NewMPool("invalid-command-cleanup", 0, mpool.NoFixed)
309+
require.NoError(t, err)
310+
defer mpool.DeleteMPool(mp)
311+
312+
cmd := NewInsertBatchCommand(
313+
&batch.Batch{Vecs: []*vector.Vector{vector.NewVec(types.T_int32.ToType())}},
314+
mp,
315+
types.BuildTS(100, 0),
316+
types.BuildTS(200, 0),
317+
)
318+
require.NotNil(t, cmd.Mp)
319+
320+
sinker.processCommand(ctx, cmd)
321+
322+
require.Error(t, sinker.Error())
323+
assert.Contains(t, sinker.Error().Error(), "InsertBatch has no rows")
324+
assert.Nil(t, cmd.InsertBatch)
325+
assert.Nil(t, cmd.Mp)
326+
327+
sinker.ClearError()
328+
})
306329
}
307330

308331
func TestMysqlSinker2_Reset(t *testing.T) {

0 commit comments

Comments
 (0)