lab4 трек 2: reconciler S3/PostgreSQL, тесты вложений, отказов и согласованности

- python -m messenger.reconcile: merge-join листинга S3 и attachments по object_key;
  dry-run read-only конструктивно (default_transaction_read_only + S3 без записи),
  --apply: orphan/stale intent удаляются, ready-строки только в карантин (обратимо),
  перепроверка под FOR UPDATE, предохранитель от массового удаления;
- attachment_ids хранится в строке сообщения (история остаётся одним index range scan),
  message_attachments — для FK и обратного поиска;
- семафор полной проверки изображений (IMAGE_VERIFY_CONCURRENCY);
- тесты: вложения (56), отказ/пауза S3 и деградированный режим LB, failover загрузки,
  приватность bucket, FAULT_POINTS после PUT/после COMMIT, janitor, reconciler;
- бенчмарки памяти загрузок и стоимости обхода reconciler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alexey Bodanyuk
2026-10-25 14:05:03 +03:00
co-authored by Claude Opus 5.5
parent 335df4b2b2
commit a2d867bec6
22 changed files with 1943 additions and 36 deletions
+4 -3
View File
@@ -227,7 +227,7 @@ def declared_length(request: Request, limit: int) -> int | None:
return length
async def read_image(reader: BodyReader, settings: Settings, declared: str) -> Upload:
async def read_image(reader: BodyReader, settings: Settings, declared: str, verify_slots: asyncio.Semaphore) -> Upload:
"""Body -> verified image. Memory: at most MAX_UPLOAD_BYTES per upload (bytearray); the format
and the pixel count are known after the first bytes, so a picture that is too big or not a
PNG/JPEG is rejected without reading/decoding the rest."""
@@ -260,8 +260,9 @@ async def read_image(reader: BodyReader, settings: Settings, declared: str) -> U
data = bytes(buffer)
del buffer
try:
await images.verify(data, info, timeout=settings.image_verify_timeout_seconds,
jpeg_max_memory_mb=settings.jpeg_max_memory_mb)
async with verify_slots:
await images.verify(data, info, timeout=settings.image_verify_timeout_seconds,
jpeg_max_memory_mb=settings.jpeg_max_memory_mb)
except images.ImageError as exc:
raise _image_error(exc) from None
except asyncio.TimeoutError: