Реализовать лабораторную 4: вложения в S3 и согласованность с БД

- приватный bucket SeaweedFS за S3-шлюзом, отдельные identities
  admin/api/reconciler, анонимный доступ запрещён
- потоковый upload с проверкой PNG/JPEG (CRC, распаковка со сверкой
  объёма, лимит пикселей до распаковки) без буферизации тела
- скачивание через авторизованный API; компенсация неудачной загрузки:
  сначала pending-строка, затем объект
- reconciler БД ↔ S3 с grace period: stale_pending, orphan_object,
  missing_object, size/checksum mismatch, обратимый карантин lost
- сценарии отказов S3, замер памяти загрузок, трек 2, evidence и REPORT.md
This commit is contained in:
celis
2026-10-31 00:31:54 +03:00
parent ec540a1a72
commit 04458025fb
58 changed files with 4549 additions and 17 deletions
+2
View File
@@ -0,0 +1,2 @@
{"parallel": 64, "replicas_hit": 2, "created_201": 32, "conflict_409": 32, "stored_messages": 1}
PASS: concurrent same-key POSTs through different replicas created exactly one message
+9
View File
@@ -0,0 +1,9 @@
messenger-lab4-api-1 running 2026-10-30T20:33:48.383931772Z
messenger-lab4-api-2 running 2026-10-30T20:33:48.204468011Z
messenger-lab4-lb-1 running 2026-10-30T20:33:54.105385765Z
messenger-lab4-migrate-1 exited 2026-10-30T20:33:44.009406544Z
messenger-lab4-postgres-1 running 2026-10-30T20:33:07.96054489Z
messenger-lab4-reconciler-1 running 2026-10-30T20:33:48.18220747Z
messenger-lab4-s3-1 running 2026-10-30T20:33:41.342697511Z
messenger-lab4-s3-init-1 exited 2026-10-30T20:33:44.589053894Z
messenger-lab4-seaweedfs-1 running 2026-10-30T20:33:28.064407103Z
+9
View File
@@ -0,0 +1,9 @@
messenger-lab4-api-1 running 2026-10-30T20:32:53.600866465Z
messenger-lab4-api-2 running 2026-10-30T20:32:53.4130002Z
messenger-lab4-lb-1 running 2026-10-30T20:18:26.365040006Z
messenger-lab4-migrate-1 exited 2026-10-30T20:32:50.57728726Z
messenger-lab4-postgres-1 running 2026-10-30T20:17:38.382177837Z
messenger-lab4-reconciler-1 running 2026-10-30T20:32:53.406361682Z
messenger-lab4-s3-1 running 2026-10-30T20:18:11.781864672Z
messenger-lab4-s3-init-1 exited 2026-10-30T20:32:51.057882202Z
messenger-lab4-seaweedfs-1 running 2026-10-30T20:17:58.177043996Z
+37
View File
@@ -0,0 +1,37 @@
# 2026-10-30, ветка solution/bpi2303-moraru, Apple M3 Pro (11 ядер, 18 GiB) / OrbStack, LB_PORT=8094
# Финальный прогон после всех изменений (read_only rootfs, фоновая компенсация «строка → объект», таймауты S3).
$ npm run typecheck
> tsc
$ make check
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
$ make validate PYTHON=.venv/bin/python
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
$ make test BASE_URL=http://localhost:8094
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
$ python3 student-tests/idempotency_race.py --base-url http://localhost:8094 --parallel 64
{"parallel": 64, "replicas_hit": 2, "created_201": 32, "conflict_409": 32, "stored_messages": 1}
PASS: concurrent same-key POSTs through different replicas created exactly one message
$ make test-persistence ACTION_SCRIPT=scripts/restart.sh BASE_URL=http://localhost:8094
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
took 53 s
# StartedAt до/после: persistence-before.txt / persistence-after.txt — изменился у 9 из 9 контейнеров
# (lb, api-1, api-2, reconciler, postgres, seaweedfs, s3 и повторённые one-shot migrate, s3-init).
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh BASE_URL=http://localhost:8094
# между прогонами: docker compose start api; лишний curl /health/live сдвигает round-robin, чтобы целью стала другая реплика
run 1: {"observed_instances_before": 2, "successful_writes": 63, "failed_attempts": 0, "first_recovery_seconds": 6.217} PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. | messenger-lab4-api-1=running messenger-lab4-api-2=exited
run 2: {"observed_instances_before": 2, "successful_writes": 66, "failed_attempts": 0, "first_recovery_seconds": 4.659} PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. | messenger-lab4-api-1=exited messenger-lab4-api-2=running
run 3: {"observed_instances_before": 2, "successful_writes": 102, "failed_attempts": 0, "first_recovery_seconds": 3.903} PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. | messenger-lab4-api-1=running messenger-lab4-api-2=exited
# resilience.py (LAB>=4) загружает sample.png до отказа и после остановки реплики скачивает его через оставшуюся,
# сравнивая байты. Лог lb в момент отказа (api1…api8 — слоты server-template, их заполняет DNS, номер слота не равен
# номеру контейнера; на каждый отказ две записи: readiness 503 во время drain, затем отказ соединения после выхода):
lb-1 | Server api/api1 is DOWN, reason: Layer7 wrong status, code: 503, info: "Service Unavailable", check duration: 2ms. 1 active and 0 backup servers left. 1 sessions active, 0 requeued, 0 remainin
lb-1 | Server api/api1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in q
lb-1 | Server api/api2 is DOWN, reason: Layer7 wrong status, code: 503, info: "Service Unavailable", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remainin
lb-1 | Server api/api2 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in q
lb-1 | Server api/api1 is DOWN, reason: Layer7 wrong status, code: 503, info: "Service Unavailable", check duration: 7ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remainin
lb-1 | Server api/api1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 1ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in q