feat: harden attachment storage for level 4

This commit is contained in:
EgorAnti
2026-11-11 21:20:45 +03:00
parent e06678b6a9
commit 90a689661b
27 changed files with 650 additions and 14 deletions
+39 -3
View File
@@ -12,10 +12,11 @@
## Проверки
```text
AttachmentServiceTest: BUILD SUCCESSFUL, 6 tests.
AttachmentServiceTest + AttachmentReconcilerTest: BUILD SUCCESSFUL, 10 tests.
tests/smoke.py: PASS: lab4 public API scenario.
student_tests/lab4_negative.py:
PASS: foreign chat/user, MIME spoof, corruption, byte limit and filename checks.
PASS: unknown/foreign attachment, foreign chat/user, MIME spoof, corruption,
byte limit and filename checks.
```
Persistence hook останавливал nginx, обе API, Redis, PostgreSQL и MinIO, затем запускал те же named volumes и повторял idempotent bucket bootstrap:
@@ -27,7 +28,7 @@ PASS: persistence preserved confirmed data and existing session.
Failover hook остановил replica из `X-Instance-Id`, обслужившую тестовый запрос:
```json
{"observed_instances_before":2,"successful_writes":105,"failed_attempts":0,"first_recovery_seconds":1.636}
{"observed_instances_before":2,"successful_writes":102,"failed_attempts":0,"first_recovery_seconds":1.386}
```
```text
@@ -41,3 +42,38 @@ PASS: unavailable S3 returns contract JSON 503
```
После запуска того же MinIO volume публичный smoke повторно завершился PASS, checksum скачанного original совпал.
## Level 4: consistency, memory and private S3
Unit tests inject an interrupted request stream before S3 PUT and a repository
failure after S3 PUT. The first leaves storage empty; the second verifies the
compensating DELETE. Reconciler tests prove that an orphan younger than the
one-hour grace period survives, an older orphan is deleted, dry-run never
deletes, and a missing object is reported.
Bootstrap was executed again against the existing bucket and completed with
exit code 0. The direct S3 probe (without application API) produced:
```text
PASS: bucket is private and API credentials are non-admin
```
Full Gradle suite using the live Compose PostgreSQL/Redis/MinIO network:
```text
BUILD SUCCESSFUL in 11m 47s
```
Concurrent memory experiment (`evidence/upload-memory-2026-11-11.json`):
```json
{"concurrency":12,"successful_uploads":12,"payload_bytes_each":6835833,
"duration_seconds":10.156,"api_replicas":2,"memory_samples":5,
"baseline_api_memory_bytes":668467200,"peak_api_memory_bytes":839909375,
"peak_increase_bytes":171442175,"configured_max_concurrent_uploads_per_replica":3}
```
The memory values are the aggregate of both API containers from `docker stats`.
Sampling can miss a shorter peak, so this is an operational bound observation,
not a JVM heap proof. The code-level bounds are 10 MiB/request, 40M pixels and
three active uploads per replica.
+14
View File
@@ -0,0 +1,14 @@
{
"concurrency": 12,
"successful_uploads": 12,
"payload_bytes_each": 6835833,
"duration_seconds": 10.156,
"api_replicas": 2,
"memory_samples": 5,
"baseline_api_memory_bytes": 668467200,
"peak_api_memory_bytes": 839909375,
"peak_increase_bytes": 171442175,
"configured_max_concurrent_uploads_per_replica": 3,
"configured_max_upload_bytes": 10485760,
"configured_max_image_pixels": 40000000
}