Skip to content

Commit

Permalink
(redo)ticdc: fix the event orderliness in redo log (pingcap#11117) (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored May 29, 2024
1 parent f99c4dc commit 0ba9329
Show file tree
Hide file tree
Showing 3 changed files with 541 additions and 18 deletions.
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 == nil || 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

0 comments on commit 0ba9329

Please sign in to comment.