feat: two-store reconciler with safe repair and cost measurement (grade 5, track 2)

This commit is contained in:
2026-11-20 05:01:20 +03:00
parent 1c3011bf28
commit 60e8f4474b
36 changed files with 807 additions and 212 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
2026-11-20T04:20:26+03:00
2026-11-20T04:38:30+03:00
make check
python3 scripts/check_contract.py
+29 -35
View File
@@ -1,4 +1,4 @@
2026-11-20T04:14:17+03:00
2026-11-20T04:41:27+03:00
failure between S3 write and database commit: an object must not stay unaccounted
$ scripts/reconcile.sh # baseline
@@ -6,21 +6,19 @@ $ scripts/reconcile.sh # baseline
"prefix": "chats/",
"grace_seconds": 3600,
"dry_run": true,
"scanned_objects": 15,
"scanned_rows": 16,
"scanned_objects": 17,
"scanned_rows": 17,
"truncated": false,
"orphans": [],
"missing": [
{
"id": "97121cfe-6b29-4227-867f-3188e72a725c",
"object_key": "chats/9452049e-b86c-4d9a-8060-d98f6966b956/97121cfe-6b29-4227-867f-3188e72a725c",
"chat_id": "9452049e-b86c-4d9a-8060-d98f6966b956",
"created_at": "2026-11-20T01:11:14Z"
}
],
"missing": [],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"duration_ms": 8
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 7,
"objects_per_second": 2428.5714285714284
}
$ podman exec -i postgres psql < scripts/sql/inject-db-failure.sql
@@ -37,21 +35,19 @@ $ scripts/reconcile.sh # same object count: compensating DELETE removed the ob
"prefix": "chats/",
"grace_seconds": 3600,
"dry_run": true,
"scanned_objects": 15,
"scanned_rows": 16,
"scanned_objects": 17,
"scanned_rows": 17,
"truncated": false,
"orphans": [],
"missing": [
{
"id": "97121cfe-6b29-4227-867f-3188e72a725c",
"object_key": "chats/9452049e-b86c-4d9a-8060-d98f6966b956/97121cfe-6b29-4227-867f-3188e72a725c",
"chat_id": "9452049e-b86c-4d9a-8060-d98f6966b956",
"created_at": "2026-11-20T01:11:14Z"
}
],
"missing": [],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"duration_ms": 7
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 7,
"objects_per_second": 2428.5714285714284
}
$ podman exec -i postgres psql < scripts/sql/reset-db-failure.sql
@@ -60,26 +56,24 @@ DROP FUNCTION
$ scripts/upload-once.py --expect 201 # service healthy again
status=201
attachment=a6844b91-5b7b-4694-93fc-87d808b687fb size=653
attachment=7dd89013-32f1-4732-a2fd-529fe2081bb8 size=653
$ scripts/reconcile.sh # one more accounted object
{
"prefix": "chats/",
"grace_seconds": 3600,
"dry_run": true,
"scanned_objects": 16,
"scanned_rows": 17,
"scanned_objects": 18,
"scanned_rows": 18,
"truncated": false,
"orphans": [],
"missing": [
{
"id": "97121cfe-6b29-4227-867f-3188e72a725c",
"object_key": "chats/9452049e-b86c-4d9a-8060-d98f6966b956/97121cfe-6b29-4227-867f-3188e72a725c",
"chat_id": "9452049e-b86c-4d9a-8060-d98f6966b956",
"created_at": "2026-11-20T01:11:14Z"
}
],
"missing": [],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"duration_ms": 7
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 7,
"objects_per_second": 2571.4285714285716
}
+35
View File
@@ -0,0 +1,35 @@
2026-11-20T04:53:36+03:00
make test-contract
BASE_URL="http://localhost:8080" python3 scripts/contract-audit.py
ok: explicit attachment_ids=null is 400
ok: empty variant is 400
ok: whitespace-only filename is 400
ok: Content-Type parameters are accepted
ok: 41,000,000 pixels is 413
ok: text length bounds
ok: attachment count bounds
ok: duplicate attachment_ids is 400
ok: idempotent replay with the same set
ok: absent and empty attachment_ids agree
ok: attachment from another chat is 404
ok: unknown attachment id is 404
ok: outsider access is 404
ok: upload to unknown chat is 404
ok: media errors are 415
ok: oversize is 413
ok: filename errors are 400
ok: chat validation errors are 400
ok: pagination errors are 400
ok: idempotency errors
ok: null request fields are 400
ok: more than 100 members is 400
ok: user field validation
ok: missing Content-Type is 415
ok: variant is case sensitive
ok: filename control characters are 400
ok: chat title bounds
ok: cursor is bound to the endpoint
ok: 204 responses carry headers and no body
ok: download Content-Length matches the bytes
PASS: 30 checks
+1 -1
View File
@@ -1,4 +1,4 @@
2026-11-20T04:17:09+03:00
2026-11-20T04:43:58+03:00
separate restricted S3 credentials for the API and idempotent bucket bootstrap
$ podman-compose run --rm s3-init (first run)
+2 -2
View File
@@ -1,7 +1,7 @@
2026-11-20T04:18:05+03:00
2026-11-20T04:56:32+03:00
users | chats | messages | attachments | links | db_size
-------+-------+----------+-------------+-------+---------
58 | 17 | 303 | 30 | 2 | 8534 kB
125 | 43 | 634 | 101 | 56 | 8958 kB
(1 row)
+4 -4
View File
@@ -1,10 +1,10 @@
2026-11-20T04:18:05+03:00
2026-11-20T04:56:17+03:00
Linux archlinux 7.3.5-arch1-1 #1 SMP PREEMPT_DYNAMIC Tue, 17 Nov 2026 22:28:33 +0000 x86_64 GNU/Linux
12
total used free shared buff/cache available
Mem: 15Gi 6.2Gi 2.7Gi 476Mi 7.1Gi 9.2Gi
Swap: 8.0Gi 57Mi 7.9Gi
Mem: 15Gi 6.5Gi 3.6Gi 440Mi 5.8Gi 8.8Gi
Swap: 8.0Gi 187Mi 7.8Gi
podman version 6.2.0
podman version 6.2.0
podman-compose version 1.6.0
@@ -16,4 +16,4 @@ docker.io/library/postgres:18.6-alpine3.24 57b23a0326ee
docker.io/library/redis:8.10.3-alpine3.23 9722accf3e8e
docker.io/migrate/migrate:v4.20.1 719a6f5d0ade
docker.io/rustfs/rustfs:1.0.6 7cd1c573d76d
localhost/messenger-api:lab4 e2582dea4a72
localhost/messenger-api:lab4 4c57d3f41dfb
+2 -2
View File
@@ -1,7 +1,7 @@
2026-11-20T04:14:49+03:00
2026-11-20T04:55:04+03:00
make test-failover ACTION_SCRIPT=scripts/stop-one.sh
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 101, "failed_attempts": 0, "first_recovery_seconds": 3.304}
{"observed_instances_before": 2, "successful_writes": 88, "failed_attempts": 0, "first_recovery_seconds": 3.256}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+2 -2
View File
@@ -1,7 +1,7 @@
2026-11-20T04:15:25+03:00
2026-11-20T04:55:38+03:00
make test-failover ACTION_SCRIPT=scripts/stop-one.sh
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 86, "failed_attempts": 0, "first_recovery_seconds": 3.228}
{"observed_instances_before": 2, "successful_writes": 99, "failed_attempts": 0, "first_recovery_seconds": 3.236}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+2 -2
View File
@@ -1,4 +1,4 @@
2026-11-20T04:20:36+03:00
2026-11-20T04:53:46+03:00
make test-idempotency
BASE_URL="http://localhost:8080" python3 scripts/idempotency-race.py
@@ -7,5 +7,5 @@ successful responses (201): 20
failed requests: 0 []
distinct message ids in responses: 1
messages stored in history: 1
instances that served requests: ['8535d7918d12', 'ad1700491457']
instances that served requests: ['72c9d7b6cc57', 'e6d2e0d15c36']
OK: exactly one message created
+5 -5
View File
@@ -1,8 +1,8 @@
2026-11-20T04:21:39+03:00
2026-11-20T04:56:16+03:00
API replicas and single entrypoint
messenger-lab4_api_1 Up 26 seconds (healthy)
messenger-lab4_api_2 Up 26 seconds (healthy)
messenger-lab4_api_1 Up 53 seconds (healthy)
messenger-lab4_api_2 Up 21 seconds (healthy)
messenger-lab4_lb_1 Up About a minute
messenger-lab4_postgres_1 Up About a minute (healthy)
messenger-lab4_redis_1 Up About a minute (healthy)
@@ -19,5 +19,5 @@ messenger-lab4_s3_1 9000-9001/tcp
X-Instance-Id distribution over 20 requests through LB
10 x-instance-id: 33839df0eea0
10 x-instance-id: 4e3d4c4f1194
10 x-instance-id: a089fe9cc382
10 x-instance-id: f309c2ef4e46
+1 -1
View File
@@ -1,4 +1,4 @@
2026-11-20T04:17:58+03:00
2026-11-20T04:56:16+03:00
per-container limits, networks, secrets
messenger-lab4_api_1 nano_cpus=1000000000 memory=536870912 networks=messenger-lab4_backend messenger-lab4_edge
+13 -13
View File
@@ -1,5 +1,5 @@
2026-11-20T04:21:28+03:00
10 concurrent uploads of a 8000x5000 PNG (40,000,000 pixels) per replica; API memory limit 512 MiB; MAX_CONCURRENT_UPLOADS=8, MAX_CONCURRENT_DECODES=1
2026-11-20T04:54:15+03:00
10 concurrent uploads of a 8000x5000 PNG (40,000,000 pixels) per replica; API limit 512 MiB; MAX_CONCURRENT_UPLOADS=8, MAX_CONCURRENT_DECODES=1
BASE_URL="http://localhost:8080" python3 scripts/upload-load.py --concurrency 10 --output evidence/upload-memory.json
{
@@ -7,30 +7,30 @@ BASE_URL="http://localhost:8080" python3 scripts/upload-load.py --concurrency 10
"uploads": 10,
"fixture": "large.png",
"fixture_bytes": 126609,
"elapsed_seconds": 1.235,
"elapsed_seconds": 1.009,
"successful": 10,
"failed": 0,
"failures": [],
"latency_ms": {
"p50": 663.7,
"p95": 1224.7,
"p99": 1224.7
"p50": 660.9,
"p95": 999.3,
"p99": 999.3
},
"api_containers": [
"messenger-lab4_api_1",
"messenger-lab4_api_2"
],
"peak_bytes_before": {
"messenger-lab4_api_1": 5050368,
"messenger-lab4_api_2": 4820992
"messenger-lab4_api_1": 5951488,
"messenger-lab4_api_2": 4993024
},
"peak_bytes_after": {
"messenger-lab4_api_1": 368119808,
"messenger-lab4_api_2": 368185344
"messenger-lab4_api_1": 348913664,
"messenger-lab4_api_2": 348721152
},
"peak_delta_bytes": {
"messenger-lab4_api_1": 363069440,
"messenger-lab4_api_2": 363364352
"messenger-lab4_api_1": 342962176,
"messenger-lab4_api_2": 343728128
},
"peak_max_mb": 351.13
"peak_max_mb": 332.75
}
+4 -8
View File
@@ -1,13 +1,9 @@
2026-11-20T04:18:05+03:00
2026-11-20T04:56:17+03:00
migrate container logs and schema version
1/u init (17.596326ms)
2/u message_idempotency (23.558514ms)
3/u attachments (35.669736ms)
no change
no change
no change
no change
1/u init (18.672238ms)
2/u message_idempotency (27.931065ms)
3/u attachments (37.481418ms)
no change
no change
+1 -1
View File
@@ -1,4 +1,4 @@
2026-11-20T04:20:27+03:00
2026-11-20T04:53:36+03:00
make test-attachments
BASE_URL="http://localhost:8080" python3 scripts/attachments-check.py
+13 -13
View File
@@ -1,4 +1,4 @@
2026-11-20T04:19:38+03:00
2026-11-20T04:54:22+03:00
make test-persistence ACTION_SCRIPT=scripts/restart.sh
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080"
@@ -7,12 +7,12 @@ PASS: persistence preserved confirmed data and existing session. Hook scope need
--- hook scope: containers and volumes before/after scripts/restart.sh ---
messenger-lab4_api_1 8535d7918d12 Up 1 second (starting)
messenger-lab4_api_2 ad1700491457 Up 1 second (starting)
messenger-lab4_lb_1 0bed57f994fa Up 1 second
messenger-lab4_postgres_1 53c091ca7f0a Up 1 second (starting)
messenger-lab4_redis_1 e0cfe44337f5 Up 1 second (healthy)
messenger-lab4_s3_1 8548fb0864af Up 1 second (healthy)
messenger-lab4_api_1 a089fe9cc382 Up 5 seconds (healthy)
messenger-lab4_api_2 f309c2ef4e46 Up 5 seconds (healthy)
messenger-lab4_lb_1 efc7da123526 Up 5 seconds
messenger-lab4_postgres_1 c64e954cf92a Up 5 seconds (healthy)
messenger-lab4_redis_1 90ac9f642b09 Up 5 seconds (healthy)
messenger-lab4_s3_1 6ae98c5aef4f Up 5 seconds (healthy)
messenger-lab4_pgdata
messenger-lab4_redisdata
messenger-lab4_s3data
@@ -20,12 +20,12 @@ messenger-lab4_s3data
$ scripts/restart.sh
messenger-lab4_api_1 8535d7918d12 Up 15 seconds (healthy)
messenger-lab4_api_2 ad1700491457 Up 16 seconds (healthy)
messenger-lab4_lb_1 0bed57f994fa Up 16 seconds
messenger-lab4_postgres_1 53c091ca7f0a Up 15 seconds (healthy)
messenger-lab4_redis_1 e0cfe44337f5 Up 15 seconds (healthy)
messenger-lab4_s3_1 8548fb0864af Up 16 seconds (healthy)
messenger-lab4_api_1 a089fe9cc382 Up 15 seconds (healthy)
messenger-lab4_api_2 f309c2ef4e46 Up 15 seconds (healthy)
messenger-lab4_lb_1 efc7da123526 Up 15 seconds
messenger-lab4_postgres_1 c64e954cf92a Up 15 seconds (healthy)
messenger-lab4_redis_1 90ac9f642b09 Up 15 seconds (healthy)
messenger-lab4_s3_1 6ae98c5aef4f Up 15 seconds (healthy)
messenger-lab4_pgdata
messenger-lab4_redisdata
messenger-lab4_s3data
+7 -5
View File
@@ -1,20 +1,22 @@
2026-11-20T04:15:49+03:00
2026-11-20T04:44:19+03:00
bucket privacy and disabled console (checks outside the application API)
$ wget http://s3:9000/messenger-attachments/chats/.../... (anonymous, from backend network)
Connecting to s3:9000 (10.89.5.36:9000)
$ anonymous GET of an existing object from the backend network
Connecting to s3:9000 (10.89.5.22:9000)
HTTP/1.1 403 Forbidden
wget: server returned error: HTTP/1.1 403 Forbidden
$ anonymous bucket listing
Connecting to s3:9000 (10.89.5.36:9000)
Connecting to s3:9000 (10.89.5.22:9000)
HTTP/1.1 403 Forbidden
wget: server returned error: HTTP/1.1 403 Forbidden
$ console port check inside s3 container
$ console port inside the s3 container
console_http=000
console-closed
$ published ports
messenger-lab4_api_1 8080/tcp
messenger-lab4_api_2 8080/tcp
messenger-lab4_lb_1 0.0.0.0:8080->8080/tcp
messenger-lab4_s3_1 9000-9001/tcp
+91 -31
View File
@@ -1,4 +1,4 @@
2026-11-20T04:13:27+03:00
2026-11-20T04:41:03+03:00
reconciler drill: baseline, grace period, dry-run, apply, repeat
$ scripts/reconcile.sh # dry-run, grace 1h, clean baseline
@@ -6,54 +6,69 @@ $ scripts/reconcile.sh # dry-run, grace 1h, clean baseline
"prefix": "chats/",
"grace_seconds": 3600,
"dry_run": true,
"scanned_objects": 15,
"scanned_rows": 15,
"scanned_objects": 18,
"scanned_rows": 18,
"truncated": false,
"orphans": [],
"missing": [],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"duration_ms": 7
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 7,
"objects_per_second": 2571.4285714285716
}
$ scripts/s3tool.sh put chats/aaaaaaaa-0000-4000-8000-000000000000/bbbbbbbb-0000-4000-8000-000000000000 - < scripts/fixtures/sample.jpg
put chats/aaaaaaaa-0000-4000-8000-000000000000/bbbbbbbb-0000-4000-8000-000000000000 (653 bytes)
$ scripts/reconcile.sh # fresh orphan stays: grace 1h
$ scripts/reconcile.sh # fresh orphan skipped by grace
{
"prefix": "chats/",
"grace_seconds": 3600,
"dry_run": true,
"scanned_objects": 16,
"scanned_rows": 15,
"scanned_objects": 19,
"scanned_rows": 18,
"truncated": false,
"orphans": [],
"missing": [],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"duration_ms": 7
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 8,
"objects_per_second": 2375
}
$ scripts/reconcile.sh -grace 0s # orphan detected, dry-run keeps it
$ scripts/reconcile.sh -grace 0s # detected, dry-run keeps it
{
"prefix": "chats/",
"grace_seconds": 0,
"dry_run": true,
"scanned_objects": 16,
"scanned_rows": 15,
"scanned_objects": 19,
"scanned_rows": 18,
"truncated": false,
"orphans": [
{
"key": "chats/aaaaaaaa-0000-4000-8000-000000000000/bbbbbbbb-0000-4000-8000-000000000000",
"size_bytes": 653,
"last_modified": "2026-11-20T01:13:27Z",
"last_modified": "2026-11-20T01:41:03Z",
"age_seconds": 0
}
],
"missing": [],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"duration_ms": 6
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 7,
"objects_per_second": 2714.285714285714
}
$ scripts/reconcile.sh -grace 0s -dry-run=false # apply
@@ -61,21 +76,26 @@ $ scripts/reconcile.sh -grace 0s -dry-run=false # apply
"prefix": "chats/",
"grace_seconds": 0,
"dry_run": false,
"scanned_objects": 16,
"scanned_rows": 15,
"scanned_objects": 19,
"scanned_rows": 18,
"truncated": false,
"orphans": [
{
"key": "chats/aaaaaaaa-0000-4000-8000-000000000000/bbbbbbbb-0000-4000-8000-000000000000",
"size_bytes": 653,
"last_modified": "2026-11-20T01:13:27Z",
"age_seconds": 3
"last_modified": "2026-11-20T01:41:03Z",
"age_seconds": 4
}
],
"missing": [],
"deleted_objects": 1,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"duration_ms": 12
"s3_requests": 2,
"db_queries": 2,
"duration_ms": 15,
"objects_per_second": 1266.6666666666667
}
$ scripts/reconcile.sh -grace 0s -dry-run=false # repeat: nothing left
@@ -83,41 +103,81 @@ $ scripts/reconcile.sh -grace 0s -dry-run=false # repeat: nothing left
"prefix": "chats/",
"grace_seconds": 0,
"dry_run": false,
"scanned_objects": 15,
"scanned_rows": 15,
"scanned_objects": 18,
"scanned_rows": 18,
"truncated": false,
"orphans": [],
"missing": [],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"duration_ms": 7
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 8,
"objects_per_second": 2250
}
missing drill: metadata row without object
$ scripts/s3tool.sh delete chats/9452049e-b86c-4d9a-8060-d98f6966b956/97121cfe-6b29-4227-867f-3188e72a725c
deleted chats/9452049e-b86c-4d9a-8060-d98f6966b956/97121cfe-6b29-4227-867f-3188e72a725c
$ scripts/s3tool.sh delete chats/<chat>/<attachment> of an existing attachment
$ scripts/s3tool.sh delete chats/bd1c9e17-0366-44b4-bd98-0a479a2a637c/1e9b9e12-eab2-4846-8952-e739a4257b37
deleted chats/bd1c9e17-0366-44b4-bd98-0a479a2a637c/1e9b9e12-eab2-4846-8952-e739a4257b37
$ scripts/reconcile.sh -grace 0s # reports missing, keeps metadata
$ scripts/reconcile.sh -grace 0s # missing reported, metadata kept in dry-run
{
"prefix": "chats/",
"grace_seconds": 0,
"dry_run": true,
"scanned_objects": 14,
"scanned_rows": 15,
"scanned_objects": 17,
"scanned_rows": 18,
"truncated": false,
"orphans": [],
"missing": [
{
"id": "97121cfe-6b29-4227-867f-3188e72a725c",
"object_key": "chats/9452049e-b86c-4d9a-8060-d98f6966b956/97121cfe-6b29-4227-867f-3188e72a725c",
"chat_id": "9452049e-b86c-4d9a-8060-d98f6966b956",
"created_at": "2026-11-20T01:11:14Z"
"id": "1e9b9e12-eab2-4846-8952-e739a4257b37",
"object_key": "chats/bd1c9e17-0366-44b4-bd98-0a479a2a637c/1e9b9e12-eab2-4846-8952-e739a4257b37",
"chat_id": "bd1c9e17-0366-44b4-bd98-0a479a2a637c",
"created_at": "2026-11-20T01:40:28Z",
"referenced_by_message": false
}
],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"duration_ms": 6
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 9,
"objects_per_second": 1888.8888888888891
}
metadata rows still present: 1
$ scripts/reconcile.sh -grace 0s -dry-run=false # safe repair: unreferenced dead row removed
{
"prefix": "chats/",
"grace_seconds": 0,
"dry_run": false,
"scanned_objects": 17,
"scanned_rows": 18,
"truncated": false,
"orphans": [],
"missing": [
{
"id": "1e9b9e12-eab2-4846-8952-e739a4257b37",
"object_key": "chats/bd1c9e17-0366-44b4-bd98-0a479a2a637c/1e9b9e12-eab2-4846-8952-e739a4257b37",
"chat_id": "bd1c9e17-0366-44b4-bd98-0a479a2a637c",
"created_at": "2026-11-20T01:40:28Z",
"referenced_by_message": false
}
],
"deleted_objects": 0,
"deleted_metadata": 1,
"retained_missing": 0,
"delete_failures": 0,
"s3_requests": 1,
"db_queries": 3,
"duration_ms": 8,
"objects_per_second": 2125
}
+17
View File
@@ -0,0 +1,17 @@
2026-11-20T04:57:42+03:00
S3 unavailable: readiness and client-visible behaviour
$ GET /health/ready on a replica
HTTP/1.1 503 Service Unavailable
wget: server returned error: HTTP/1.1 503 Service Unavailable
$ GET /health/live on a replica (process is alive)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Instance-Id: a089fe9cc382
$ client request through the load balancer
status=503
$ readiness after S3 recovery
status=200
+1 -1
View File
@@ -1,4 +1,4 @@
2026-11-20T04:20:26+03:00
2026-11-20T04:53:35+03:00
make test
python3 tests/smoke.py --base-url "http://localhost:8080"
+4 -4
View File
@@ -1,16 +1,16 @@
2026-11-20T04:18:15+03:00
2026-11-20T04:56:31+03:00
object bytes live in the RustFS volume, metadata in PostgreSQL
id | object_key | size_bytes | sha256
--------------------------------------+---------------------------------------------------------------------------------+------------+------------------------------------------------------------------
3dbc5415-9791-4983-a253-bc71fdc79a24 | chats/3ec617cd-fddf-4ae1-ad9d-37a4bb319b76/3dbc5415-9791-4983-a253-bc71fdc79a24 | 126609 | 518fd54cb19f8ceaca99139652fb96ed3a5d502392450846c832924b1722d2bf
82d5d4f3-e97a-4aea-9501-69ef2b74e138 | chats/e8618579-667a-4423-aa62-5402596e57d8/82d5d4f3-e97a-4aea-9501-69ef2b74e138 | 111817 | 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
(1 row)
S3 volume listing for that object
total 128
-rw-r--r-- 1 rustfs rustfs 127190 Nov 20 01:17 xl.meta
total 112
-rw-r--r-- 1 rustfs rustfs 112398 Nov 20 01:55 xl.meta
attachments table columns (no binary content)
+18 -16
View File
@@ -1,4 +1,4 @@
2026-11-20T04:20:28+03:00
2026-11-20T04:53:38+03:00
make test-go
? messenger/cmd/reconcile [no test files]
@@ -10,50 +10,52 @@ make test-go
=== RUN TestSessionExpiry
--- PASS: TestSessionExpiry (3.09s)
=== RUN TestLogout
--- PASS: TestLogout (0.11s)
--- PASS: TestLogout (0.13s)
=== RUN TestWrongPassword
--- PASS: TestWrongPassword (0.10s)
=== RUN TestRedisUnavailable
redis: 2026/11/20 04:20:32 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:20:32 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:20:33 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:20:33 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:20:34 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:20:34 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
--- PASS: TestRedisUnavailable (2.83s)
redis: 2026/11/20 04:53:42 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:53:43 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:53:43 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:53:44 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:53:44 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:53:44 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
--- PASS: TestRedisUnavailable (2.95s)
=== RUN TestDatabaseUnavailable
--- PASS: TestDatabaseUnavailable (0.17s)
=== RUN TestInvalidJSON
--- PASS: TestInvalidJSON (0.01s)
=== RUN TestForeignChat
--- PASS: TestForeignChat (0.16s)
--- PASS: TestForeignChat (0.18s)
=== RUN TestEmptyMessage
redis: 2026/11/20 04:20:35 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/20 04:53:45 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
--- PASS: TestEmptyMessage (0.08s)
=== RUN TestDuplicateUsername
--- PASS: TestDuplicateUsername (0.10s)
=== RUN TestPaginationMultiplePages
--- PASS: TestPaginationMultiplePages (0.08s)
--- PASS: TestPaginationMultiplePages (0.09s)
=== RUN TestConcurrentMessages
--- PASS: TestConcurrentMessages (0.59s)
--- PASS: TestConcurrentMessages (0.57s)
PASS
ok messenger/internal/handler 7.325s
ok messenger/internal/handler 7.474s
=== RUN TestPlanDetectsOrphansAndMissing
--- PASS: TestPlanDetectsOrphansAndMissing (0.00s)
=== RUN TestPlanHonoursGraceAndPrefix
--- PASS: TestPlanHonoursGraceAndPrefix (0.00s)
=== RUN TestPlanNeverDeletesReferencedObjects
--- PASS: TestPlanNeverDeletesReferencedObjects (0.00s)
=== RUN TestPlanOnlyReportsRowsInsidePrefix
--- PASS: TestPlanOnlyReportsRowsInsidePrefix (0.00s)
=== RUN TestPlanOutputIsSorted
--- PASS: TestPlanOutputIsSorted (0.00s)
PASS
ok messenger/internal/reconcile 0.002s
=== RUN TestRegisterUsernameRace
--- PASS: TestRegisterUsernameRace (0.05s)
--- PASS: TestRegisterUsernameRace (0.02s)
=== RUN TestCreateChatRollback
--- PASS: TestCreateChatRollback (0.02s)
PASS
ok messenger/internal/repository/postgres 0.071s
ok messenger/internal/repository/postgres 0.040s
? messenger/internal/repository/redis [no test files]
? messenger/internal/repository/s3 [no test files]
? messenger/internal/router [no test files]
+41
View File
@@ -0,0 +1,41 @@
2026-11-20T04:42:15+03:00
traversal cost of the reconciler (synthetic objects under chats/bench/, 1 KiB each); scan uses LIST pages, repair deletes one by one
{
"prefix": "chats/bench",
"measurements": [
{
"objects": 100,
"scan_ms": 9,
"scan_s3_requests": 1,
"scan_db_queries": 2,
"scan_objects_per_second": 11111.1,
"scan_ms_per_object": 0.09,
"repair_ms": 1324,
"repair_s3_requests": 101,
"repair_deleted": 100
},
{
"objects": 1000,
"scan_ms": 34,
"scan_s3_requests": 1,
"scan_db_queries": 2,
"scan_objects_per_second": 29411.8,
"scan_ms_per_object": 0.034,
"repair_ms": 12232,
"repair_s3_requests": 1001,
"repair_deleted": 1000
},
{
"objects": 5000,
"scan_ms": 166,
"scan_s3_requests": 5,
"scan_db_queries": 2,
"scan_objects_per_second": 30120.5,
"scan_ms_per_object": 0.0332,
"repair_ms": 69929,
"repair_s3_requests": 5005,
"repair_deleted": 5000
}
]
}
+193
View File
@@ -0,0 +1,193 @@
2026-11-20T04:41:49+03:00
two-store consistency: injections on both sides, dry-run, safe repair, repeat, protection of fresh and used data
injections:
S3 has an object that has no metadata row (fresh orphan)
metadata exists but the object is gone: one attachment used by a message, one unused
$ scripts/s3tool.sh put chats/aaaaaaaa-0000-4000-8000-000000000000/bbbbbbbb-0000-4000-8000-000000000000 - < scripts/fixtures/sample.jpg
put chats/aaaaaaaa-0000-4000-8000-000000000000/bbbbbbbb-0000-4000-8000-000000000000 (653 bytes)
$ scripts/s3tool.sh delete chats/47f62016-7525-4910-9823-0b21f2664b10/6a9f0506-2126-497a-b8b4-89ac728fe5a1 # used
deleted chats/47f62016-7525-4910-9823-0b21f2664b10/6a9f0506-2126-497a-b8b4-89ac728fe5a1
$ scripts/s3tool.sh delete chats/d03b2c6b-67fd-4b5d-bc17-9e926440ff8d/c49ab2de-258a-4851-8ad2-f7f585fd3488 # unused
deleted chats/d03b2c6b-67fd-4b5d-bc17-9e926440ff8d/c49ab2de-258a-4851-8ad2-f7f585fd3488
$ scripts/reconcile.sh -grace 1h # dry-run
{
"prefix": "chats/",
"grace_seconds": 3600,
"dry_run": true,
"scanned_objects": 19,
"scanned_rows": 20,
"truncated": false,
"orphans": [],
"missing": [
{
"id": "6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"object_key": "chats/47f62016-7525-4910-9823-0b21f2664b10/6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"chat_id": "47f62016-7525-4910-9823-0b21f2664b10",
"created_at": "2026-11-20T01:41:41Z",
"referenced_by_message": true
},
{
"id": "c49ab2de-258a-4851-8ad2-f7f585fd3488",
"object_key": "chats/d03b2c6b-67fd-4b5d-bc17-9e926440ff8d/c49ab2de-258a-4851-8ad2-f7f585fd3488",
"chat_id": "d03b2c6b-67fd-4b5d-bc17-9e926440ff8d",
"created_at": "2026-11-20T01:41:41Z",
"referenced_by_message": false
}
],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 8,
"objects_per_second": 2375
}
$ scripts/reconcile.sh -grace 1h -dry-run=false # apply: fresh object survives, safe metadata repair
{
"prefix": "chats/",
"grace_seconds": 3600,
"dry_run": false,
"scanned_objects": 19,
"scanned_rows": 20,
"truncated": false,
"orphans": [],
"missing": [
{
"id": "6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"object_key": "chats/47f62016-7525-4910-9823-0b21f2664b10/6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"chat_id": "47f62016-7525-4910-9823-0b21f2664b10",
"created_at": "2026-11-20T01:41:41Z",
"referenced_by_message": true
},
{
"id": "c49ab2de-258a-4851-8ad2-f7f585fd3488",
"object_key": "chats/d03b2c6b-67fd-4b5d-bc17-9e926440ff8d/c49ab2de-258a-4851-8ad2-f7f585fd3488",
"chat_id": "d03b2c6b-67fd-4b5d-bc17-9e926440ff8d",
"created_at": "2026-11-20T01:41:41Z",
"referenced_by_message": false
}
],
"deleted_objects": 0,
"deleted_metadata": 1,
"retained_missing": 1,
"delete_failures": 0,
"s3_requests": 1,
"db_queries": 3,
"duration_ms": 12,
"objects_per_second": 1583.3333333333333
}
$ scripts/s3tool.sh list chats/aaaaaaaa-0000-4000-8000-000000000000 # fresh orphan still present
chats/aaaaaaaa-0000-4000-8000-000000000000/bbbbbbbb-0000-4000-8000-000000000000 653 2026-11-20T01:41:49Z
$ scripts/reconcile.sh -grace 0s # now eligible for deletion
{
"prefix": "chats/",
"grace_seconds": 0,
"dry_run": true,
"scanned_objects": 19,
"scanned_rows": 19,
"truncated": false,
"orphans": [
{
"key": "chats/aaaaaaaa-0000-4000-8000-000000000000/bbbbbbbb-0000-4000-8000-000000000000",
"size_bytes": 653,
"last_modified": "2026-11-20T01:41:49Z",
"age_seconds": 7
}
],
"missing": [
{
"id": "6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"object_key": "chats/47f62016-7525-4910-9823-0b21f2664b10/6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"chat_id": "47f62016-7525-4910-9823-0b21f2664b10",
"created_at": "2026-11-20T01:41:41Z",
"referenced_by_message": true
}
],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 0,
"delete_failures": 0,
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 8,
"objects_per_second": 2375
}
$ scripts/reconcile.sh -grace 0s -dry-run=false # apply
{
"prefix": "chats/",
"grace_seconds": 0,
"dry_run": false,
"scanned_objects": 19,
"scanned_rows": 19,
"truncated": false,
"orphans": [
{
"key": "chats/aaaaaaaa-0000-4000-8000-000000000000/bbbbbbbb-0000-4000-8000-000000000000",
"size_bytes": 653,
"last_modified": "2026-11-20T01:41:49Z",
"age_seconds": 13
}
],
"missing": [
{
"id": "6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"object_key": "chats/47f62016-7525-4910-9823-0b21f2664b10/6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"chat_id": "47f62016-7525-4910-9823-0b21f2664b10",
"created_at": "2026-11-20T01:41:41Z",
"referenced_by_message": true
}
],
"deleted_objects": 1,
"deleted_metadata": 0,
"retained_missing": 1,
"delete_failures": 0,
"s3_requests": 2,
"db_queries": 2,
"duration_ms": 15,
"objects_per_second": 1266.6666666666667
}
$ scripts/reconcile.sh -grace 0s -dry-run=false # repeat: idempotent
{
"prefix": "chats/",
"grace_seconds": 0,
"dry_run": false,
"scanned_objects": 18,
"scanned_rows": 19,
"truncated": false,
"orphans": [],
"missing": [
{
"id": "6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"object_key": "chats/47f62016-7525-4910-9823-0b21f2664b10/6a9f0506-2126-497a-b8b4-89ac728fe5a1",
"chat_id": "47f62016-7525-4910-9823-0b21f2664b10",
"created_at": "2026-11-20T01:41:41Z",
"referenced_by_message": true
}
],
"deleted_objects": 0,
"deleted_metadata": 0,
"retained_missing": 1,
"delete_failures": 0,
"s3_requests": 1,
"db_queries": 2,
"duration_ms": 9,
"objects_per_second": 2000.0000000000002
}
used attachments remain untouched (rows and objects)
used_attachments | ready
------------------+-------
3 | 3
(1 row)
retained referenced metadata row for the attachment whose object was deleted: 1
object of that referenced attachment is still absent: 0
+11 -11
View File
@@ -3,30 +3,30 @@
"uploads": 10,
"fixture": "large.png",
"fixture_bytes": 126609,
"elapsed_seconds": 1.235,
"elapsed_seconds": 1.009,
"successful": 10,
"failed": 0,
"failures": [],
"latency_ms": {
"p50": 663.7,
"p95": 1224.7,
"p99": 1224.7
"p50": 660.9,
"p95": 999.3,
"p99": 999.3
},
"api_containers": [
"messenger-lab4_api_1",
"messenger-lab4_api_2"
],
"peak_bytes_before": {
"messenger-lab4_api_1": 5050368,
"messenger-lab4_api_2": 4820992
"messenger-lab4_api_1": 5951488,
"messenger-lab4_api_2": 4993024
},
"peak_bytes_after": {
"messenger-lab4_api_1": 368119808,
"messenger-lab4_api_2": 368185344
"messenger-lab4_api_1": 348913664,
"messenger-lab4_api_2": 348721152
},
"peak_delta_bytes": {
"messenger-lab4_api_1": 363069440,
"messenger-lab4_api_2": 363364352
"messenger-lab4_api_1": 342962176,
"messenger-lab4_api_2": 343728128
},
"peak_max_mb": 351.13
"peak_max_mb": 332.75
}