Skip to content

Commit

Permalink
(redo)ticdc: fix the event orderliness in redo log (#11117) (#11181)
Browse files Browse the repository at this point in the history
close #11096
  • Loading branch information
ti-chi-bot authored May 29, 2024
1 parent 192fc75 commit 6db1dc2
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.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 6db1dc2

Please sign in to comment.