forked from mtusi2026/mtusi2026lab2
Исправление по замечанию: отзыв сессии выдерживает гонку с наполнением кэша
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
=== 1. Останавливаю кэш сессий (valkey) ===
|
||||
Container mtusi-lab2-valkey-1 Stopping
|
||||
Container mtusi-lab2-valkey-1 Stopped
|
||||
api Up 31 seconds (healthy)
|
||||
postgres Up 37 seconds (unhealthy)
|
||||
api Up 40 seconds (healthy)
|
||||
postgres Up 46 seconds (unhealthy)
|
||||
PASS login_and_read_work_without_cache
|
||||
PASS unknown_token_is_still_rejected
|
||||
PASS readiness_ignores_the_cache
|
||||
@@ -13,7 +13,7 @@ PASS readiness_ignores_the_cache
|
||||
=== 2. Останавливаю PostgreSQL ===
|
||||
Container mtusi-lab2-postgres-1 Stopping
|
||||
Container mtusi-lab2-postgres-1 Stopped
|
||||
api Up 32 seconds (healthy)
|
||||
api Up 41 seconds (healthy)
|
||||
valkey Up Less than a second (health: starting)
|
||||
PASS readiness_reports_the_outage
|
||||
PASS writes_fail_with_503
|
||||
@@ -24,6 +24,6 @@ PASS login_fails_closed
|
||||
Container mtusi-lab2-postgres-1 Started
|
||||
|
||||
=== 3. Состояние восстановлено ===
|
||||
api Up 38 seconds (healthy)
|
||||
postgres Up 3 seconds (health: starting)
|
||||
valkey Up 7 seconds (healthy)
|
||||
api Up 44 seconds (healthy)
|
||||
postgres Up Less than a second (health: starting)
|
||||
valkey Up 3 seconds (health: starting)
|
||||
|
||||
+35
-35
@@ -7,7 +7,7 @@ valkey valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682f
|
||||
=== Засев 10000 сообщений с неравномерными чатами ===
|
||||
seed_duration | seeded_rows | target_total | messages_total
|
||||
-----------------+-------------+--------------+----------------
|
||||
00:00:00.000975 | 0 | 10000 | 52887
|
||||
00:00:00.001099 | 0 | 10000 | 53293
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -19,70 +19,70 @@ valkey valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682f
|
||||
|
||||
messages_total | chats_with_messages | table_size | indexes_size
|
||||
----------------+---------------------+------------+--------------
|
||||
52887 | 14 | 5280 kB | 7024 kB
|
||||
53293 | 14 | 5320 kB | 7152 kB
|
||||
(1 row)
|
||||
|
||||
--- распределение истории по чатам: 5 самых больших и 5 самых маленьких ---
|
||||
chat_id | rows
|
||||
--------------------------------------+-------
|
||||
174a0477-1fd5-47a9-ab90-ee8b7ef903af | 36305
|
||||
fb87d20c-528a-4bb7-9cd5-e1d4486bdfca | 16537
|
||||
3e751b33-08b7-4433-a2be-bb355af7bf62 | 25
|
||||
11bd8f2b-db27-4c63-89f0-469ee53c6cad | 5
|
||||
30e5554f-e2e0-411e-b5bd-ab86e1fd9c5f | 3
|
||||
69ee7d45-68b4-4606-befe-efaeecdedd32 | 38293
|
||||
e95dc135-101e-442f-baf7-b21f0ed7edaf | 14955
|
||||
20948a76-f794-4765-9fcc-7a9ebccafd2e | 25
|
||||
b2bd268f-f9b6-40fb-8039-1bde44c0f9ee | 5
|
||||
f4d3517a-4afa-4461-a4fc-16c6302f3d7c | 3
|
||||
(5 rows)
|
||||
|
||||
chat_id | rows
|
||||
--------------------------------------+------
|
||||
b490286c-39b8-4940-92cf-23817def915a | 1
|
||||
6fc32369-98df-4387-b07f-00dfa6e0b391 | 1
|
||||
f4c1fdcc-0ddd-4fb5-a962-c8901deac9e2 | 1
|
||||
903d0035-1bda-4ac6-9fbf-52f28fe0b94c | 1
|
||||
fb6df905-d5d2-4300-b74f-1f0196f9e2b0 | 1
|
||||
6dbc6664-e048-4858-9ce5-f507afb9fd7c | 1
|
||||
ac1c8e3d-4e29-44fc-b770-d3ef6f2351ae | 1
|
||||
5a65b658-2555-4ac9-b10a-9a081f81f37b | 1
|
||||
17c53c09-19a0-4c0c-87f8-2f8c66468119 | 1
|
||||
451812c7-05dc-4b1d-9ddb-3679c4ccd15f | 1
|
||||
(5 rows)
|
||||
|
||||
--- A. keyset, первая страница самого большого чата ---
|
||||
QUERY PLAN
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.41..5.46 rows=50 width=67) (actual time=0.005..0.011 rows=50 loops=1)
|
||||
Buffers: shared hit=21
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..3662.26 rows=36288 width=67) (actual time=0.005..0.009 rows=50 loops=1)
|
||||
Index Cond: (chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid)
|
||||
Buffers: shared hit=21
|
||||
Limit (cost=0.41..5.43 rows=50 width=67) (actual time=0.005..0.013 rows=50 loops=1)
|
||||
Buffers: shared hit=24
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..3813.50 rows=38014 width=67) (actual time=0.005..0.010 rows=50 loops=1)
|
||||
Index Cond: (chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid)
|
||||
Buffers: shared hit=24
|
||||
Planning:
|
||||
Buffers: shared hit=8
|
||||
Planning Time: 0.049 ms
|
||||
Execution Time: 0.018 ms
|
||||
Planning Time: 0.036 ms
|
||||
Execution Time: 0.021 ms
|
||||
(9 rows)
|
||||
|
||||
--- B. keyset, страница на глубине 90% истории (так работает cursor API) ---
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.41..8.17 rows=50 width=67) (actual time=0.006..0.014 rows=50 loops=1)
|
||||
Buffers: shared hit=54
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..2148.72 rows=13857 width=67) (actual time=0.005..0.012 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 14:37:21.481035+00'::timestamp with time zone, 'b34cffc1-608f-4281-89b6-d598a0000a8d'::uuid)))
|
||||
Buffers: shared hit=54
|
||||
Planning Time: 0.022 ms
|
||||
Execution Time: 0.034 ms
|
||||
Limit (cost=0.41..8.31 rows=50 width=67) (actual time=0.006..0.013 rows=50 loops=1)
|
||||
Buffers: shared hit=53
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..2141.23 rows=13555 width=67) (actual time=0.006..0.011 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 20:11:34.584521+00'::timestamp with time zone, 'aa6010bb-02c6-4d17-986b-0f5103547576'::uuid)))
|
||||
Buffers: shared hit=53
|
||||
Planning Time: 0.023 ms
|
||||
Execution Time: 0.032 ms
|
||||
(7 rows)
|
||||
|
||||
--- C. OFFSET на той же глубине (так API не делает: цена растёт со страницей) ---
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=3297.57..3302.61 rows=50 width=67) (actual time=4.132..4.139 rows=50 loops=1)
|
||||
Buffers: shared hit=33082
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..3662.26 rows=36288 width=67) (actual time=0.012..3.519 rows=32724 loops=1)
|
||||
Index Cond: (chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid)
|
||||
Buffers: shared hit=33082
|
||||
Planning Time: 0.020 ms
|
||||
Execution Time: 4.146 ms
|
||||
Limit (cost=3457.31..3462.32 rows=50 width=67) (actual time=4.463..4.470 rows=50 loops=1)
|
||||
Buffers: shared hit=34920
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..3813.50 rows=38014 width=67) (actual time=0.005..3.799 rows=34513 loops=1)
|
||||
Index Cond: (chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid)
|
||||
Buffers: shared hit=34920
|
||||
Planning Time: 0.016 ms
|
||||
Execution Time: 4.476 ms
|
||||
(7 rows)
|
||||
|
||||
--- индексы таблицы messages ---
|
||||
index | size | scans
|
||||
----------------------+---------+-------
|
||||
messages_history_idx | 4720 kB | 12
|
||||
messages_pkey | 2304 kB | 0
|
||||
messages_history_idx | 4832 kB | 12
|
||||
messages_pkey | 2320 kB | 0
|
||||
(2 rows)
|
||||
|
||||
|
||||
+16
-16
@@ -1,19 +1,19 @@
|
||||
M REPORT.md
|
||||
M app/sessions.py
|
||||
M evidence/dependency.txt
|
||||
M evidence/explain-10k.txt
|
||||
M evidence/git-hygiene.txt
|
||||
M evidence/load-cache.json
|
||||
M evidence/load-nocache.json
|
||||
M evidence/load.txt
|
||||
M evidence/migrations.txt
|
||||
M evidence/outages.txt
|
||||
M evidence/persistence.txt
|
||||
M evidence/stand.txt
|
||||
M evidence/track2/run.txt
|
||||
M scripts/bootstrap.sh
|
||||
M student-tests/evidence.sh
|
||||
M student-tests/test_outages.py
|
||||
M .env.example
|
||||
MM REPORT.md
|
||||
M app/config.py
|
||||
MM app/sessions.py
|
||||
MM evidence/dependency.txt
|
||||
MM evidence/explain-10k.txt
|
||||
MM evidence/git-hygiene.txt
|
||||
MM evidence/load-cache.json
|
||||
MM evidence/load-nocache.json
|
||||
MM evidence/load.txt
|
||||
MM evidence/migrations.txt
|
||||
MM evidence/outages.txt
|
||||
MM evidence/persistence.txt
|
||||
MM evidence/stand.txt
|
||||
MM evidence/track2/run.txt
|
||||
MM student-tests/test_outages.py
|
||||
--- правила игнорирования ---
|
||||
.gitignore:2:.env .env
|
||||
.gitignore:5:secrets/ secrets/database_url
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 30.0,
|
||||
"elapsed_seconds": 30.013,
|
||||
"elapsed_seconds": 30.011,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 36305,
|
||||
"successful_requests": 38293,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 1209.659,
|
||||
"successful_rps": 1275.96,
|
||||
"successful_latency_ms": {
|
||||
"p50": 3.13,
|
||||
"p95": 4.568,
|
||||
"p99": 6.509
|
||||
"p50": 2.933,
|
||||
"p95": 4.335,
|
||||
"p99": 7.548
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 30.0,
|
||||
"elapsed_seconds": 30.016,
|
||||
"elapsed_seconds": 30.017,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 16537,
|
||||
"successful_requests": 14955,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 550.943,
|
||||
"successful_rps": 498.216,
|
||||
"successful_latency_ms": {
|
||||
"p50": 6.908,
|
||||
"p95": 9.405,
|
||||
"p99": 12.388
|
||||
"p50": 7.457,
|
||||
"p95": 11.462,
|
||||
"p99": 14.472
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
|
||||
+12
-12
@@ -2,16 +2,16 @@
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 30.0,
|
||||
"elapsed_seconds": 30.013,
|
||||
"elapsed_seconds": 30.011,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 36305,
|
||||
"successful_requests": 38293,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 1209.659,
|
||||
"successful_rps": 1275.96,
|
||||
"successful_latency_ms": {
|
||||
"p50": 3.13,
|
||||
"p95": 4.568,
|
||||
"p99": 6.509
|
||||
"p50": 2.933,
|
||||
"p95": 4.335,
|
||||
"p99": 7.548
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
@@ -19,16 +19,16 @@
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 30.0,
|
||||
"elapsed_seconds": 30.016,
|
||||
"elapsed_seconds": 30.017,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 16537,
|
||||
"successful_requests": 14955,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 550.943,
|
||||
"successful_rps": 498.216,
|
||||
"successful_latency_ms": {
|
||||
"p50": 6.908,
|
||||
"p95": 9.405,
|
||||
"p99": 12.388
|
||||
"p50": 7.457,
|
||||
"p95": 11.462,
|
||||
"p99": 14.472
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ migrate-1 | migrations complete: 1 file(s)
|
||||
Container mtusi-lab2-postgres-1 Running
|
||||
Container mtusi-lab2-postgres-1 Waiting
|
||||
Container mtusi-lab2-postgres-1 Healthy
|
||||
Container mtusi-lab2-migrate-run-6c5706582141 Creating
|
||||
Container mtusi-lab2-migrate-run-6c5706582141 Created
|
||||
Container mtusi-lab2-migrate-run-003b830c021a Creating
|
||||
Container mtusi-lab2-migrate-run-003b830c021a Created
|
||||
skip 0001_init
|
||||
migrations complete: 1 file(s)
|
||||
--- схема ---
|
||||
@@ -30,6 +30,6 @@ Access method: heap
|
||||
|
||||
version | checksum | applied_at
|
||||
-----------+------------------------------------------------------------------+-------------------------------
|
||||
0001_init | 4fd0a8c68a5cffd3ae67a21646eb1928477d18b8716e68c1220469d858ccb9c1 | 2026-10-23 14:36:13.656522+00
|
||||
0001_init | 4fd0a8c68a5cffd3ae67a21646eb1928477d18b8716e68c1220469d858ccb9c1 | 2026-10-23 20:10:21.263237+00
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -3,5 +3,7 @@ PASS logout_is_not_confirmed_while_cache_is_down
|
||||
PASS cached_sessions_do_not_cross_users
|
||||
PASS cache_is_repopulated_after_a_miss
|
||||
PASS cache_survives_its_own_restart
|
||||
PASS revoked_session_cannot_be_resurrected_by_a_race
|
||||
PASS failed_logout_leaves_cache_and_database_consistent
|
||||
PASS hung_database_fails_fast
|
||||
6/6 checks passed
|
||||
8/8 checks passed
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
--- состояние контейнеров до рестарта ---
|
||||
api Up 39 seconds (healthy)
|
||||
postgres Up 3 seconds (health: starting)
|
||||
valkey Up 7 seconds (healthy)
|
||||
api Up 44 seconds (healthy)
|
||||
postgres Up Less than a second (health: starting)
|
||||
valkey Up 3 seconds (health: starting)
|
||||
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080"
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -10,9 +10,9 @@ api Up Less than a second (health: starting)
|
||||
postgres Up Less than a second (health: starting)
|
||||
valkey Up Less than a second (health: starting)
|
||||
--- логи postgres о перезапуске ---
|
||||
postgres-1 | 2026-10-23 14:36:53.364 UTC [1] LOG: starting PostgreSQL 17.7 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 15.2.0) 15.2.0, 64-bit
|
||||
postgres-1 | 2026-10-23 14:36:53.364 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
|
||||
postgres-1 | 2026-10-23 14:36:53.364 UTC [1] LOG: listening on IPv6 address "::", port 5432
|
||||
postgres-1 | 2026-10-23 14:36:53.364 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
|
||||
postgres-1 | 2026-10-23 14:36:53.366 UTC [29] LOG: database system was shut down at 2026-10-23 14:36:53 UTC
|
||||
postgres-1 | 2026-10-23 14:36:53.368 UTC [1] LOG: database system is ready to accept connections
|
||||
postgres-1 | 2026-10-23 20:11:06.649 UTC [1] LOG: starting PostgreSQL 17.7 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 15.2.0) 15.2.0, 64-bit
|
||||
postgres-1 | 2026-10-23 20:11:06.649 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
|
||||
postgres-1 | 2026-10-23 20:11:06.649 UTC [1] LOG: listening on IPv6 address "::", port 5432
|
||||
postgres-1 | 2026-10-23 20:11:06.650 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
|
||||
postgres-1 | 2026-10-23 20:11:06.652 UTC [29] LOG: database system was shut down at 2026-10-23 20:11:06 UTC
|
||||
postgres-1 | 2026-10-23 20:11:06.654 UTC [1] LOG: database system is ready to accept connections
|
||||
|
||||
+2
-2
@@ -8,9 +8,9 @@ PostgreSQL 17.7 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 15.2.0) 1
|
||||
Valkey server v=8.1.10 sha=00000000:1 malloc=jemalloc-5.3.0 bits=64 build=2cb63ac0e4567989
|
||||
--- строка старта API: действующие лимиты и TTL ---
|
||||
api-1 | INFO: Waiting for application startup.
|
||||
api-1 | 2026-10-23 14:36:14,347 INFO messenger started: instance=9b4feca99e44 session_store=postgres session_ttl=3600 cache_ttl=30 pool=1..10 max_inflight=64 max_body=65536
|
||||
api-1 | 2026-10-23 20:10:21,987 INFO messenger started: instance=b9f88891f2b8 session_store=postgres session_ttl=3600 cache_ttl=30 pool=1..10 max_inflight=64 max_body=65536
|
||||
api-1 | INFO: Application startup complete.
|
||||
api-1 | INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
|
||||
api-1 | INFO: 172.18.0.1:56506 - "GET /health/ready HTTP/1.1" 200 OK
|
||||
api-1 | INFO: 172.18.0.1:57028 - "GET /health/ready HTTP/1.1" 200 OK
|
||||
--- сверка .env с .env.example ---
|
||||
ready: .env and secrets/ created locally; they stay out of Git
|
||||
|
||||
+60
-60
@@ -8,7 +8,7 @@ Docker version 29.7.2, build a7dcaa6
|
||||
=== 1. Засев истории: цель 120000 сообщений, чаты неравномерные ===
|
||||
seed_duration | seeded_rows | target_total | messages_total
|
||||
-----------------+-------------+--------------+----------------
|
||||
00:00:00.616654 | 67113 | 120000 | 120000
|
||||
00:00:00.637022 | 66707 | 120000 | 120000
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -26,15 +26,15 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..47.47 rows=50 width=90) (actual time=0.009..0.020 rows=50 loops=1)
|
||||
Buffers: shared hit=54
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.42..6827.62 rows=7255 width=90) (actual time=0.008..0.018 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 14:37:21.481035+00'::timestamp with time zone, 'b34cffc1-608f-4281-89b6-d598a0000a8d'::uuid)))
|
||||
Buffers: shared hit=54
|
||||
Limit (cost=0.42..52.46 rows=50 width=89) (actual time=0.015..0.024 rows=50 loops=1)
|
||||
Buffers: shared hit=53
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.42..7478.52 rows=7184 width=89) (actual time=0.014..0.021 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 20:11:34.584521+00'::timestamp with time zone, 'aa6010bb-02c6-4d17-986b-0f5103547576'::uuid)))
|
||||
Buffers: shared hit=53
|
||||
Planning:
|
||||
Buffers: shared hit=19
|
||||
Planning Time: 0.086 ms
|
||||
Execution Time: 0.042 ms
|
||||
Planning Time: 0.097 ms
|
||||
Execution Time: 0.047 ms
|
||||
(9 rows)
|
||||
|
||||
pages_measured
|
||||
@@ -44,46 +44,46 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
hundred_pages_duration
|
||||
------------------------
|
||||
00:00:00.00105
|
||||
00:00:00.001077
|
||||
(1 row)
|
||||
|
||||
insert_10k_duration
|
||||
---------------------
|
||||
00:00:00.083522
|
||||
00:00:00.085221
|
||||
(1 row)
|
||||
|
||||
############ Вариант B: только (chat_id) ############
|
||||
index_size
|
||||
------------
|
||||
848 kB
|
||||
856 kB
|
||||
(1 row)
|
||||
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=3231.76..3231.89 rows=50 width=90) (actual time=1.856..1.860 rows=50 loops=1)
|
||||
Buffers: shared hit=451 read=33
|
||||
I/O Timings: shared read=0.074
|
||||
-> Sort (cost=3231.76..3249.63 rows=7146 width=90) (actual time=1.855..1.857 rows=50 loops=1)
|
||||
Limit (cost=3274.42..3274.55 rows=50 width=90) (actual time=2.027..2.031 rows=50 loops=1)
|
||||
Buffers: shared hit=475 read=35
|
||||
I/O Timings: shared read=0.088
|
||||
-> Sort (cost=3274.42..3292.14 rows=7088 width=90) (actual time=2.026..2.028 rows=50 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 33kB
|
||||
Buffers: shared hit=451 read=33
|
||||
I/O Timings: shared read=0.074
|
||||
-> Bitmap Heap Scan on messages (cost=408.67..2994.38 rows=7146 width=90) (actual time=1.514..1.710 rows=3630 loops=1)
|
||||
Recheck Cond: (chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid)
|
||||
Filter: (ROW(created_at, id) > ROW('2026-10-23 14:37:21.481035+00'::timestamp with time zone, 'b34cffc1-608f-4281-89b6-d598a0000a8d'::uuid))
|
||||
Rows Removed by Filter: 32675
|
||||
Heap Blocks: exact=451
|
||||
Buffers: shared hit=451 read=33
|
||||
I/O Timings: shared read=0.074
|
||||
-> Bitmap Index Scan on messages_chat_only_idx (cost=0.00..406.88 rows=36612 width=0) (actual time=0.362..0.362 rows=36305 loops=1)
|
||||
Index Cond: (chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid)
|
||||
Buffers: shared read=33
|
||||
I/O Timings: shared read=0.074
|
||||
Buffers: shared hit=475 read=35
|
||||
I/O Timings: shared read=0.088
|
||||
-> Bitmap Heap Scan on messages (cost=428.23..3038.96 rows=7088 width=90) (actual time=1.631..1.839 rows=3829 loops=1)
|
||||
Recheck Cond: (chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid)
|
||||
Filter: (ROW(created_at, id) > ROW('2026-10-23 20:11:34.584521+00'::timestamp with time zone, 'aa6010bb-02c6-4d17-986b-0f5103547576'::uuid))
|
||||
Rows Removed by Filter: 34464
|
||||
Heap Blocks: exact=475
|
||||
Buffers: shared hit=475 read=35
|
||||
I/O Timings: shared read=0.088
|
||||
-> Bitmap Index Scan on messages_chat_only_idx (cost=0.00..426.46 rows=38156 width=0) (actual time=0.397..0.397 rows=38293 loops=1)
|
||||
Index Cond: (chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid)
|
||||
Buffers: shared read=35
|
||||
I/O Timings: shared read=0.088
|
||||
Planning:
|
||||
Buffers: shared hit=28 read=1
|
||||
Buffers: shared hit=27 read=1
|
||||
I/O Timings: shared read=0.009
|
||||
Planning Time: 0.126 ms
|
||||
Execution Time: 1.879 ms
|
||||
Planning Time: 0.123 ms
|
||||
Execution Time: 2.056 ms
|
||||
(24 rows)
|
||||
|
||||
pages_measured
|
||||
@@ -93,12 +93,12 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
hundred_pages_duration
|
||||
------------------------
|
||||
00:00:02.460907
|
||||
00:00:02.52905
|
||||
(1 row)
|
||||
|
||||
insert_10k_duration
|
||||
---------------------
|
||||
00:00:00.077769
|
||||
00:00:00.080589
|
||||
(1 row)
|
||||
|
||||
############ Вариант C: (chat_id, created_at, id) INCLUDE (sender_id, text) ############
|
||||
@@ -109,19 +109,19 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..43.36 rows=50 width=90) (actual time=0.039..0.045 rows=50 loops=1)
|
||||
Limit (cost=0.42..45.99 rows=50 width=89) (actual time=0.014..0.018 rows=50 loops=1)
|
||||
Buffers: shared hit=1 read=3
|
||||
I/O Timings: shared read=0.012
|
||||
-> Index Only Scan using messages_history_covering_idx on messages (cost=0.42..6095.87 rows=7098 width=90) (actual time=0.038..0.041 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 14:37:21.481035+00'::timestamp with time zone, 'b34cffc1-608f-4281-89b6-d598a0000a8d'::uuid)))
|
||||
I/O Timings: shared read=0.005
|
||||
-> Index Only Scan using messages_history_covering_idx on messages (cost=0.42..6560.61 rows=7197 width=89) (actual time=0.013..0.015 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '69ee7d45-68b4-4606-befe-efaeecdedd32'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 20:11:34.584521+00'::timestamp with time zone, 'aa6010bb-02c6-4d17-986b-0f5103547576'::uuid)))
|
||||
Heap Fetches: 0
|
||||
Buffers: shared hit=1 read=3
|
||||
I/O Timings: shared read=0.012
|
||||
I/O Timings: shared read=0.005
|
||||
Planning:
|
||||
Buffers: shared hit=29 read=1
|
||||
I/O Timings: shared read=0.007
|
||||
Planning Time: 0.144 ms
|
||||
Execution Time: 0.056 ms
|
||||
Buffers: shared hit=28 read=1
|
||||
I/O Timings: shared read=0.003
|
||||
Planning Time: 0.118 ms
|
||||
Execution Time: 0.027 ms
|
||||
(13 rows)
|
||||
|
||||
pages_measured
|
||||
@@ -131,12 +131,12 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
hundred_pages_duration
|
||||
------------------------
|
||||
00:00:00.000723
|
||||
00:00:00.000734
|
||||
(1 row)
|
||||
|
||||
insert_10k_duration
|
||||
---------------------
|
||||
00:00:00.085783
|
||||
00:00:00.08596
|
||||
(1 row)
|
||||
|
||||
############ Схема после эксперимента (ROLLBACK вернул индексы) ############
|
||||
@@ -147,7 +147,7 @@ Docker version 29.7.2, build a7dcaa6
|
||||
(2 rows)
|
||||
|
||||
|
||||
Самый большой чат: 174a0477-1fd5-47a9-ab90-ee8b7ef903af
|
||||
Самый большой чат: 69ee7d45-68b4-4606-befe-efaeecdedd32
|
||||
|
||||
=== 3. Состояние источника до бэкапа ===
|
||||
relation | rows
|
||||
@@ -156,19 +156,19 @@ Docker version 29.7.2, build a7dcaa6
|
||||
chats | 68
|
||||
messages | 120000
|
||||
sessions | 45
|
||||
users | 76
|
||||
users | 78
|
||||
(5 rows)
|
||||
|
||||
big_chat_rows | big_chat_md5
|
||||
---------------+----------------------------------
|
||||
36305 | 1841fdf890f6207bc78cb973bedeec27
|
||||
38293 | f18725746ed1acbdda044e804cdc4c7c
|
||||
(1 row)
|
||||
|
||||
id | created_at | text
|
||||
--------------------------------------+-------------------------------+----------
|
||||
1d15f9ed-952e-45e7-9553-dcd3bc3dd76e | 2026-10-23 14:36:54.449674+00 | load-2-0
|
||||
4bc8c702-07e1-42d2-be14-8cdd6dad31a7 | 2026-10-23 14:36:54.450312+00 | load-0-0
|
||||
3993ceca-7c29-400d-a1e9-287137672829 | 2026-10-23 14:36:54.450773+00 | load-1-0
|
||||
39cb2935-f53c-4e54-a75d-8b197126a6b4 | 2026-10-23 20:11:07.699544+00 | load-3-0
|
||||
62d3d8a1-fdaa-4a6c-812f-79ef268ada42 | 2026-10-23 20:11:07.700168+00 | load-1-0
|
||||
4fa775f1-6033-4d84-9e6c-0f39844e6201 | 2026-10-23 20:11:07.700828+00 | load-0-0
|
||||
(3 rows)
|
||||
|
||||
marker_rows
|
||||
@@ -178,7 +178,7 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
|
||||
=== 4. Бэкап pg_dump -Fc ===
|
||||
backup_seconds=0.741
|
||||
backup_seconds=0.743
|
||||
dump_size=5.7M
|
||||
|
||||
=== 5. Запись после бэкапа: граница потери данных ===
|
||||
@@ -188,7 +188,7 @@ dump_size=5.7M
|
||||
/var/run/postgresql:5432 - accepting connections
|
||||
|
||||
=== 7. Восстановление в новое хранилище ===
|
||||
restore_seconds=0.357
|
||||
restore_seconds=0.354
|
||||
|
||||
=== 8. Сверка восстановленной копии ===
|
||||
relation | rows
|
||||
@@ -197,19 +197,19 @@ restore_seconds=0.357
|
||||
chats | 68
|
||||
messages | 120000
|
||||
sessions | 45
|
||||
users | 76
|
||||
users | 78
|
||||
(5 rows)
|
||||
|
||||
big_chat_rows | big_chat_md5
|
||||
---------------+----------------------------------
|
||||
36305 | 1841fdf890f6207bc78cb973bedeec27
|
||||
38293 | f18725746ed1acbdda044e804cdc4c7c
|
||||
(1 row)
|
||||
|
||||
id | created_at | text
|
||||
--------------------------------------+-------------------------------+----------
|
||||
1d15f9ed-952e-45e7-9553-dcd3bc3dd76e | 2026-10-23 14:36:54.449674+00 | load-2-0
|
||||
4bc8c702-07e1-42d2-be14-8cdd6dad31a7 | 2026-10-23 14:36:54.450312+00 | load-0-0
|
||||
3993ceca-7c29-400d-a1e9-287137672829 | 2026-10-23 14:36:54.450773+00 | load-1-0
|
||||
39cb2935-f53c-4e54-a75d-8b197126a6b4 | 2026-10-23 20:11:07.699544+00 | load-3-0
|
||||
62d3d8a1-fdaa-4a6c-812f-79ef268ada42 | 2026-10-23 20:11:07.700168+00 | load-1-0
|
||||
4fa775f1-6033-4d84-9e6c-0f39844e6201 | 2026-10-23 20:11:07.700828+00 | load-0-0
|
||||
(3 rows)
|
||||
|
||||
marker_rows
|
||||
@@ -219,9 +219,9 @@ restore_seconds=0.357
|
||||
|
||||
|
||||
=== 9. Итог ===
|
||||
backup_seconds=0.741 restore_seconds=0.357
|
||||
backup_seconds=0.743 restore_seconds=0.354
|
||||
messages_source_without_marker=120000 messages_restored=120000
|
||||
big_chat_md5_source=1841fdf890f6207bc78cb973bedeec27
|
||||
big_chat_md5_restored=1841fdf890f6207bc78cb973bedeec27
|
||||
big_chat_md5_source=f18725746ed1acbdda044e804cdc4c7c
|
||||
big_chat_md5_restored=f18725746ed1acbdda044e804cdc4c7c
|
||||
RESULT: восстановленная копия совпадает с источником на момент бэкапа
|
||||
маркеров после бэкапа в восстановленной копии: 0 (ожидается 0: всё, что подтверждено после снимка, в дампе отсутствует)
|
||||
|
||||
Reference in New Issue
Block a user