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
+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
}