Repository navigation
fix(fs): a direct overwrite reaches the live object only after its row is written - #4852
HanadHassan wants to merge 5 commits into
Conversation
Covers a direct overwrite whose row write errors, one whose parent folder moves away mid-upload, and the batch path, each asserting the previous content and object survive. A control asserts that a successful overwrite stages its upload at a key of its own and keeps the entry uuid.
…w is written Direct overwrites (/fs/write, /fs/batchWrite, WebDAV PUT, legacy /up) now upload to a key of their own, as signed overwrites already do. The step that adopts the live entry writes the row first and moves the uploaded object onto the live key only once that row lands. A write whose row can't be recorded drops its upload and leaves the previous file as it was. Batch cleanup removes uploads for overwrites too, never the live key.
- FSService: each overwrite in a write or batch lands its own row and then its own bytes, so one whose row can't be recorded leaves every other file whole. New files in the batch are created only once every overwrite has landed. - FSService: the row uuid and the upload key travel separately, so an overwrite updates its row in the one store call it made before. - FSService: an overwrite whose target file moved mid-upload answers 409 "Upload target has moved", as signed overwrites do, instead of writing onto the moved file. - FSService: batch cleanup deletes only the keys the batch uploaded. - Tests assert outcomes (each file whole, no upload left behind) for a failed row write, a folder or file moved mid-upload, and batches mixing a failed overwrite with other overwrites and new files.
The tests cover overwrites whose row can't be recorded or whose target moved; a copy that fails after the row lands is not covered, so the block no longer claims a file is never left half-written.
|
Holding off on merging this one: there's one bug to fix, and a few trade-offs to weigh. Overwriting an empty (touched) file can delete it. A file created with
If the copy fails outright, the file is deleted on its next read. Before this PR the bytes landed on the live key first, so there was no gap. Fix: when the existing entry has no stored object ( The row runs ahead of the bytes for the whole copy.
Cost. Every overwrite now does an extra copy plus an awaited delete of the staged key. Rows are written one at a time (8 in flight) instead of in one batch, and the user is billed two storage write ops instead of one. The staged-key delete could at least come off the request path. Smaller things
The PR already names the root fix: an object key separate from the uuid, so an overwrite becomes one row switch. That may be worth doing directly instead of this two-step version. If you keep this approach, the empty-file case has to be fixed first. |
|
Thanks for holding this. I checked each point. The touched-file deletion reproduces: a read during the copy 404s, the ghost handler removes the entry, and the write still answers 200. A failed copy leaves the row at the new size over the old bytes. The rest hold as you described. The Content-Length point is a bit worse than stated: a plain WebDAV GET also takes its length from the row, so a row out of step with the object truncates the download or leaves it hanging. The one nuance is the 409 on delete-and-recreate. The wording is wrong, but the refusal itself is what keeps the previous file intact (more below). I also tested whether staging is worth it at all, and I think it is. On main, when a file is moved to Trash during an upload and a new file is created at its name, the overwrite lands on the trashed file's object; the raced branch then copies that object onto the new file and deletes it, so the trashed file is gone on its next read. The same ordering lets an overwrite replace a file that moved out from under it mid-upload. Each case comes down to the bytes reaching the live key before the checks that can still refuse the write. So I'd rather do the root fix you pointed at than patch the two-step version. The shape I have in mind is a nullable If you'd rather keep the two-step approach, I'll apply your fixes here instead: copy before the row when there's no stored object, re-sync the row from the live object when the copy fails, take the staged-key delete off the request path, give staged keys a recognisable prefix with an expiry, emit the missing |
|
Closing in favour of #4879, which takes the same approach for direct overwrites and also covers the batch and signed-completion paths. Thanks for the PR. |
A direct overwrite (
/fs/write,/fs/batchWrite, WebDAVPUT, legacy/up) uploaded its bytes straight onto the live object key. If the row write failed afterwards, because the parent folder moved mid-upload or the database dropped the connection, the request answered with an error while the previous content was already gone.What changed
FSService#createUploadedEntries: a direct overwrite uploads to a key of its own. Each overwrite then writes its row under the live uuid and only then moves the upload onto the live key, one overwrite at a time. An overwrite whose row can't be recorded leaves its file, and every other file in the batch, whole.FSService#landOverwrite: if the target file itself moved mid-upload, the write answers409 Upload target has moved, as signed overwrites do, instead of writing onto the moved file.What it doesn't fix
An entry's object key is its uuid, so the row and the bytes still change in two steps.
Behavior to be aware of
updateThumbnailsblock comes from the pre-commit hook (eslint --fixwith the locked prettier), not from this change.bench-accept: overwrite an existing file -- a direct overwrite now stages its upload and copies it onto the live key after the row is written, so a failed save can't replace the previous version.
Testing
FSService.test.ts, upload edges, write limits, FS/legacy/WebDAV write and shared-folder suites: 618 tests); lint, type check and benchmarks left to CI.FSService.test.ts› "a direct overwrite that cannot land leaves every file whole": a failed row write, a folder moved mid-upload, a file moved mid-upload, a batch with one failed overwrite among others, and a batch mixing a failed overwrite with a new file each leave every file whole and no upload behind (fail without the fix withexpected 26 to be 11, no 409, or a leftover new file).