Skip to content

[stable-2.46] Sync uploads incrementally to avoid fsync freezes - #743

Merged
rhafer merged 1 commit into
opencloud-eu:stable-2.46from
rhafer:stable-2.46-backport
Jul 27, 2026
Merged

rhafer merged 1 commit into
opencloud-eu:stable-2.46from
rhafer:stable-2.46-backport

Conversation

@rhafer

@rhafer rhafer commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

Fixes opencloud-eu/opencloud#3027 for stable-2.46

Backports #720

Sync uploads incrementally to avoid fsync freezes

(cherry picked from commit 9db0ec1)
@rhafer
rhafer requested a review from Copilot July 24, 2026 10:28
@rhafer rhafer changed the title Merge pull request #720 from aduffeck/improve-uploads [stable-2.46] Sync uploads incrementally to avoid fsync freezes Jul 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
@rhafer
rhafer requested review from aduffeck and micbar July 24, 2026 10:43
@rhafer
rhafer merged commit 4314250 into opencloud-eu:stable-2.46 Jul 27, 2026
19 of 20 checks passed
@openclouders openclouders mentioned this pull request Jul 27, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants