When the ready commit fails after the object was written, the upload handler now locks the row, keeps it if it turned out ready, and otherwise deletes the object first and the pending row second before answering 503. A ready update that touches no row means the intent was already swept, so it fails as unavailable and the object goes too; a 201 without a row cannot happen. Every worker runs an UploadSweeper that every 30 s removes pending intents older than UPLOAD_GRACE_SECONDS (900 s, at least 60 s) one row at a time under FOR UPDATE SKIP LOCKED over the partial pending index, object first, and logs an audit event for each discard. Bodies are buffered only inside one of UPLOAD_CONCURRENCY slots per worker and released before the ready commit, and a client that disconnects in the middle of a body becomes a 400 instead of an unhandled 500. The tests run against a throwaway PostgreSQL: a trigger rejects the ready commit and the compensation leaves neither row nor object, a row removed during the write gives 503, a failed write stays until the grace ends, fresh intents and an aged ready attachment in a message survive a sweep, two concurrent sweeps share five intents exactly, the background loop runs by itself, a second upload waits for the slot without reading its body, and aborted and stalled bodies leave nothing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
3.8 KiB
3.8 KiB
1. Зона attachments: домен и приложение
- 1.1 Домен: событие
AttachmentDiscarded(reason),Attachment.discard(reason), ошибкаUploadAborted - 1.2 Порты: репозиторий
lock,next_abandoned,remove;UploadSlots; командаSweepAbandonedUploads - 1.3 Обработчики: запись под слотом, компенсация
discardпослеPUT, уборка по одной строке - 1.4 Проверка группы: unit-тест
discard,make lint
2. Зона attachments: инфраструктура, настройки и точки входа
- 2.1 Адаптер PostgreSQL:
FOR UPDATE,FOR UPDATE SKIP LOCKEDпо частичному индексу,DELETE … AND status='pending',UPDATE 0→Unavailable - 2.2 Настройки
UPLOAD_CONCURRENCY,UPLOAD_GRACE_SECONDS(≥ 60),UPLOAD_SWEEP_INTERVAL_SECONDS,UPLOAD_SWEEP_BATCH; провайдер dishka - 2.3 HTTP:
ClientDisconnect→UploadAborted(400); журналaudit.attachment_discarded - 2.4
UploadSweeperи его запуск/остановка в lifespanmain.py - 2.5 Платформа: откат транзакции не стирает события прежних транзакций команды, шина публикует их и при ошибке обработчика
- 2.6 Проверка группы: API-тесты против одноразового PostgreSQL — отказ
COMMITпослеPUT(компенсация), снятое намерение (503, объект удалён), сбойPUTи уборка после grace, свежее и готовое переживают проход, два прохода одновременно, фоновая уборка, ожидание слота, обрыв (400), зависшее тело (503, слот свободен)
3. Стенд
- 3.1
compose.yamlи.env.example: новые переменные зоны уapi - 3.2
scripts/s3-check.sh: консоль из сети стенда - 3.3 Проверка группы:
docker compose config --quiet,make up,make test
4. Проверки против стенда
- 4.1
student-tests/stack/test_attachment_faults.py: негативный suite через LB и журнал без500 - 4.2 Там же: отказ
COMMIT(триггер) → компенсация; падение реплики междуPUTиCOMMIT→ остаток виден, свежий переживает проход, старый убран; готовое вложение в сообщении переживает проход; обрыв и зависание тела - 4.3 Цель
make upload-faults, шаг CI - 4.4 Проверка группы:
make upload-faults,make s3-check
5. Замер памяти
- 5.1
scripts/lab4_seed.pyиз заготовки (memory.currentдо нагрузки),scripts/upload-memory.sh, цельmake upload-memory, ruff для скрипта - 5.2 Проверка группы: прогон 64/3 слота × 1/10 MiB × 10/20/40; выбор
UPLOAD_CONCURRENCYпо результату
6. Отчёт
- 6.1
evidence/:upload-faults.txt,upload-memory/,s3-security.txt,student-tests.txt - 6.2
REPORT.md: строки 4.1–4.4, механизм компенсации и уборки, эксперимент памяти, таблица отказов, ограничения - 6.3 Проверка группы:
make check,make lint,make student-test,make test,make test-persistence ACTION_SCRIPT=scripts/restart.sh,make test-failover ACTION_SCRIPT=scripts/stop-one.sh, сценарии уровня «3» иmake upload-faults