lab2: postgres, sessions, redis, persistence, stale read
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-09 21:30:36 +03:00
parent 65003b6119
commit d8842a3de4
54 changed files with 3205 additions and 19 deletions
Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
Limit (cost=0.29..4.45 rows=50 width=64) (actual time=0.030..0.039 rows=50 loops=1)
Buffers: shared hit=3
-> Index Scan using messages_chat_created_id_idx on messages
Index Cond: (chat_id = '...'::uuid)
Buffers: shared hit=3
Planning Time: 0.560 ms
Execution Time: 0.069 ms
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
1) "session:-p3QE-W4uB-mVaLw_tFMhcm3K65RufBAE59ZVi6TABQ"
2) "session:dqpgjo2m7OZVryghhb331A6vzLbZhByHxZkELcItUpg"
+3
View File
@@ -0,0 +1,3 @@
aof_enabled:1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
+1
View File
@@ -0,0 +1 @@
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
+28
View File
@@ -0,0 +1,28 @@
=== STALE READ EXPERIMENT (трек 5.1) ===
BUG MODE (invalidation OFF):
1. Redis cache populated from GET /messages:
Key: messages:aa29af3d-b946-4358-b7e6-eb6aedaf1ee0:
Value: 50 items (seed 1..50)
2. POST STALE_1 → 201 Created.
DB has STALE_1: 1
3. Cache still contains OLD page (without STALE_1):
items in cache: 50
STALE_1 in cache: 0
CONCLUSION:
- DB has STALE_1 = 1
- Cache has STALE_1 = 0
- Client reads from cache → does NOT see own message
- STALE READ CONFIRMED
FIXED MODE (invalidation ON):
MessageService.Send вызывает MessageCache.Invalidate(chatID) при флаге invalidate=true.
Инвалидация удаляет все ключи messages:{chatID}:* из Redis.
Следующий GET /messages идёт в БД и возвращает свежие данные.
Защита реализована в коде: internal/repository/redis/message_cache.go, метод Invalidate.