Реализовать лабораторную 2 на оценку 4

PostgreSQL как источник истины, непрозрачные сессии в Redis с TTL и AOF, миграции под advisory lock, пул и таймауты, проверки гонки/отката/отказов и отчёт с evidence.
This commit is contained in:
Чиняева
2026-11-06 22:37:31 +03:00
parent 65003b6119
commit df31f4a9fb
43 changed files with 2045 additions and 22 deletions
+1
View File
@@ -0,0 +1 @@
PASS: wrong password, Basic rejection, logout and token reuse checks
+1
View File
@@ -0,0 +1 @@
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
+4
View File
@@ -0,0 +1,4 @@
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mtusi-lab2-api-1 mtusi-lab2-api "gunicorn --bind=0.0тАж" api 23 seconds ago Up 1 second (health: starting) 0.0.0.0:18080->8080/tcp, [::]:18080->8080/tcp
mtusi-lab2-postgres-1 postgres:16.4-alpine "docker-entrypoint.sтАж" postgres 12 minutes ago Up 2 seconds (health: starting) 5432/tcp
mtusi-lab2-redis-1 redis:7.4.0-alpine "docker-entrypoint.sтАж" redis 12 minutes ago Up 2 seconds (health: starting) 6379/tcp
+4
View File
@@ -0,0 +1,4 @@
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mtusi-lab2-api-1 mtusi-lab2-api "gunicorn --bind=0.0тАж" api 19 seconds ago Up 17 seconds (healthy) 0.0.0.0:18080->8080/tcp, [::]:18080->8080/tcp
mtusi-lab2-postgres-1 postgres:16.4-alpine "docker-entrypoint.sтАж" postgres 12 minutes ago Up About a minute (healthy) 5432/tcp
mtusi-lab2-redis-1 redis:7.4.0-alpine "docker-entrypoint.sтАж" redis 12 minutes ago Up About a minute (healthy) 6379/tcp
+19
View File
@@ -0,0 +1,19 @@
empty users body 400 invalid_request
extra user field 400 invalid_request
chat1 201 None
chat2 201 None
unknown member 400 invalid_request
caller missing 400 invalid_request
duplicate member 400 invalid_request
invalid chat uuid 400 invalid_request
message 201 None
message 201 None
page exactly limit 200 2 None
chat1 page 200 None
chat1 page had no next cursor
chat page 1 200 1 True
chat page 2 200 1 False
blank text 400 invalid_request
too long text 400 invalid_request
sender_id rejected 400 invalid_request
EDGE PASS
+1
View File
@@ -0,0 +1 @@
PASS: expired session is rejected with 401 and Bearer challenge
+16
View File
@@ -0,0 +1,16 @@
# EXPLAIN (ANALYZE, BUFFERS) for keyset history pagination
generated_at_utc: 2026-11-06T19:27:08.308823Z
messages_in_chat: 10000
chat_id: 009edfde-74bf-4dd7-8e55-a665d2d6f38a
query: WHERE chat_id = ? AND (created_at, id) > (?, ?) ORDER BY created_at, id LIMIT 51
Limit (cost=0.29..94.71 rows=51 width=78) (actual time=0.020..0.029 rows=51 loops=1)
Buffers: shared hit=4
-> Index Scan using messages_chat_created_at_id_idx on messages (cost=0.29..926.01 rows=500 width=78) (actual time=0.019..0.025 rows=51 loops=1)
Index Cond: ((chat_id = '009edfde-74bf-4dd7-8e55-a665d2d6f38a'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:09.501+00'::timestamp with time zone, 'd8f60f44-b107-4f1a-bae2-4fcf80d33d70'::uuid)))
Buffers: shared hit=4
Planning:
Buffers: shared hit=6
Planning Time: 0.138 ms
Execution Time: 0.124 ms
PASS: index used on 10000 messages; evidence written to /tmp/explain_history.txt
+5
View File
@@ -0,0 +1,5 @@
OBSERVED: redis down: readiness=503, bearer request=503
OBSERVED: redis up: readiness=200 in 0.48s, same token=200 (AOF persistence)
OBSERVED: postgres down: readiness=503, bearer request=503
OBSERVED: postgres up: readiness=200 in 3.01s, same token=200
PASS: dependency loss produced only bounded 503 responses; no anonymous trust
+17
View File
@@ -0,0 +1,17 @@
{
"lab": 2,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 15.0,
"elapsed_seconds": 15.047,
"concurrency": 4,
"successful_requests": 2599,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 172.728,
"successful_latency_ms": {
"p50": 22.956,
"p95": 38.873,
"p99": 44.759
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
+17
View File
@@ -0,0 +1,17 @@
{
"lab": 2,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 15.0,
"elapsed_seconds": 15.047,
"concurrency": 4,
"successful_requests": 2599,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 172.728,
"successful_latency_ms": {
"p50": 22.956,
"p95": 38.873,
"p99": 44.759
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
+2
View File
@@ -0,0 +1,2 @@
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
+8
View File
@@ -0,0 +1,8 @@
statement_timeout = 5s
idle_in_transaction_session_timeout = 10s
lock_timeout = 3s
pool_min = 1
pool_max = 10
pool_size = 1
pool_available = 1
PASS: bounded pool and SQL timeouts are active
+1
View File
@@ -0,0 +1 @@
PASS: 8 concurrent registrations produced exactly one user and one session
+10
View File
@@ -0,0 +1,10 @@
rdb_last_save_time:1793993503
aof_enabled:1
aof_rewrite_in_progress:0
aof_last_write_status:ok
23
sample_session_key=session:0ca7134c5787318eb96bdeca133253f826477b52413ccd3f7f905f9aed20007d
sample_session_ttl_seconds=3486
+1
View File
@@ -0,0 +1 @@
PASS: failed membership insert rolled back the chat; subsequent create is atomic
+36
View File
@@ -0,0 +1,36 @@
TABLES
table_name
-------------------
chat_members
chats
messages
schema_migrations
users
(5 rows)
INDEXES
indexname | indexdef
---------------------------------+-------------------------------------------------------------------------------------------------------
chat_members_pkey | CREATE UNIQUE INDEX chat_members_pkey ON public.chat_members USING btree (chat_id, user_id)
chat_members_user_chat_idx | CREATE INDEX chat_members_user_chat_idx ON public.chat_members USING btree (user_id, chat_id)
chats_created_at_id_idx | CREATE INDEX chats_created_at_id_idx ON public.chats USING btree (created_at, id)
chats_pkey | CREATE UNIQUE INDEX chats_pkey ON public.chats USING btree (id)
messages_chat_created_at_id_idx | CREATE INDEX messages_chat_created_at_id_idx ON public.messages USING btree (chat_id, created_at, id)
messages_pkey | CREATE UNIQUE INDEX messages_pkey ON public.messages USING btree (id)
schema_migrations_pkey | CREATE UNIQUE INDEX schema_migrations_pkey ON public.schema_migrations USING btree (version)
users_pkey | CREATE UNIQUE INDEX users_pkey ON public.users USING btree (id)
users_username_key | CREATE UNIQUE INDEX users_username_key ON public.users USING btree (username)
(9 rows)
MIGRATIONS
version | applied_at
----------+-------------------------------
001_init | 2026-11-06 19:22:16.209767+00
(1 row)
COUNTS
users | chats | members | messages
-------+-------+---------+----------
34 | 11 | 18 | 22635
(1 row)
+1
View File
@@ -0,0 +1 @@
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.