Bound per-cycle binlog purge to avoid LOCK_index write stalls#239
Merged
Conversation
Reducing binlog_retention_period on a write-heavy service made the next
60s purge tick collect the entire newly-eligible backlog and issue one
PURGE BINARY LOGS over all of it. MySQL runs that under LOCK_index, which
every committing transaction also needs, so a large backlog stalls all
writes for the full purge duration (hours / >1 TB).
Cap each purge cycle by file count and total bytes so a large backlog
drains as many small purges across successive ticks instead of one long
stall. The cap trims the tail of the already-computed contiguous
oldest-first prefix, so all existing safety semantics (stream safety,
min_binlog_age_before_purge, replication state, no-GTID handling) are
preserved. At least one file is always purged to guarantee progress.
Also emit myhoard.binlog.purged_per_cycle.{files,bytes} so the cap can be
verified.
vladislav-manafov-aiven
force-pushed
the
cap-per-cycle-binlog-purge
branch
from
June 29, 2026 07:53
5fa1d71 to
b641965
Compare
alexole
reviewed
Jul 1, 2026
alexole
reviewed
Jul 1, 2026
alexole
reviewed
Jul 6, 2026
alexole
approved these changes
Jul 6, 2026
Contributor
|
Please create a follow up to reduce interval when throttled to 1 second or even less, otherwise the rate of binlogs generation might be higher then removing and there is a risk of filling up the disk. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reducing binlog_retention_period on a write-heavy service made the next 60s purge tick collect the entire newly-eligible backlog and issue one PURGE BINARY LOGS over all of it. MySQL runs that under LOCK_index, which every committing transaction also needs, so a large backlog stalls all writes for the full purge duration (hours / >1 TB).
Cap each purge cycle by file count and total bytes so a large backlog drains as many small purges across successive ticks instead of one long stall. The cap trims the tail of the already-computed contiguous oldest-first prefix, so all existing safety semantics (stream safety, min_binlog_age_before_purge, replication state, no-GTID handling) are preserved. At least one file is always purged to guarantee progress.
Also emit myhoard.binlog.purged_per_cycle.{files,bytes} so the cap can be verified.