-
Notifications
You must be signed in to change notification settings - Fork 288
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): split RowChangeEvent if unique key is updated #9437
sink(ticdc): split RowChangeEvent if unique key is updated #9437
Conversation
cdc/model/sink.go
Outdated
} | ||
|
||
func (e RowChangedEvents) Less(i, j int) bool { | ||
return len(e[i].Columns)-len(e[i].PreColumns) < |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not easy to understand directly, please add some comments about how the condition comes up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to another implementation
@@ -719,6 +748,115 @@ func (t *SingleTableTxn) GetCommitTs() uint64 { | |||
return t.CommitTs | |||
} | |||
|
|||
// TrySplitAndSortUpdateEvent split update events if unique key is updated | |||
func (t *SingleTableTxn) TrySplitAndSortUpdateEvent() error { | |||
if len(t.Rows) < 2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible there is only an update event, shall we split it here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it's not needed to split a single update event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this update event has unique key columns changed? I think this update event also should be splitted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is almost identical to the convertRowChangedEvents
method.
After the enable-old-value is removed, this 2 method can be merged into one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pr focuses on the duplicated key case, the pre-condition is more than two update events emitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convertRowChangedEvents checks "enable-old-value" and handle key.
/retest-required |
1 similar comment
/retest-required |
…f-handle-key-is-changefeed # Conflicts: # cdc/sink/dmlsink/mq/mq_dml_sink.go
…ed-if-handle-key-is-changefeed
/test all |
for i := range updateEvent.Columns { | ||
col := updateEvent.Columns[i] | ||
preCol := updateEvent.PreColumns[i] | ||
if col != nil && (col.Flag.IsUniqueKey() || col.Flag.IsHandleKey()) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this condition " col.Flag.IsHandleKey()) && preCol != nil && (preCol.Flag.IsUniqueKey()" mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we check if the column is a part of the handle key or a unique key, if so we should check if the value has been changed,
for the condition " col.Flag.IsHandleKey()) && preCol != nil && (preCol.Flag.IsUniqueKey()" I think it's safe to split the row because we can always split an update to delete + insert.
…ed-if-handle-key-is-changefeed
/retest-required |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: asddongmen, nongfushanquan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <[email protected]>
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <[email protected]>
What problem does this PR solve?
Issue Number: close #9430
What is changed and how it works?
split and sort RowChangeEvent if unique key is updated
split the update to delete and insert, then sort the whole txn with the order delete>update>insert
Check List
Tests
Questions
Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?
Release note