Исправление по замечанию: кэш сессий наполняется после промаха
This commit is contained in:
@@ -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 31 seconds (healthy)
|
||||
api Up 32 seconds (healthy)
|
||||
valkey Up Less than a second (health: starting)
|
||||
PASS readiness_reports_the_outage
|
||||
PASS writes_fail_with_503
|
||||
@@ -25,5 +25,5 @@ PASS login_fails_closed
|
||||
|
||||
=== 3. Состояние восстановлено ===
|
||||
api Up 38 seconds (healthy)
|
||||
postgres Up Less than a second (health: starting)
|
||||
postgres Up 3 seconds (health: starting)
|
||||
valkey Up 7 seconds (healthy)
|
||||
|
||||
+36
-36
@@ -7,7 +7,7 @@ valkey valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682f
|
||||
=== Засев 10000 сообщений с неравномерными чатами ===
|
||||
seed_duration | seeded_rows | target_total | messages_total
|
||||
-----------------+-------------+--------------+----------------
|
||||
00:00:00.001309 | 0 | 10000 | 53764
|
||||
00:00:00.000975 | 0 | 10000 | 52887
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -19,70 +19,70 @@ valkey valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682f
|
||||
|
||||
messages_total | chats_with_messages | table_size | indexes_size
|
||||
----------------+---------------------+------------+--------------
|
||||
53764 | 14 | 5368 kB | 6320 kB
|
||||
52887 | 14 | 5280 kB | 7024 kB
|
||||
(1 row)
|
||||
|
||||
--- распределение истории по чатам: 5 самых больших и 5 самых маленьких ---
|
||||
chat_id | rows
|
||||
--------------------------------------+-------
|
||||
e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32 | 32944
|
||||
c995246c-35ed-422d-b097-c71f8829a0e0 | 20775
|
||||
d73dc509-7b93-4fc3-b6de-b7079bcc294f | 25
|
||||
7485e75e-455e-4a7b-b164-3dbc84099fc0 | 5
|
||||
63d536a7-78d4-4502-92fa-9bbac4e7c5c4 | 3
|
||||
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
|
||||
(5 rows)
|
||||
|
||||
chat_id | rows
|
||||
--------------------------------------+------
|
||||
143b0ced-4c1a-4742-a4ad-02c4b606ba0f | 1
|
||||
b4faa937-91fc-4f41-b25e-f3f692878c1f | 1
|
||||
84d473db-544b-4a24-995b-43a4852c68ab | 1
|
||||
574fc146-1610-484a-85a9-cb084afa7d28 | 1
|
||||
836ed5bf-8ccb-419e-96d5-2c4fe7342292 | 1
|
||||
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
|
||||
(5 rows)
|
||||
|
||||
--- A. keyset, первая страница самого большого чата ---
|
||||
QUERY PLAN
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.41..6.89 rows=50 width=67) (actual time=0.006..0.016 rows=50 loops=1)
|
||||
Buffers: shared hit=24
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..4269.16 rows=32968 width=67) (actual time=0.006..0.014 rows=50 loops=1)
|
||||
Index Cond: (chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid)
|
||||
Buffers: shared hit=24
|
||||
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
|
||||
Planning:
|
||||
Buffers: shared hit=6
|
||||
Planning Time: 0.046 ms
|
||||
Execution Time: 0.026 ms
|
||||
Buffers: shared hit=8
|
||||
Planning Time: 0.049 ms
|
||||
Execution Time: 0.018 ms
|
||||
(9 rows)
|
||||
|
||||
--- B. keyset, страница на глубине 90% истории (так работает cursor API) ---
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.41..11.51 rows=50 width=67) (actual time=0.017..0.025 rows=50 loops=1)
|
||||
Buffers: shared hit=53
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..3272.65 rows=14746 width=67) (actual time=0.017..0.023 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid) AND (ROW(created_at, id) > ROW('2026-10-19 15:51:38.025965+00'::timestamp with time zone, '0375fd16-e024-4391-93a5-0d5a1a21786d'::uuid)))
|
||||
Buffers: shared hit=53
|
||||
Planning Time: 0.027 ms
|
||||
Execution Time: 0.063 ms
|
||||
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
|
||||
(7 rows)
|
||||
|
||||
--- C. OFFSET на той же глубине (так API не делает: цена растёт со страницей) ---
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=3839.41..3845.89 rows=50 width=67) (actual time=4.152..4.159 rows=50 loops=1)
|
||||
Buffers: shared hit=29813
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..4269.16 rows=32968 width=67) (actual time=0.008..3.474 rows=29699 loops=1)
|
||||
Index Cond: (chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid)
|
||||
Buffers: shared hit=29813
|
||||
Planning Time: 0.018 ms
|
||||
Execution Time: 4.172 ms
|
||||
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
|
||||
(7 rows)
|
||||
|
||||
--- индексы таблицы messages ---
|
||||
index | size | scans
|
||||
----------------------+---------+-------
|
||||
messages_history_idx | 4072 kB | 12
|
||||
messages_pkey | 2248 kB | 0
|
||||
messages_history_idx | 4720 kB | 12
|
||||
messages_pkey | 2304 kB | 0
|
||||
(2 rows)
|
||||
|
||||
|
||||
+15
-26
@@ -1,30 +1,19 @@
|
||||
M .env.example
|
||||
M Makefile
|
||||
M REPORT.md
|
||||
?? .github/workflows/app.yml
|
||||
?? Dockerfile
|
||||
?? app/
|
||||
?? compose.yaml
|
||||
?? evidence/dependency.txt
|
||||
?? evidence/expiry.txt
|
||||
?? evidence/explain-10k.txt
|
||||
?? evidence/git-hygiene.txt
|
||||
?? evidence/level4-tests.txt
|
||||
?? evidence/load-cache.json
|
||||
?? evidence/load-nocache.json
|
||||
?? evidence/load.txt
|
||||
?? evidence/migrations.txt
|
||||
?? evidence/outages.txt
|
||||
?? evidence/persistence.txt
|
||||
?? evidence/smoke.txt
|
||||
?? evidence/stand.txt
|
||||
?? evidence/track2/
|
||||
?? migrations/
|
||||
?? requirements.txt
|
||||
?? scripts/bootstrap.sh
|
||||
?? scripts/migrate.py
|
||||
?? scripts/restart.sh
|
||||
?? student-tests/
|
||||
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
|
||||
--- правила игнорирования ---
|
||||
.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.012,
|
||||
"elapsed_seconds": 30.013,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 32944,
|
||||
"successful_requests": 36305,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 1097.706,
|
||||
"successful_rps": 1209.659,
|
||||
"successful_latency_ms": {
|
||||
"p50": 3.248,
|
||||
"p95": 6.063,
|
||||
"p99": 10.603
|
||||
"p50": 3.13,
|
||||
"p95": 4.568,
|
||||
"p99": 6.509
|
||||
},
|
||||
"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.033,
|
||||
"elapsed_seconds": 30.016,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 20775,
|
||||
"successful_requests": 16537,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 691.741,
|
||||
"successful_rps": 550.943,
|
||||
"successful_latency_ms": {
|
||||
"p50": 5.447,
|
||||
"p95": 8.152,
|
||||
"p99": 11.778
|
||||
"p50": 6.908,
|
||||
"p95": 9.405,
|
||||
"p99": 12.388
|
||||
},
|
||||
"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.012,
|
||||
"elapsed_seconds": 30.013,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 32944,
|
||||
"successful_requests": 36305,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 1097.706,
|
||||
"successful_rps": 1209.659,
|
||||
"successful_latency_ms": {
|
||||
"p50": 3.248,
|
||||
"p95": 6.063,
|
||||
"p99": 10.603
|
||||
"p50": 3.13,
|
||||
"p95": 4.568,
|
||||
"p99": 6.509
|
||||
},
|
||||
"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.033,
|
||||
"elapsed_seconds": 30.016,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 20775,
|
||||
"successful_requests": 16537,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 691.741,
|
||||
"successful_rps": 550.943,
|
||||
"successful_latency_ms": {
|
||||
"p50": 5.447,
|
||||
"p95": 8.152,
|
||||
"p99": 11.778
|
||||
"p50": 6.908,
|
||||
"p95": 9.405,
|
||||
"p99": 12.388
|
||||
},
|
||||
"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-d04acc691283 Creating
|
||||
Container mtusi-lab2-migrate-run-d04acc691283 Created
|
||||
Container mtusi-lab2-migrate-run-6c5706582141 Creating
|
||||
Container mtusi-lab2-migrate-run-6c5706582141 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-19 15:50:30.673311+00
|
||||
0001_init | 4fd0a8c68a5cffd3ae67a21646eb1928477d18b8716e68c1220469d858ccb9c1 | 2026-10-23 14:36:13.656522+00
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
PASS revoked_session_stays_revoked_after_cache_restart
|
||||
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 hung_database_fails_fast
|
||||
4/4 checks passed
|
||||
6/6 checks passed
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--- состояние контейнеров до рестарта ---
|
||||
api Up 38 seconds (healthy)
|
||||
postgres Up Less than a second (health: starting)
|
||||
api Up 39 seconds (healthy)
|
||||
postgres Up 3 seconds (health: starting)
|
||||
valkey Up 7 seconds (healthy)
|
||||
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.
|
||||
@@ -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-19 15:51:09.945 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-19 15:51:09.945 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
|
||||
postgres-1 | 2026-10-19 15:51:09.945 UTC [1] LOG: listening on IPv6 address "::", port 5432
|
||||
postgres-1 | 2026-10-19 15:51:09.946 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
|
||||
postgres-1 | 2026-10-19 15:51:09.949 UTC [29] LOG: database system was shut down at 2026-10-19 15:51:09 UTC
|
||||
postgres-1 | 2026-10-19 15:51:09.951 UTC [1] LOG: database system is ready to accept connections
|
||||
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
|
||||
|
||||
@@ -6,3 +6,11 @@ postgres postgres:17.7-alpine@sha256:bb377b7239d2774ac8cc76f481596ce96c5a6b5e9d1
|
||||
valkey valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682fd35e1ebb4b0990a4a4a8507 Up 7 seconds (healthy)
|
||||
PostgreSQL 17.7 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 15.2.0) 15.2.0, 64-bit
|
||||
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 | 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
|
||||
--- сверка .env с .env.example ---
|
||||
ready: .env and secrets/ created locally; they stay out of Git
|
||||
|
||||
+66
-66
@@ -6,9 +6,9 @@ Darwin arm64
|
||||
Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
=== 1. Засев истории: цель 120000 сообщений, чаты неравномерные ===
|
||||
seed_duration | seeded_rows | target_total | messages_total
|
||||
----------------+-------------+--------------+----------------
|
||||
00:00:00.63315 | 66236 | 120000 | 120000
|
||||
seed_duration | seeded_rows | target_total | messages_total
|
||||
-----------------+-------------+--------------+----------------
|
||||
00:00:00.616654 | 67113 | 120000 | 120000
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -21,20 +21,20 @@ Docker version 29.7.2, build a7dcaa6
|
||||
############ Вариант A: messages_history_idx (chat_id, created_at, id) ############
|
||||
index_size
|
||||
------------
|
||||
10 MB
|
||||
11 MB
|
||||
(1 row)
|
||||
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..37.36 rows=50 width=89) (actual time=0.015..0.025 rows=50 loops=1)
|
||||
Buffers: shared hit=53
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.42..5594.06 rows=7570 width=89) (actual time=0.014..0.022 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid) AND (ROW(created_at, id) > ROW('2026-10-19 15:51:38.025965+00'::timestamp with time zone, '0375fd16-e024-4391-93a5-0d5a1a21786d'::uuid)))
|
||||
Buffers: shared hit=53
|
||||
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
|
||||
Planning:
|
||||
Buffers: shared hit=17
|
||||
Planning Time: 0.098 ms
|
||||
Execution Time: 0.048 ms
|
||||
Buffers: shared hit=19
|
||||
Planning Time: 0.086 ms
|
||||
Execution Time: 0.042 ms
|
||||
(9 rows)
|
||||
|
||||
pages_measured
|
||||
@@ -44,12 +44,12 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
hundred_pages_duration
|
||||
------------------------
|
||||
00:00:00.001121
|
||||
00:00:00.00105
|
||||
(1 row)
|
||||
|
||||
insert_10k_duration
|
||||
---------------------
|
||||
00:00:00.083689
|
||||
00:00:00.083522
|
||||
(1 row)
|
||||
|
||||
############ Вариант B: только (chat_id) ############
|
||||
@@ -60,30 +60,30 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=3134.85..3134.97 rows=50 width=89) (actual time=1.691..1.695 rows=50 loops=1)
|
||||
Buffers: shared hit=411 read=30
|
||||
I/O Timings: shared read=0.076
|
||||
-> Sort (cost=3134.85..3153.65 rows=7522 width=89) (actual time=1.691..1.692 rows=50 loops=1)
|
||||
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)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 33kB
|
||||
Buffers: shared hit=411 read=30
|
||||
I/O Timings: shared read=0.076
|
||||
-> Bitmap Heap Scan on messages (cost=368.71..2884.97 rows=7522 width=89) (actual time=1.378..1.560 rows=3294 loops=1)
|
||||
Recheck Cond: (chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid)
|
||||
Filter: (ROW(created_at, id) > ROW('2026-10-19 15:51:38.025965+00'::timestamp with time zone, '0375fd16-e024-4391-93a5-0d5a1a21786d'::uuid))
|
||||
Rows Removed by Filter: 29650
|
||||
Heap Blocks: exact=411
|
||||
Buffers: shared hit=411 read=30
|
||||
I/O Timings: shared read=0.076
|
||||
-> Bitmap Index Scan on messages_chat_only_idx (cost=0.00..366.83 rows=32872 width=0) (actual time=0.333..0.333 rows=32944 loops=1)
|
||||
Index Cond: (chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid)
|
||||
Buffers: shared read=30
|
||||
I/O Timings: shared read=0.076
|
||||
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
|
||||
Planning:
|
||||
Buffers: shared hit=26 read=1
|
||||
Buffers: shared hit=28 read=1
|
||||
I/O Timings: shared read=0.009
|
||||
Planning Time: 0.130 ms
|
||||
Execution Time: 1.728 ms
|
||||
Planning Time: 0.126 ms
|
||||
Execution Time: 1.879 ms
|
||||
(24 rows)
|
||||
|
||||
pages_measured
|
||||
@@ -93,12 +93,12 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
hundred_pages_duration
|
||||
------------------------
|
||||
00:00:02.186353
|
||||
00:00:02.460907
|
||||
(1 row)
|
||||
|
||||
insert_10k_duration
|
||||
---------------------
|
||||
00:00:00.078473
|
||||
00:00:00.077769
|
||||
(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..34.19 rows=50 width=89) (actual time=0.017..0.021 rows=50 loops=1)
|
||||
Limit (cost=0.42..43.36 rows=50 width=90) (actual time=0.039..0.045 rows=50 loops=1)
|
||||
Buffers: shared hit=1 read=3
|
||||
I/O Timings: shared read=0.006
|
||||
-> Index Only Scan using messages_history_covering_idx on messages (cost=0.42..5110.68 rows=7565 width=89) (actual time=0.016..0.019 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid) AND (ROW(created_at, id) > ROW('2026-10-19 15:51:38.025965+00'::timestamp with time zone, '0375fd16-e024-4391-93a5-0d5a1a21786d'::uuid)))
|
||||
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)))
|
||||
Heap Fetches: 0
|
||||
Buffers: shared hit=1 read=3
|
||||
I/O Timings: shared read=0.006
|
||||
I/O Timings: shared read=0.012
|
||||
Planning:
|
||||
Buffers: shared hit=28 read=1
|
||||
I/O Timings: shared read=0.005
|
||||
Planning Time: 0.184 ms
|
||||
Execution Time: 0.031 ms
|
||||
Buffers: shared hit=29 read=1
|
||||
I/O Timings: shared read=0.007
|
||||
Planning Time: 0.144 ms
|
||||
Execution Time: 0.056 ms
|
||||
(13 rows)
|
||||
|
||||
pages_measured
|
||||
@@ -131,12 +131,12 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
hundred_pages_duration
|
||||
------------------------
|
||||
00:00:00.000744
|
||||
00:00:00.000723
|
||||
(1 row)
|
||||
|
||||
insert_10k_duration
|
||||
---------------------
|
||||
00:00:00.084611
|
||||
00:00:00.085783
|
||||
(1 row)
|
||||
|
||||
############ Схема после эксперимента (ROLLBACK вернул индексы) ############
|
||||
@@ -147,7 +147,7 @@ Docker version 29.7.2, build a7dcaa6
|
||||
(2 rows)
|
||||
|
||||
|
||||
Самый большой чат: e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32
|
||||
Самый большой чат: 174a0477-1fd5-47a9-ab90-ee8b7ef903af
|
||||
|
||||
=== 3. Состояние источника до бэкапа ===
|
||||
relation | rows
|
||||
@@ -155,20 +155,20 @@ Docker version 29.7.2, build a7dcaa6
|
||||
chat_members | 1036
|
||||
chats | 68
|
||||
messages | 120000
|
||||
sessions | 43
|
||||
users | 74
|
||||
sessions | 45
|
||||
users | 76
|
||||
(5 rows)
|
||||
|
||||
big_chat_rows | big_chat_md5
|
||||
---------------+----------------------------------
|
||||
32944 | 6c6725a76404fbb0b8b5b509707e30b5
|
||||
36305 | 1841fdf890f6207bc78cb973bedeec27
|
||||
(1 row)
|
||||
|
||||
id | created_at | text
|
||||
--------------------------------------+-------------------------------+----------
|
||||
8ecedfe9-56ef-410d-98b3-e3fc414128d9 | 2026-10-19 15:51:11.010631+00 | load-1-0
|
||||
424bfa46-6e49-4b60-8ca3-ac3c3f9be02a | 2026-10-19 15:51:11.011234+00 | load-3-0
|
||||
05b0e1a2-5862-461a-b8aa-1f91f647e18d | 2026-10-19 15:51:11.01201+00 | load-2-0
|
||||
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
|
||||
(3 rows)
|
||||
|
||||
marker_rows
|
||||
@@ -178,8 +178,8 @@ Docker version 29.7.2, build a7dcaa6
|
||||
|
||||
|
||||
=== 4. Бэкап pg_dump -Fc ===
|
||||
backup_seconds=0.761
|
||||
dump_size=5.6M
|
||||
backup_seconds=0.741
|
||||
dump_size=5.7M
|
||||
|
||||
=== 5. Запись после бэкапа: граница потери данных ===
|
||||
в источнике маркеров: 1
|
||||
@@ -188,7 +188,7 @@ dump_size=5.6M
|
||||
/var/run/postgresql:5432 - accepting connections
|
||||
|
||||
=== 7. Восстановление в новое хранилище ===
|
||||
restore_seconds=0.370
|
||||
restore_seconds=0.357
|
||||
|
||||
=== 8. Сверка восстановленной копии ===
|
||||
relation | rows
|
||||
@@ -196,20 +196,20 @@ restore_seconds=0.370
|
||||
chat_members | 1036
|
||||
chats | 68
|
||||
messages | 120000
|
||||
sessions | 43
|
||||
users | 74
|
||||
sessions | 45
|
||||
users | 76
|
||||
(5 rows)
|
||||
|
||||
big_chat_rows | big_chat_md5
|
||||
---------------+----------------------------------
|
||||
32944 | 6c6725a76404fbb0b8b5b509707e30b5
|
||||
36305 | 1841fdf890f6207bc78cb973bedeec27
|
||||
(1 row)
|
||||
|
||||
id | created_at | text
|
||||
--------------------------------------+-------------------------------+----------
|
||||
8ecedfe9-56ef-410d-98b3-e3fc414128d9 | 2026-10-19 15:51:11.010631+00 | load-1-0
|
||||
424bfa46-6e49-4b60-8ca3-ac3c3f9be02a | 2026-10-19 15:51:11.011234+00 | load-3-0
|
||||
05b0e1a2-5862-461a-b8aa-1f91f647e18d | 2026-10-19 15:51:11.01201+00 | load-2-0
|
||||
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
|
||||
(3 rows)
|
||||
|
||||
marker_rows
|
||||
@@ -219,9 +219,9 @@ restore_seconds=0.370
|
||||
|
||||
|
||||
=== 9. Итог ===
|
||||
backup_seconds=0.761 restore_seconds=0.370
|
||||
backup_seconds=0.741 restore_seconds=0.357
|
||||
messages_source_without_marker=120000 messages_restored=120000
|
||||
big_chat_md5_source=6c6725a76404fbb0b8b5b509707e30b5
|
||||
big_chat_md5_restored=6c6725a76404fbb0b8b5b509707e30b5
|
||||
big_chat_md5_source=1841fdf890f6207bc78cb973bedeec27
|
||||
big_chat_md5_restored=1841fdf890f6207bc78cb973bedeec27
|
||||
RESULT: восстановленная копия совпадает с источником на момент бэкапа
|
||||
маркеров после бэкапа в восстановленной копии: 0 (ожидается 0: всё, что подтверждено после снимка, в дампе отсутствует)
|
||||
|
||||
Reference in New Issue
Block a user