Repository navigation
fix(fs): preserve localFileInodes invariants on failed local file upload - #5277
saisagar1998 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors error handling and cleanup logic for local files in the filesystem, particularly when sync or flush operations fail. It ensures that local file inodes are correctly unlinked and removed from localFileInodes only if they match the active inode, preventing accidental eviction of newer files with the same name. Additionally, new unit tests are added to verify that upload failures preserve filesystem invariants. As there are no review comments, no further feedback is provided.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5277 +/- ##
==========================================
+ Coverage 85.13% 85.48% +0.34%
==========================================
Files 181 181
Lines 19875 19879 +4
==========================================
+ Hits 16921 16993 +72
+ Misses 2953 2885 -68
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
When uploading a newly created local file fails in
flushFile,syncFile, orcreateLocalFile,fs.localFileInodescould become out of sync with the inode state:IsLocal() == true,IsUnlinked() == false) fromfs.localFileInodescausedcheckInvariantsForLocalFileInodes()to panic withlocalFileInodes mismatchunder--debug_invariants.delete(fs.localFileInodes, f.Name())calls could evict a newer local file inode with the same name.createLocalFile, errors increateStreamingWriteHandlerAndSyncOrTempWriterleft the minted inode infs.inodesand leaked the lock/lookup count in the defer.Changes:
flushFile: only unlink and remove fromfs.localFileInodeswhenf.IsLocal()is true, callingf.Unlink()underf's lock before takingfs.muand guarding deletion withif fs.localFileInodes[f.Name()] == f.syncFile: remove the unguardeddelete(fs.localFileInodes, f.Name())on error instead of callingf.Unlink(). Leaving the inode linked keeps invariants valid, preserves retryability for transientfsyncerrors, and ensures subsequentFlushFileonclosestill reports upload errors (such asESTALE) rather than returningnilfor an unlinked inode.promoteToGenerationBacked: guarddelete(fs.localFileInodes, name)withif fs.localFileInodes[name] == f.createLocalFile: on failure increateStreamingWriteHandlerAndSyncOrTempWriter, unlink, remove fromfs.localFileInodes, and dispose the minted inode viaunlockAndDecrementLookupCount; also ensurefs.mu.Unlock()always runs andchildis only locked/incremented whenerr == nil.Link to the issue in case of a bug fix.
Fixes #5272 (b/587595321)
Testing details
TestLocalFile_UploadFailurePreservesInvariants(staged_writes,streaming_writes,zonal_streaming_writes) ininternal/fs/fs_internal_test.gowithlocker.EnableInvariantsCheck().go test -race -v -count=1 ./internal/fs -run TestLocalFile_UploadFailurePreservesInvariants(pass)go test -count=1 ./internal/fs -run "TestStaleFileHandle|TestLocalFileTest"(pass)go vet ./internal/fs/...(pass)Any backward incompatible change? If so, please explain.
No.