Skip to content

Commit

Permalink
test: add TestIgnoreEmptyRowChangeEvent test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 authored and ti-chi-bot committed Oct 27, 2021
1 parent 42873aa commit 1b4a101
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
20 changes: 20 additions & 0 deletions cdc/processor/pipeline/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@ func (s *outputSuite) TestManyTs(c *check.C) {
c.Assert(node.CheckpointTs(), check.Equals, uint64(2))
}

func (s *outputSuite) TestIgnoreEmptyRowChangeEvent(c *check.C) {
defer testleak.AfterTest(c)()
ctx := cdcContext.NewContext(context.Background(), &cdcContext.GlobalVars{})
ctx = cdcContext.WithChangefeedVars(ctx, &cdcContext.ChangefeedVars{
ID: "changefeed-id-test-ignore-empty-row-change-event",
Info: &model.ChangeFeedInfo{
StartTs: oracle.GoTimeToTS(time.Now()),
Config: config.GetDefaultReplicaConfig(),
},
})
sink := &mockSink{}
node := newSinkNode(sink, 0, 10, &mockFlowController{})
c.Assert(node.Init(pipeline.MockNodeContext4Test(ctx, pipeline.Message{}, nil)), check.IsNil)

// empty row, no Columns and PreColumns.
c.Assert(node.Receive(pipeline.MockNodeContext4Test(ctx,
pipeline.PolymorphicEventMessage(&model.PolymorphicEvent{CRTs: 1, RawKV: &model.RawKVEntry{OpType: model.OpTypePut}, Row: &model.RowChangedEvent{CommitTs: 1}}), nil)), check.IsNil)
c.Assert(node.eventBuffer, check.HasLen, 0)
}

func (s *outputSuite) TestSplitUpdateEventWhenEnableOldValue(c *check.C) {
defer testleak.AfterTest(c)()
ctx := cdcContext.NewContext(context.Background(), &cdcContext.GlobalVars{})
Expand Down
6 changes: 0 additions & 6 deletions cdc/sink/codec/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,6 @@ func (d *JSONEventBatchEncoder) EncodeCheckpointEvent(ts uint64) (*MQMessage, er

// AppendRowChangedEvent implements the EventBatchEncoder interface
func (d *JSONEventBatchEncoder) AppendRowChangedEvent(e *model.RowChangedEvent) (EncoderResult, error) {
// Some transactions could generate empty row change event, such as
// begin; insert into t (id) values (1); delete from t where id=1; commit;
// Just ignore these row changed events
if len(e.Columns) == 0 && len(e.PreColumns) == 0 {
return EncoderNoOperation, nil
}
keyMsg, valueMsg := rowEventToMqMessage(e)
key, err := keyMsg.Encode()
if err != nil {
Expand Down
22 changes: 0 additions & 22 deletions cdc/sink/codec/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,28 +346,6 @@ func (s *batchSuite) TestMaxBatchSize(c *check.C) {
c.Check(sum, check.Equals, 10000)
}

func (s *batchSuite) TestEmptyMessage(c *check.C) {
defer testleak.AfterTest(c)()
encoder := NewJSONEventBatchEncoder()
err := encoder.SetParams(map[string]string{"max-batch-size": "64"})
c.Check(err, check.IsNil)

emptyEvent := &model.RowChangedEvent{
CommitTs: 1,
Table: &model.TableName{Schema: "a", Table: "b"},
Columns: []*model.Column{},
}

for i := 0; i < 10000; i++ {
r, err := encoder.AppendRowChangedEvent(emptyEvent)
c.Check(r, check.Equals, EncoderNoOperation)
c.Check(err, check.IsNil)
}

messages := encoder.Build()
c.Assert(messages, check.HasLen, 0)
}

func (s *batchSuite) TestDefaultEventBatchCodec(c *check.C) {
defer testleak.AfterTest(c)()
s.testBatchCodec(c, func() EventBatchEncoder {
Expand Down

0 comments on commit 1b4a101

Please sign in to comment.