Skip to content

feat(platform): add durable writes, locks and file clones - #9

Merged
PiquelChips merged 1 commit into
mainfrom
feat/platform
Nov 4, 2026
Merged

PiquelChips merged 1 commit into
mainfrom
feat/platform

Conversation

@PiquelChips

Copy link
Copy Markdown
Member

Storage needs four things that work differently on each platform:

  • syncing data and directories to stable storage;
  • file locks the kernel releases when a process dies;
  • copy-on-write clones;
  • telling local file systems from network ones.

Without one place for this, cfgs would end up scattered everywhere.

crates/origin-platform puts each behind a trait: Durability, FileLock, CloneFile, FileSystem. Linux and macOS each get a module, and a single cfg_select! picks one by build target. That is the only place the code depends on the OS. A conformance suite runs against the native implementation, including a lock held by a child process that gets killed.

  • DurableWrite is the write sequence every later PR uses. Files are staged beside their destination without syncing. Then one batch sync covers them all: syncfs on Linux (or fdatasync for a single file), and fsync per file plus one F_FULLFSYNC on macOS. The files are then renamed into place from several threads, and each directory is synced once. A directory created by a batch has its parent synced at once, even if the batch is abandoned.
  • FileSystem::check_writable refuses network file systems (NFS, SMB, AFP, 9p…) with an error naming them. Dropbox and iCloud folders sit on local file systems, so they can't be detected this way.
  • No unsafe. System calls come from std, rustix and reflink-copy. rustix and reflink-copy were approved as dependencies.

Benchmarks: a 128-file batch takes 17 ms, against 390 ms when every file is synced, and an uncontended lock takes 3.3 µs.

Note

Written by Claude Opus 5.5 in Claude Code, reviewed by GPT-6.1 Sol and Claude Opus 5.5 over three review rounds (via T3 Code).

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ebb28c4f-fc1c-4c42-be60-20308492a9bf
Commits

Reviewing files that changed from the base of the PR and between 1132e4c and cb5fd31.

Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 16
  • AGENTS.md
  • Cargo.toml
  • README.md
  • crates/origin-platform/Cargo.toml
  • crates/origin-platform/benches/platform.rs
  • crates/origin-platform/src/clone.rs
  • crates/origin-platform/src/durability.rs
  • crates/origin-platform/src/error.rs
  • crates/origin-platform/src/file_system.rs
  • crates/origin-platform/src/lib.rs
  • crates/origin-platform/src/lock.rs
  • crates/origin-platform/src/native/linux.rs
  • crates/origin-platform/src/native/macos.rs
  • crates/origin-platform/src/native/mod.rs
  • crates/origin-platform/tests/conformance.rs
  • justfile
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@PiquelChips
PiquelChips added this pull request to stack #18 October 18, 2026 16:04
@PiquelChips PiquelChips self-assigned this Oct 18, 2026
@PiquelChips PiquelChips added the enhancement New feature or request label Oct 18, 2026
@PiquelChips PiquelChips added this to the 0.1 milestone Oct 18, 2026
@PiquelChips PiquelChips moved this from Needs Triage to In Progress in sourceorigin.dev Oct 18, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in sourceorigin.dev Oct 18, 2026
@PiquelChips PiquelChips added the area/platform origin-platform: durable writes, locks, clones, process groups label Oct 18, 2026
@PiquelChips PiquelChips moved this from In Progress to Ready in sourceorigin.dev Oct 18, 2026
@PiquelChips
PiquelChips force-pushed the feat/platform branch 3 times, most recently from d853f93 to 2a3f22d Compare November 2, 2026 23:34
@PiquelChips
PiquelChips removed this pull request from stack #18 November 4, 2026 18:00
@PiquelChips
PiquelChips added this pull request to stack #38 November 4, 2026 18:00
Base automatically changed from chore/workspace to main November 4, 2026 18:34
Storage needs four things the platforms do differently: syncing data and
directories to stable storage, file locks the kernel releases when a
process dies, copy-on-write clones, and telling local file systems from
network ones. origin-platform puts each behind a trait (Durability,
FileLock, CloneFile, FileSystem) with Linux and macOS modules, and a
single cfg_select! picks the module and the Native alias for the build
target. A conformance suite runs against Native, including a lock held by
a child process that is killed.

DurableWrite is the write sequence the store will use: each file is
written under a temporary name beside its destination without syncing,
then a commit makes the whole batch durable with one
Durability::sync_batch, renames the group into place from several
threads and syncs each directory involved once. Staging beside the
destination keeps renames into different directories from contending on
one shared temporary directory, and DurableWrite::is_temporary lets
readers skip, and clean up, the `.tmp-` files a crash leaves behind. On Linux the batch is
one syncfs (a lone file is fdatasync'd, which is cheaper); on macOS it is
a plain fsync per file and a single F_FULLFSYNC, as SQLite does. A
128-file batch drops from about 390 ms to 17 ms.

FileSystem classifies the file system holding a path with statfs, and
check_writable refuses network ones (NFS, SMB, AFP, 9p, ...) with an error
naming them. Dropbox and iCloud folders sit on local file systems and
can't be detected this way.
@PiquelChips
PiquelChips merged commit a0064c6 into main Nov 4, 2026
12 of 21 checks passed
@PiquelChips
PiquelChips deleted the feat/platform branch November 4, 2026 19:32
@github-project-automation github-project-automation Bot moved this from Ready to Done in sourceorigin.dev Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/platform origin-platform: durable writes, locks, clones, process groups enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant