Исправление по замечанию: кэш сессий наполняется после промаха
Application / app (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
alenchha
2026-10-23 17:42:38 +03:00
parent a0c16afa33
commit 1a60b9cd1f
16 changed files with 263 additions and 194 deletions
+66 -66
View File
@@ -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: всё, что подтверждено после снимка, в дампе отсутствует)