Repository navigation
fix(fs): a direct overwrite reaches the live object only once its write is accepted - #4879
Merged
Merged
Conversation
…te is accepted A direct overwrite (`/fs/write`, `/fs/batchWrite`, WebDAV PUT, legacy `/up`) uploads under a key of its own, as a signed one already does. Once the storage check and every other item of its batch have passed, it checks that the entry is still at the path (cached row first, the primary when that doesn't match), copies its bytes onto the entry's key, and replaces only that row while the upload's own key is deleted. A refused or failed write leaves the file and its recorded size as they were and deletes its upload; an overwrite whose target moved or was deleted gets 409 `Upload target has moved` instead of creating a file at the path. - `batchCreateEntries` takes `replaceOnly`: update the row at the path holding that uuid, or 409, never insert or return another row. The UPDATE also matches the row's `path` as read (or a NULL path), and has to match a row. A row the replica hasn't seen yet is looked up on the primary by uuid. No UPDATE of the batch starts until every entry has passed its checks. Direct overwrites, signed overwrite completions and adopted raced creates use it. - If that row write fails after the bytes were moved (the file moved, was replaced or was deleted meanwhile), the row still holding the key records the new size, or with no row left the object is deleted. A batch-signed completion with one refused overwrite does the same for the ones already promoted. Sessions whose staged object was already promoted are marked failed; the rest stay pending and can be completed again. - Batch cleanup deletes overwrite uploads too, never the replaced file's own object, and keeps objects that rows of the same batch already point at. - Copies and deletes run at most 8 at a time.
Contributor
BenchmarksNo unaccepted regressions. 74 benchmarks: 0 regressed, 1 accepted, 0 improved, 0 new, 0 removed.
All benchmarks
|
Contributor
- When a write or batch fails after its rows may have been written, the cleanup reads the primary for rows holding the uploaded keys and keeps those objects. Some rows of a batch can be inserted before another is refused. If that read fails, nothing is deleted. - A new file whose path another writer took first is refused with 409 when that writer's row lives in another bucket or region, instead of copying into this upload's bucket and repointing the row. - `FSEntryStore.getEntriesByUuidsFromPrimary` reads rows by uuid on the primary; the batch insert read-back uses it.
…ettle Two overwrites of one file can copy onto its key in one order and write its row in the other, leaving the row with the other write's size. Each copy onto a file's key now schedules a check 10 s later. The check reads the row on the primary and the object's size, and when they differ, sets the row's size with an UPDATE conditional on the size it read. - `FSEntryStore.setSizeIfUnchanged(uuid, expected, size)`. - The check skips a row that has moved to another bucket or region, and logs instead of throwing.
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.
A direct overwrite (
/fs/write,/fs/batchWrite, WebDAV PUT, legacy/up) uploads under a key of its own, as a signed overwrite already does. Once the storage check and every other item of its batch have passed, it checks that the entry is still at the path, copies its bytes onto the entry's key, and replaces only that row while the upload's own key is deleted. A refused or failed write leaves the file and its recorded size as they were and deletes its upload.Changes
FSService.write()and the batch path (prepareBatchWrites/finalizePreparedBatchWrites) always upload under a fresh object key, and copy it onto the entry's key only after the write is accepted. The target check reads the cached row and goes to the primary only when that row isn't at the path; a row that moved since is refused by the replace itself. Copies and deletes run at most 8 at a time.batchCreateEntriestakesreplaceOnly: update the row at the path holding that uuid, or 409, and never insert or return another row.pathas read (or a NULL path), and has to match a row.FSEntryStore.getEntriesByUuidsFromPrimarydoes the read, and the batch insert read-back uses it too.FSEntryStore.setSizeIfUnchanged). Every write schedules its own check, so the check of the last write to land leaves the row matching its bytes.Behavior to be aware of
Upload target has moved/Write target changed mid-write) instead of creating a file at the original path.bench-accept: FSController.bench.ts > overwrite an existing file -- the upload is copied onto the file's key only once the write is accepted: one S3 copy and a cached target check (67 → 80 ms); the upload's own key is deleted alongside the row write
Testing
FSService.test.tsandFSEntryStore.test.tsfor each case above: refused and failed overwrites, targets moved, replaced or deleted mid-upload and mid-move, batch cleanup, stale and lagging replica reads, legacy rows, and signed batch session handling, cleanup after a partly written batch, raced creates in another bucket, and two overwrites whose copies and row writes land in opposite orders. The refused and moved-target overwrite tests fail on main, and the concurrent-overwrite test fails without the size check.npm run check.Supersedes #4852.