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 4 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
19 changes: 16 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,22 @@
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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove useless else branch:

Suggested change
if h[i].data.RedoRow.Row.StartTs < h[j].data.RedoRow.Row.StartTs {
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
}
...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good Point!

return true
} else if h[i].data.RedoRow.Row.StartTs > h[j].data.RedoRow.Row.StartTs {
return false

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

View check run for this annotation

Codecov / codecov/patch

cdc/redo/reader/reader.go#L371

Added line #L371 was not covered by tests
} else {
// in the same txn, we need to sort by delete/update/insert order
if h[i].data.RedoRow.Row.ToRowChangedEvent().IsDelete() {
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 379 in cdc/redo/reader/reader.go

View check run for this annotation

Codecov / codecov/patch

cdc/redo/reader/reader.go#L379

Added line #L379 was not covered by tests
}
}

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

Expand Down
Loading
Loading