Skip to content

Conversation

@Lyndon-Li
Copy link
Contributor

@Lyndon-Li Lyndon-Li commented Sep 16, 2025

The file restore is using buffered IO, so after the restore completes, file data are actually written to the system cache, there is no guarantee all data have been flushed to disk. The flush may happen some time later according to the system cache's own data management policy.
On the other hand, users may restore data to a "removable disk", e.g., a virtual disk or a USB disk.

As a result, if users remove the disk immediately after the restore (e.g., detach the virtual disk from the hypervisor), the restore data may be lost.

This PR adds a flush call (f.Sync) for each file after the restore.

The flush may take some time because it waits for the kernel to completes the flush IO. So for large amount of files, the throughput may get affected.
However, I think for a restore tool, it is always correct to make sure the data is unconditionally restored to the disk. So the overhead is something ought to spend.
So I don't make this as a conditional call (e.g., adding a user option for it). Let me know if this affects other modules or scenarios.

Copy link
Collaborator

@julio-lopez julio-lopez left a comment

Choose a reason for hiding this comment

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

This cannot be the default behavior

@julio-lopez julio-lopez requested a review from Copilot October 17, 2025 02:55
Copy link

Copilot AI left a comment

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 ensures data durability during snapshot restoration by adding an explicit filesystem sync operation after each file is restored. This prevents potential data loss when users immediately detach removable storage after restoration completes.

Key changes:

  • Added f.Sync() call after file write operations to flush buffered data to disk before closing files

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Lyndon-Li Lyndon-Li marked this pull request as draft November 12, 2025 10:34
@Lyndon-Li Lyndon-Li changed the title feat(snapshot): Flush after restoring each file feat(snapshots): Flush after restoring each file Nov 12, 2025
@Lyndon-Li Lyndon-Li marked this pull request as ready for review November 12, 2025 11:41
@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.03%. Comparing base (cb455c6) to head (84f00c1).
⚠️ Report is 751 commits behind head on master.

Files with missing lines Patch % Lines
snapshot/restore/local_fs_output.go 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4825      +/-   ##
==========================================
+ Coverage   75.86%   78.03%   +2.16%     
==========================================
  Files         470      548      +78     
  Lines       37301    31417    -5884     
==========================================
- Hits        28299    24515    -3784     
+ Misses       7071     4851    -2220     
- Partials     1931     2051     +120     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@julio-lopez julio-lopez merged commit 157c80e into kopia:master Nov 13, 2025
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants