Repository navigation
Conversation
When the AOF buffer is empty, flushAppendOnlyFile() publishes primary_repl_offset as fsynced so that WAITAOF doesn't hang on offsets that only reached replicas (RM_Call with NO_AOF). It did that whenever no fsync was visibly in progress, without checking that the AOF had been fsynced at all. Under appendfsync everysec a write that lands between two fsyncs was acknowledged by WAITAOF 1 0 on the next event loop iteration, up to a second before it reached the disk. The same happened while a background fsync was still running, since aof_last_incr_fsync_offset advances when the fsync is requested, and while the fsync of the previous INCR file queued by an AOF rewrite was still running. Only publish the offset when everything written has had an fsync requested and no AOF fsync job is pending. The jobs publish the offset themselves when they complete. Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
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.
Under
appendfsync everysec,WAITAOF 1 0can acknowledge a write up to a second before it is fsynced. When the AOF buffer is empty,flushAppendOnlyFile()publishesprimary_repl_offsetas fsynced (added in Redis #12622 so WAITAOF doesn't hang on NO_AOF module writes), but its only guard is async_in_progressflag that is usually never computed on that path. This only publishes the offset when every written byte has had an fsync requested and no AOF fsync job is still running.AI generated details
Problem
src/aof.c:1189-1217. With an emptyaof_buf, the first branch evaluatessync_in_progress = aofFsyncInProgress()only afteraof_last_incr_fsync_offset != aof_last_incr_sizeandmstime - aof_last_fsync >= 1000both hold. Otherwisesync_in_progressstays 0 and the else branch storesprimary_repl_offsetintofsynced_reploff_pending. Three ways that publishes data that is not on disk:aof_last_incr_fsync_offsetadvances at request time,aof.c:1394)fdatasyncreturnsbio.c:310). Manual run belowaof.c:831), old file'sBIO_CLOSE_AOFfsync still queuedappendfsync alwaystests/unit/moduleapi/usercall.tclpasses)The previous everysec tests missed it because
WAITAOF local copy everysecasserts{1 0}with timeout 0, which the bug satisfies early. Introduced by redis/redis#12622 (c2a4b7849), so every Valkey release is affected.Fix
Publish only when
aof_last_incr_fsync_offset == aof_last_incr_size, noBIO_AOF_FSYNCjob is pending, and noBIO_CLOSE_AOFjob is pending. The old!sync_in_progressterm is dropped: with the offset check it can only be 0 there.Behavior change:
WAITAOF 1 0under everysec now waits for the next real fsync, up to about a second, instead of returning on the next event loop. The existingWAITAOF local copy everysectest goes from about 0 ms to about 800 ms.Not changed here: when a background fsync fails, the job doesn't publish but still drains, so the next empty-buffer flush publishes anyway. That is the fdatasync EIO case in valkey-io#5571 / valkey-io#5572.
Alternative considered
Only the offset check (
aof_last_incr_fsync_offset == aof_last_incr_size). It fixes the first row but not the other two. Withfdatasyncslowed to 300 ms viaLD_PRELOAD, 30 x (SET;WAITAOF 1 0 5000) under everysec:With the offset check, e.g. the fsync ran
364718to365019and WAITAOF replied at364820. For the AOFRW row (SET;BGREWRITEAOF;WAITAOF 1 0 5000), without theBIO_CLOSE_AOFterm WAITAOF replied at498586while the old INCR file's fsync ran498585to498904; with it the reply waits for the fsync.Testing
The new test uses
no-appendfsync-on-rewrite yeswith a bgsave child, so no fsync can happen while it assertsWAITAOF 1 0 100times out. Without the fix, 5 of 5 runs:The in-flight and AOFRW rows have no automated test: they need an fsync slow enough to observe, and there is no debug knob for that. Without the fix the test only fails if the write lands within a second of the preceding fsync, which a slow runner (valgrind) may miss; with the fix it cannot pass by luck.
This was generated by AI but verified, with love, by a human.