Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shaohk could you add a bit more background in this comment on "why" writing the heartbeat causes us to
avoid lost data due to MySQL two-phase-commit
? That will be useful to those without contextThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to describe the scene:
When using semi-sync and setting
rpl_semi_sync_master_wait_point=AFTER_SYNC
, if an INSERT statement is being committed but blocks due to an unmet ack count, the data inserted by the transaction is not visible toReadMigrationRangeValues
, so the copy of the existing data in the table does not include the new row inserted by the transaction. However, the binlog event for the transaction is already written to the binlog, so theaddDMLEventsListener
only captures the binlog event after the transaction, and thus the transaction's binlog event is not captured, resulting in data loss.If you add a heartbeat, and the transaction commit blocks because the ack is not met, then the heartbeat will not be able to write, so the ReadMigrationRangeValues will not be run. When the heartbeat writes successfully, the
ReadMigrationRangeValues
will read the newly inserted data, thus Avoiding data loss due to the above problemThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fanduzi that's my understanding too 👍
I'm hoping we can add some of this context into the code-comment on line 392, so that this is easier to read for those without context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shaohk two more questions:
.ReadMigrationRangeValues()
func? The goal with the.Migrate()
func is to leave a lot of the details to other functionsChangeLogState
instead of the heartbeat?.WriteChangelogState()
in the applier is used for this. Perhaps a newChangeLogState
likeReadMigrationRangeValues
would work here 🤔. Example PRThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I just saw these messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timvaillancourt
Use changelog state instead of the heartbeat PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fanduzi
Thanks, I added your description to the code comments. #1141