Repository navigation
fix: keep a plain write over a version its client never read - #176
Merged
Merged
Conversation
… served A write that states no precondition went through Backend::update, which extends whatever version is current when it lands, so a peer's edit that arrived after the client's read was superseded with no conflict copy. Backend::commit_edit commits against a stated base and leaves a failed precondition to the scope's conflicts policy (ScopedBackend runs commit_with_policy: fork keeps a copy, reject refuses). ServedVersions records the version a presenter served or wrote per path and writes a plain write through commit_edit against it, CreateIfAbsent when the client's listing lacked the path, and unconditionally only on a backend without committed versions. CommitOutcome moves beside Commit so the trait can name it.
A PUT with no If-Match now commits against the version the presenter last served for the path (a GET whose version held still across the fetch, or the presenter's own last write), so a peer's version that landed in between is forked or rejected by the scope's policy instead of being superseded. A PUT to a path the listing lacks creates only if absent. DELETE and MOVE forget the paths they take away. A PUT or MOVE also stamped the item with its backend-relative path, so a GET of the mount-prefixed path missed it until the listing was refreshed; both now stamp the mount-prefixed path as directory expansion does.
… presenter The HTTP API's PUT without If-Match, the FFI upload and the File Provider import wrote through Backend::update or upload, superseding a version another node wrote after the client's read with no conflict copy, as the WebDAV PUT did. Each now records the version it serves and writes through ServedVersions, so the scope's conflicts policy keeps or refuses such a write. The HTTP API keeps a record per bearer, answers a write a reject scope refuses with 409 Conflict rather than an If-Match failure, and names the conflict copy a forked write landed as.
…es in policy tests
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 #169
Fixes #170
A WebDAV
PUTwithoutIf-Matchwenthandle_put→ScopedBackend::update(awriters = anyscope with noblock_sizetakes the plain path) →P2pBackend::update→write_contentwith no check, which reads the row current at that moment and bumps its vector ("a peer row merged in between is extended rather than overwritten"). When the peer's concurrent row had already been merged on the writing node, the new row dominated it, somerge_oneon the peer took it as a successor and never loggedpreserving losing version as conflict copy: the peer's write was gone with no copy. #128 fixed this for writes that name a version (If-Match,commitwithReplaceIfVersion); a plain write named none.A write with no precondition is now committed against the version the client edited:
Backend::commit_editcommits against a stated base and hands a failed precondition to the scope'sconflictspolicy. Its default iscommit;ScopedBackendadmits the path as for any write and runscommit_with_policy, soforkkeeps a conflict copy andrejectrefuses withCommitError::Rejected.ServedVersions(engine,commit::served) records per backend and path the version a presenter served or wrote, andServedVersions::writecommits a plain write throughcommit_editagainst it. The base is the version last served or written there; with none,CreateIfAbsentwhen the client's listing lacked the path (so a file a peer created meanwhile is kept too), else the version current at the write (an unconditional overwrite, as before). A backend without committed versions is written unconditionally. A landed write becomes the base; a forked one leaves the base alone, since the client still has not seen what the path holds.GETwhose version held still across the fetch; the HTTP API, FFI and File Provider record the version read before the download (older than or equal to what was served, so the error direction is a spurious fork, never a lost write).CommitOutcomemoves fromcommit::policytocommitso the trait can name it.Write paths:
PUT(noIf-Match)update/upload: extends the current rowServedVersions::write, one record per path shared by the server's clients (no per-client handle in WebDAV);409in a reject scope;DELETE/MOVEforget the pathsPUTwithIf-Match/If-None-Match: *commit,412on a mismatchPUT(noIf-Match)metadatathenupdate/uploadServedVersions::writeper bearer; a reject scope answers409 Conflict; a fork returns the conflict copy's entryPUTwithIf-Matchcommit,412uploadmetadatathenupdate/uploadServedVersions::write, base recorded byread_fileimport_documentupdate(existing) orupload(new)ServedVersions::write, base recorded byfetch_contents; a new name is a create-if-absentWRITE/SETATTRrewrite: read version, patch the byte range into the current content,commit, retry onPreconditionFailedWRITEpositional patches merge at byte level rather than lose the whole write, but a save over a peer edit neither forks nor keeps either version whole; needs close-to-open buffering, tracked in #174EROFS(read-only)uploadof dirty files)uploadvfs::tree)uploadAlso fixed: a
PUTorMOVEstamped its item with the backend-relative path, so aGETof the mount-prefixed path on the writing daemon answered404until the sync runner re-added the item (#170). Both now stamp the mount-prefixed path, as directory expansion does.Tests (
crates/presenter-webdav/tests/plain_put_conflicts.rs, two P2P nodes from the backend-p2p harness behind real WebDAV servers andScopedBackend; the interleaving is ordered, never timed: B's client lists and GETsbase, A's edit is written and polled until B holds it, then B's clientPUTs):PUTover A's edit: both contents survive, one atdoc.txtand one conflict copy, identical on both nodes:policy conflicts=reject:409, A's edit stands, no copyPUTcreatingnew.txtafter A created it: both survivePUTs (two in a row with no read between, then one after reading A's later edit): no conflict copy; a read straight after the writer's ownPUTreturns itOn main (
ae5caf9, with only the test commits) the fork and create tests time out waiting for both contents to be held on both nodes, the reject test gets201instead of409, and the sequential test gets the404of #170. With the change all four pass.Two-host rerun of the issue's reproduction with this branch (release builds, one P2P backend per host, WebDAV on loopback, concurrent unconditional
PUTs overlapping in time): both writes survived, with identical trees and hashes on both hosts, in 10 of 10 trials, converging within about 2 s. Six trials were kept by thePUT's policy commit (a(name date).conflictcopy) and four by the P2P merge (a.conflict-<id>-<time>copy). The overwrite check (v1 reaches the peer, then v2 and v3 written straight after) served v3 on the peer in 20 of 20 trials with no conflict copy. The copy label is the backend name rather than the device's, which is #178.