Repository navigation
Conversation
_sync_write truncated the state file in place and then wrote the new content with a single unchecked os.write and no fsync. A crash, a full disk or a short write between the truncate and the write left an empty or partially written file: the queue state was lost or undecodable, and a short write was even reported as success. Write to a temp file in the same directory, fsync it, os.replace() it over the state file, then fsync the directory. On any failure the temp file is removed and the previous state is untouched. Because the data file's inode now changes on every write, writers serialise on a sidecar <path>.lock file instead of on the data file, and reads need no lock. Old and new writers lock different files, so they must not run against the same state file at the same time.
This branch has not been deployed
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.
Stack 7/9, base #8.
The state file was truncated then rewritten in place, so a crash or short write lost the queue. Now writes a temp file, fsyncs, and
os.replace()s it; writers lock a sidecar<path>.lock. Old and new writers must not share a file.Tests:
test_short_write_leaves_previous_content_intact,test_failed_fsync_keeps_old_content_and_cleans_upfail on base;test_concurrent_writers_same_etag_exactly_one_wins,test_successful_write_leaves_no_temp_filespass on both.