Repository navigation
[stable-2.46] Sync uploads incrementally to avoid fsync freezes - #743
Merged
Merged
Conversation
Sync uploads incrementally to avoid fsync freezes (cherry picked from commit 9db0ec1)
There was a problem hiding this comment.
Pull request overview
This PR backports improvements to upload persistence by syncing data incrementally during uploads and by optimizing blobstore ingestion to avoid large end-of-upload sync stalls.
Changes:
- Sync each received upload chunk to disk (fdatasync/fsync depending on platform) to improve resumability and reduce large fsync spikes.
- Update the POSIX blobstore upload path to prefer
os.Rename(with EXDEV fallback to copy) and add periodic syncing during copy operations. - Add tests and a test-only seam to force the copy-fallback upload path.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/storage/pkg/decomposedfs/upload/upload.go | Adds per-chunk fdatasync in the decomposedfs upload write path. |
| pkg/storage/pkg/decomposedfs/disk/disk_unix.go | Introduces platform-specific fdatasync wrapper for darwin/freebsd via File.Sync(). |
| pkg/storage/pkg/decomposedfs/disk/disk_linux.go | Introduces Linux fdatasync wrapper via syscall.Fdatasync. |
| pkg/storage/pkg/decomposedfs/disk/disk_fallback.go | Adds a non-linux/freebsd/darwin fallback implementation of fdatasync. |
| pkg/storage/fs/posix/blobstore/blobstore.go | Reworks blobstore Upload to try rename first, add periodic syncing during copy, and introduces helper copyWithPeriodicSync. |
| pkg/storage/fs/posix/blobstore/export_test.go | Adds a test-only setter seam to force the copy-fallback path. |
| pkg/storage/fs/posix/blobstore/blobstore_copy_fallback_test.go | Adds test coverage for the copy-fallback upload path (including >16MiB case). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
156
to
160
| // also "upload" the file to a local path, e.g., for keeping the "current" version of the file | ||
| if err := os.MkdirAll(filepath.Dir(copyTarget), 0700); err != nil { | ||
| return err | ||
| sourceFile, err := os.Open(source) | ||
| if err != nil { | ||
| return errors.Wrapf(err, "could not open source file '%s' for reading", source) | ||
| } |
Comment on lines
+92
to
96
| tempFile, err := os.OpenFile(tempName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600) | ||
| if err != nil { | ||
| return fmt.Errorf("unable to create temp file '%s': %v", tempName, err) | ||
| } | ||
|
|
Comment on lines
+206
to
+209
| if err == io.EOF { | ||
| _ = dst.Sync() | ||
| return nil | ||
| } |
Comment on lines
+10
to
+12
| func Fdatasync(f *os.File) error { | ||
| return nil | ||
| } |
Comment on lines
+70
to
+83
| if bs.canUseRenameForUpload { | ||
| err := os.Rename(source, tempName) | ||
| switch { | ||
| case err == nil: | ||
| // continue | ||
| case errors.Is(err, syscall.EXDEV): | ||
| // the upload and target file are on different devices, we need to copy the file instead of renaming it | ||
| bs.canUseRenameForUpload = false | ||
| default: | ||
| return fmt.Errorf("failed to move source file '%s' to temp file '%s' - %v", source, tempName, err) | ||
| } | ||
| } | ||
| defer func() { | ||
| _ = sourceFile.Close() | ||
| }() | ||
|
|
||
| tempFile, err := os.OpenFile(tempName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600) | ||
| if err != nil { | ||
| return fmt.Errorf("unable to create temp file '%s': %v", tempName, err) | ||
| } | ||
| if !bs.canUseRenameForUpload { |
Comment on lines
74
to
+78
| defer func() { | ||
| // sync the written chunk to disk. This ensures that the upload can be resumed, | ||
| // and helps to prevent issues with filesystem/journal freezes at the end of the upload | ||
| // when committing a large fsync operation on slow disks. | ||
| _ = disk.Fdatasync(file) |
micbar
approved these changes
Jul 24, 2026
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.
Fixes opencloud-eu/opencloud#3027 for stable-2.46
Backports #720