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

(redo)ticdc: fix the event orderliness in redo log #11117

Merged
merged 6 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 13 additions & 3 deletions cdc/redo/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
}

func (h logHeap) Less(i, j int) bool {
// we separate ddl and dml, so we only need to compare dml with dml, and ddl with ddl.
if h[i].data.Type == model.RedoLogTypeDDL {
if h[i].data.RedoDDL.DDL == nil {
return true
Expand All @@ -363,10 +364,19 @@
return false
}

if h[i].data.RedoRow.Row.CommitTs == h[j].data.RedoRow.Row.CommitTs &&
h[i].data.RedoRow.Row.StartTs < h[j].data.RedoRow.Row.StartTs {
return true
if h[i].data.RedoRow.Row.CommitTs == h[j].data.RedoRow.Row.CommitTs {
if h[i].data.RedoRow.Row.StartTs != h[j].data.RedoRow.Row.StartTs {
return h[i].data.RedoRow.Row.StartTs < h[j].data.RedoRow.Row.StartTs
}
// in the same txn, we need to sort by delete/update/insert order
if h[i].data.RedoRow.Row.ToRowChangedEvent().IsDelete() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToRowChangedEvent should only be called once, if it may cost some resource.

else is redundant I think.

return true
} else if h[i].data.RedoRow.Row.ToRowChangedEvent().IsUpdate() {
return !h[j].data.RedoRow.Row.ToRowChangedEvent().IsDelete()
}
return false

Check warning on line 377 in cdc/redo/reader/reader.go

View check run for this annotation

Codecov / codecov/patch

cdc/redo/reader/reader.go#L377

Added line #L377 was not covered by tests
}

return h[i].data.RedoRow.Row.CommitTs < h[j].data.RedoRow.Row.CommitTs
}

Expand Down
Loading
Loading