Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
Parsed test spec with 3 sessions
 
starting permutation: reindex upd wake_reindex reindexed swapped wake_check checked rows orphan
injection_points_attach
-----------------------
                       
(1 row)
 
injection_points_attach
-----------------------
                       
(1 row)
 
step reindex: REINDEX INDEX CONCURRENTLY ri_pk_pkey; <waiting ...>
step upd: UPDATE ri_fk SET pid = 42 WHERE id = 1; <waiting ...>
step wake_reindex: 
    SELECT injection_points_detach('reindex-relation-concurrently-before-swap');
    SELECT injection_points_wakeup('reindex-relation-concurrently-before-swap');
 
injection_points_detach
-----------------------
                       
(1 row)
 
injection_points_wakeup
-----------------------
                       
(1 row)
 
step reindex: <... completed>
step reindexed: 
step swapped: 
    SELECT count(*) = 0 AS old_index_dropped
      FROM pg_class WHERE oid = (SELECT conindid FROM ri_old_index);
    SELECT conindid <> (SELECT conindid FROM ri_old_index) AS constraint_moved
      FROM pg_constraint WHERE conname = 'ri_fk_pid_fkey';
 
old_index_dropped
-----------------
t                
(1 row)
 
constraint_moved
----------------
t               
(1 row)
 
step wake_check: 
    SELECT injection_points_detach('ri-before-pk-lock');
    SELECT injection_points_wakeup('ri-before-pk-lock');
 
injection_points_detach
-----------------------
                       
(1 row)
 
injection_points_wakeup
-----------------------
                       
(1 row)
 
step upd: <... completed>
step checked: 
step rows: SELECT id, pid FROM ri_fk WHERE id IN (1, 2) ORDER BY id;
id|pid
--+---
 1| 42
 2|  2
(2 rows)
 
step orphan: INSERT INTO ri_fk VALUES (999, 12345);
ERROR:  insert or update on table "ri_fk" violates foreign key constraint "ri_fk_pid_fkey"
 
starting permutation: park_drop reindex upd_new wake_reindex await_drop dead wake_check checked wake_drop reindexed rows orphan
injection_points_attach
-----------------------
                       
(1 row)
 
injection_points_attach
-----------------------
                       
(1 row)
 
step park_drop: 
    SELECT injection_points_attach('reindex-relation-concurrently-before-drop', 'wait');
 
injection_points_attach
-----------------------
                       
(1 row)
 
step reindex: REINDEX INDEX CONCURRENTLY ri_pk_pkey; <waiting ...>
step upd_new: UPDATE ri_fk SET pid = 500 WHERE id = 1; <waiting ...>
step wake_reindex: 
    SELECT injection_points_detach('reindex-relation-concurrently-before-swap');
    SELECT injection_points_wakeup('reindex-relation-concurrently-before-swap');
 
injection_points_detach
-----------------------
                       
(1 row)
 
injection_points_wakeup
-----------------------
                       
(1 row)
 
step await_drop: 
    DO $$
    BEGIN
        LOOP
            PERFORM 1 FROM pg_stat_activity
              WHERE wait_event = 'reindex-relation-concurrently-before-drop';
            EXIT WHEN FOUND;
            PERFORM pg_sleep(.1);
        END LOOP;
    END
    $$;
 
step dead: 
    SELECT indisvalid, indisready, indislive
      FROM pg_index WHERE indexrelid = (SELECT conindid FROM ri_old_index);
    INSERT INTO ri_pk VALUES (500);
 
indisvalid|indisready|indislive
----------+----------+---------
f         |f         |f        
(1 row)
 
step wake_check: 
    SELECT injection_points_detach('ri-before-pk-lock');
    SELECT injection_points_wakeup('ri-before-pk-lock');
 
injection_points_detach
-----------------------
                       
(1 row)
 
injection_points_wakeup
-----------------------
                       
(1 row)
 
step upd_new: <... completed>
step checked: 
step wake_drop: 
    SELECT injection_points_detach('reindex-relation-concurrently-before-drop');
    SELECT injection_points_wakeup('reindex-relation-concurrently-before-drop');
 
injection_points_detach
-----------------------
                       
(1 row)
 
injection_points_wakeup
-----------------------
                       
(1 row)
 
step reindex: <... completed>
step reindexed: 
step rows: SELECT id, pid FROM ri_fk WHERE id IN (1, 2) ORDER BY id;
id|pid
--+---
 1|500
 2|  2
(2 rows)
 
step orphan: INSERT INTO ri_fk VALUES (999, 12345);
ERROR:  insert or update on table "ri_fk" violates foreign key constraint "ri_fk_pid_fkey"