Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sink(ticdc): precheck before split the update event #6403

Merged
merged 7 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cdc/entry/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,16 @@ func datum2Column(tableInfo *model.TableInfo, datums map[int64]types.Datum, fill
for _, colInfo := range tableInfo.Columns {
colSize := 0
if !model.IsColCDCVisible(colInfo) {
log.Info("skip the column which is not visible",
zap.String("table", tableInfo.Name.O), zap.String("column", colInfo.Name.O))
continue
}
colName := colInfo.Name.O
colDatums, exist := datums[colInfo.ID]
var colValue interface{}
if !exist && !fillWithDefaultValue {
log.Info("column value is not found",
zap.String("table", tableInfo.Name.O), zap.String("column", colName))
continue
}
var err error
Expand Down
7 changes: 5 additions & 2 deletions cdc/processor/pipeline/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ func shouldSplitUpdateEvent(updateEvent *model.PolymorphicEvent) bool {
handleKeyCount := 0
equivalentHandleKeyCount := 0
for i := range updateEvent.Row.Columns {
if updateEvent.Row.Columns[i].Flag.IsHandleKey() && updateEvent.Row.PreColumns[i].Flag.IsHandleKey() {
col := updateEvent.Row.Columns[i]
preCol := updateEvent.Row.PreColumns[i]
if col != nil && col.Flag.IsHandleKey() && preCol != nil && preCol.Flag.IsHandleKey() {
handleKeyCount++
colValueString := model.ColumnValueString(updateEvent.Row.Columns[i].Value)
preColValueString := model.ColumnValueString(updateEvent.Row.PreColumns[i].Value)
Expand Down Expand Up @@ -286,7 +288,8 @@ func splitUpdateEvent(updateEvent *model.PolymorphicEvent) (*model.PolymorphicEv
deleteEvent.Row.Columns = nil
for i := range deleteEvent.Row.PreColumns {
// NOTICE: Only the handle key pre column is retained in the delete event.
if !deleteEvent.Row.PreColumns[i].Flag.IsHandleKey() {
if deleteEvent.Row.PreColumns[i] != nil &&
!deleteEvent.Row.PreColumns[i].Flag.IsHandleKey() {
deleteEvent.Row.PreColumns[i] = nil
}
}
Expand Down
17 changes: 13 additions & 4 deletions cdc/processor/pipeline/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,11 @@ func TestSplitUpdateEventWhenDisableOldValue(t *testing.T) {
sink.Reset()
// Update to the handle key column.
columns = []*model.Column{
{
Name: "col0",
Flag: model.BinaryFlag,
Value: "col1-value-updated",
},
{
Name: "col1",
Flag: model.BinaryFlag,
Expand All @@ -628,6 +633,8 @@ func TestSplitUpdateEventWhenDisableOldValue(t *testing.T) {
},
}
preColumns = []*model.Column{
// It is possible that the pre columns are nil. For example, when you do `add column` DDL.
nil,
{
Name: "col1",
Flag: model.BinaryFlag,
Expand All @@ -653,9 +660,11 @@ func TestSplitUpdateEventWhenDisableOldValue(t *testing.T) {

deleteEventIndex := 0
require.Len(t, sink.received[deleteEventIndex].row.Columns, 0)
require.Len(t, sink.received[deleteEventIndex].row.PreColumns, 2)
nonHandleKeyColIndex := 0
handleKeyColIndex := 1
require.Len(t, sink.received[deleteEventIndex].row.PreColumns, 3)
nilColIndex := 0
require.Nil(t, sink.received[deleteEventIndex].row.PreColumns[nilColIndex])
nonHandleKeyColIndex := 1
handleKeyColIndex := 2
// NOTICE: When old value disabled, we only keep the handle key pre cols.
require.Nil(t, sink.received[deleteEventIndex].row.PreColumns[nonHandleKeyColIndex])
require.Equal(t, "col2", sink.received[deleteEventIndex].row.PreColumns[handleKeyColIndex].Name)
Expand All @@ -664,7 +673,7 @@ func TestSplitUpdateEventWhenDisableOldValue(t *testing.T) {
)

insertEventIndex := 1
require.Len(t, sink.received[insertEventIndex].row.Columns, 2)
require.Len(t, sink.received[insertEventIndex].row.Columns, 3)
require.Len(t, sink.received[insertEventIndex].row.PreColumns, 0)
}

Expand Down