Repository navigation
Conversation
Create truncated the target and wrote it in place, so a reader that loaded the .fileIndex while the writer saved it could get a partial file (unexpected EOF), and a process exiting mid-save left the index truncated for good. Seen in production: a 380 KB ethlog index cut to its first 40k of 76k entries. The local FS now writes to a hidden temporary file in the same directory and Close syncs it and renames it over the target, so readers see the old or the new file, never part of one. A failed write is discarded and the previous file kept. Other file systems are unchanged; GCS uploads are already atomic. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.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.
Problem
LocalFS.Create(go-storage's local FS) truncates the target and writes it in place. For files rewritten in place, most importantly the.fileIndex:failed to load file index: unexpected EOF.Change
storage/local.LocalFSnow implementsCreateitself:.<name>.tmp-*.Closesyncs that file and renames it over the target. Readers see the previous file or the complete new one, never part of one. A crash leaves the previous file intact.Writefailed,Closeremoves the temporary file, keeps the previous one and returns the error.os.Creategives them under the usual umask, andWriterOptionsmod/creation times are still applied.Only the local FS changes. GCS uploads are already atomic.
Tests
TestFileIndex_ConcurrentSaveAndLoad: saves a 20k-entry index 30 times while another goroutine loads it. Onmasterit fails withunexpected EOFwithin milliseconds; with this change it passes.storage/localunit tests:Close;Close;go test ./...passes.🤖 Generated with Claude Code