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.
Summary
This PR addresses an issue where acknowledgments (ACKs) were sometimes sent to the master before binlog events were fully written and fsynced to disk during backup operations. Sending ACKs prematurely in semi-synchronous replication could lead to data loss if the replica fails after sending the ACK but before persisting the event.
ACK after backup
Event handling
EventHandler
interface with aHandleEvent
method for processing binlog events. This allows custom event handling logic to be injected into the replication streameventHandler
field andSetEventHandler
method toBinlogSyncer
.BackupEventHandler
which writes binlog events to disk and ensures that each event is fsynced before returning. This ensures data durability before ACKs are sent.Separating parsing from handling
onStream
method inBinlogSyncer
to separate event parsing (parseEvent
) from event handling and ACK sending (handleEventAndACK
). This adheres to the single-responsibility principle and makes the code cleanerb.nextPos
) and GTIDSet handling fromparseEvent
tohandleEventAndACK
to avoid side effects during parsing. Something calledparseEvent
should only be parsing, not modifying state or sending ACKs.Testing
Three new tests:
TestGTIDSetHandling
- This confirms the continued functionality of the existing GTIDSet logic after it was involved in a refactorTestACKSentAfterFsync
- This confirms that ACKs are only send after the backup files are fsyncedTestBackupEventHandlerInvocation
- This confirms that the (new) EventHandler works as expected