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) #11181

Merged
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 @@ -364,6 +364,7 @@ func (h logHeap) Len() int {
}

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 @@ -381,10 +382,19 @@ func (h logHeap) Less(i, j int) bool {
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.IsDelete() {
return true
} else if h[i].data.RedoRow.Row.IsUpdate() {
return !h[j].data.RedoRow.Row.IsDelete()
}
return false
}

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

Expand Down
Loading
Loading