Commit 0c2b3f8
feat(BA-6155): add metadata-driven chunk-store upload session engine
Introduce the concurrency-safe upload session engine that replaces the
single-file-append TUS model. Each chunk is written to its own file under
chunks/, named by absolute byte offset; info.json is the source of truth,
updated only via atomic rename under a short fcntl.flock window. Heavy chunk
payload writes happen lock-free in per-request temp files, so multiple Storage
Proxy replicas sharing an NFS mount can upload concurrently without the TOCTOU
corruption of the stat-check-then-append model.
This commit combines what were previously two stacked PRs — the pure session
state model and the on-disk storage class — into a single cohesive unit. They
both live in tus_session.py and the model has no consumer on its own, so
splitting them across PRs hurt reviewability rather than helping it.
Contents:
- errors/upload.py: ChunkConflictError (409), UploadSessionCorruptedError (500)
- services/upload/tus_session.py:
- ChunkRecord / SessionState (committed_offset as the largest contiguous
prefix, missing_ranges, progress_percent, find_at_offset) / ChunkAcceptance
- TusUploadSession: ensure_initialized, read_state, open_temp_chunk,
commit_chunk (idempotent on duplicate (offset,length,sha256), 409 on
conflict, no-op on already-completed), assemble, cleanup
- stream_chunk_to_temp: bounded-memory streaming + sha256
- cleanup() keeps the completed info.json marker and reclaims only chunk files
under the lock, so a late duplicate PATCH that raced completion on another
replica observes status=="completed" and no-ops instead of crashing on a
vanished temp/target (surfaced by the real-NFS multi-proxy reproduction).
- Unit tests for both the model and the on-disk/concurrency behavior.
Supersedes the separate state-model change (was BA-6154).
Resolves BA-6155.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent e035f55 commit 0c2b3f8
9 files changed
Lines changed: 1080 additions & 0 deletions
File tree
- changes
- src/ai/backend/storage
- errors
- services/upload
- tests/unit/storage/services/upload
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
| |||
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
93 | 100 | | |
94 | 101 | | |
95 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments