Skip to content

feat(fs): coordinate shared-root version mutations and null recovery - #1660

Merged
overtrue merged 1 commit into
mainfrom
p3/1537-shared-root-version-lock
Nov 27, 2026
Merged

overtrue merged 1 commit into
mainfrom
p3/1537-shared-root-version-lock

Conversation

@overtrue

Copy link
Copy Markdown
Collaborator

Summary

Coordinate all version, bucket, metadata, tagging, ACL, lifecycle, and multipart-completion mutations targeting the same canonical FsBackend root across both same-process instances and cooperating OS processes, and close duplicate-null resurrection and post-rename multipart completion gaps ahead of durable Object Lock (#1512). All public Object Lock 501 NotImplemented refusals remain intact.

Key changes (21 files strictly under crates/fs/, 0 Protected Files):

  • crates/fs/src/root_lock.rs: Process-wide canonical-path tokio::sync::RwLock registry with dead-weak pruning plus fail-closed OS advisory locking (std::fs::File::try_lock / try_lock_shared) on <canonical-root>/.version-lock (rejecting symlinks/non-files with 400 InvalidRequest and validating Unix (dev, ino)), uncontended fast path, bounded Duration-budget spawn_blocking retry with CancelAcquireOnDrop, RootVersionGuard::run_blocking retaining both locks across critical FS mutations if the async caller drops, and lock_shared() for CreateMultipartUpload (crates/fs/src/lib.rs) so concurrent initiations overlap while strictly excluding CreateBucket/DeleteBucket and version mutations.
  • crates/fs/src/versioning/null_recovery.rs & crates/fs/src/versioning/publish.rs: Durable supersedes-null intent staged inside .tmp-* before atomic rename; staging::create_and_write_file flush-before-rename on BODY_FILE, TAGS_FILE, and RECORD_FILE; commit_staged_version renaming atomically, marking CompletionTombstoneGuard::mark_published() immediately, rechecking lock_record::ensure_deletable, and retiring superseded null directories and legacy plain files; reconcile_null_records_for_key and reconcile_all_null_records deterministically reconciling duplicate-null keys and single-null supersedes-null intents while failing closed on equal sequences, active protection (403 AccessDenied), symlinks (400 InvalidRequest), or removal failure (500 InternalError); and explicit_for_key selecting the highest-sequence record via .max_by_key(|r| r.sequence).
  • crates/fs/src/completion.rs, completion_replay.rs, lifecycle.rs, versioning.rs, reads.rs, buckets.rs, tagging.rs, acl.rs, version_listing.rs, README.md, MAP.md: Single-owner shared-root lock across multipart completion (upload -> .complete-* -> publish_object_if_locked -> tombstone teardown), best-effort staged completion receipt written before rename, .version-lock regular-file skip + symlink/dir fail-closed in lifecycle_buckets(), and updated coordination/crash-boundary documentation.
  • Tests (crates/fs/src/versioning/shared_root_tests.rs, crates/fs/tests/crud/shared_root.rs, null_recovery.rs, root_lock.rs): 18 negative + 2 positive unit and real cross-process current_exe() controls covering shared-root mutex/OS lock exclusion, shared/exclusive two-directional OS locking, symlink/dir fail-closed, queued & started cancellation safety, single- and duplicate-null recovery without resurrection, post-rename multipart receipt & tombstone durability, and preserved Object Lock 501 refusals.

Closes #1537

Verification

$ cargo fmt --all --check
(exit 0)

$ # CI static-guard loop (all non-REQUIRES-PR / non-REQUIRES-BUILD scripts/check_*.sh)
CI_STATIC_GUARDS_RAN=144 FAILED=0

$ GATEWAY_PROTECTED_BASE=origin/main GATEWAY_PROTECTED_HEAD=HEAD GATEWAY_PR_BODY_JSON='""' bash scripts/check_protected_files.sh
check_protected_files: no protected contract change

$ cargo clippy --offline --workspace --all-targets -- -D warnings
    Finished `dev` profile [unoptimized] target(s) in 3m 06s

$ RUSTDOCFLAGS="-D warnings" cargo doc --offline -p rustfs-gateway-fs --no-deps
    Finished `dev` profile [unoptimized] target(s) in 20.37s

$ cargo test --offline -p rustfs-gateway-fs --features external-payload --quiet
test result: ok. 129 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 507 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

$ cargo test --offline --workspace --quiet
=== WORKSPACE_TESTS_OK ===

$ cargo xtask verify --crate rustfs-gateway-fs
verify: crate rustfs-gateway-fs build compiled 11 crate(s) in 26.29s outside the budget
verify: crate rustfs-gateway-fs passed in 29.37s

Mutation Proofs (all intentionally broken, confirmed RED, and restored)

  • M1: Disabled OS try_lock in crates/fs/src/root_lock.rs -> cross-process shared_root controls and n_started_blocking_mutation_retains_os_lock_until_completion_after_future_drop failed RED.
  • M2: Disabled canonical-root registry reuse in RootVersionLock::for_canonical_root -> same-process canonical/symlink alias lock-sharing tests failed RED.
  • M3: Removed symlink_metadata check in open_safe_lock_file -> n_malformed_version_lock_symlink_and_directory_fail_closed failed RED.
  • M4: Disabled reconcile_null_records_for_key while keeping explicit_for_key max-sequence sorting -> duplicate-null reconciliation and non-resurrection tests failed RED.
  • M5: Dropped .tmp-* skip in version_records -> staging visibility / cancellation controls failed RED.
  • M6a: Dropped write_staged_completion_receipt in stage_version -> post-rename multipart replay test failed RED.
  • M6b: Deferred tombstone_guard.mark_published() past superseded-null cleanup in commit_staged_version -> post-rename upload non-resurrection test failed RED.
  • M7: Dropped || has_supersedes_null_intent(&record.path)? in reconcile_all_null_records -> n_listing_reconciles_single_null_supersedes_intent_and_refuses_symlink_intent failed RED (listing reconciliation must remove superseded legacy plain file).
  • M8: Stubbed lock_shared to exclusive lock() (concurrent shared lock failed RED) and bypassed OS try_lock_shared in LockMode::Shared (shared lock must fail closed while an external OS exclusive lock is held failed RED).

Role Verdicts

  • simplicity-adversary: attacked shared-root RwLock/OS flock coordinator (crates/fs/src/root_lock.rs), duplicate-null recovery (versioning/null_recovery.rs), staged publish/commit (versioning/publish.rs), and multipart replay (completion.rs, completion_replay.rs) — no break found
  • concurrency-durability: attacked cross-instance and cross-process .version-lock exclusion, shared/exclusive lock ordering, queued and started cancellation safety, create_and_write_file flush-before-rename, and single/duplicate-null recovery without resurrection — no break found

Breaking Change

  • BREAKING — this PR touches a protected file or changes a public contract.

Checklist

  • The four-command gate passed (fmt, clippy, test, cargo xtask verify)
  • New or changed public API has rustdoc
  • Negative test cases outnumber positive ones
  • Every new assertion was mutated — the implementation was broken on purpose and the assertion
    went red. The PR description names which ones
  • No Protected File touched; if one was, the PR description contains BREAKING and a migration path
  • No unsafe introduced
  • No inventory / linkme introduced
  • No #[non_exhaustive] added to a DTO
  • No s3s code copied; behavioural evidence is URL + self-written summary
  • No credentials, signatures, or expected-signature values reachable from logs or error bodies
  • No plan document, analysis report, or working note committed
  • Commits follow Conventional Commits; PR title ≤72 characters
  • A Handoff comment has been appended to the issue

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.

fs: coordinate shared-root version mutations before Object Lock

1 participant