Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 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
# Check that a canceled or terminated waiter does not leave a stale slot
# behind in the waiter array. A leaked slot would make later wakeups of
# the same injection point bump the leaked slot's counter instead of the
# real waiter's, leaving the real waiter stuck.
 
setup
{
    CREATE EXTENSION injection_points;
}
teardown
{
    DROP EXTENSION injection_points;
}
 
# The first waiter, that gets canceled or terminated.  This does not
# use injection_points_set_local() on purpose: the injection point
# must survive s1's termination so that s3 can still detach it.
session s1
setup   {
    SELECT injection_points_attach('injection-points-wait', 'wait');
}
step wait1  { SELECT injection_points_run('injection-points-wait'); }
 
# The second waiter, that receives a wakeup.
session s2
step wait2  { SELECT injection_points_run('injection-points-wait'); }
step noop2  { }
 
# Control session.  The blocker annotations on cancel3/terminate3,
# together with noop3, make the tester wait until wait1 has fully
# completed before starting wait2.  Otherwise, wait2 could register a
# new waiter slot while s1 still owns the previous one.
session s3
step cancel3    {
    SELECT pg_cancel_backend(pid) FROM pg_stat_activity
      WHERE wait_event = 'injection-points-wait';
}
step terminate3 {
    SELECT pg_terminate_backend(pid) FROM pg_stat_activity
      WHERE wait_event = 'injection-points-wait';
}
step wakeup3    { SELECT injection_points_wakeup('injection-points-wait'); }
step detach3    { SELECT injection_points_detach('injection-points-wait'); }
step noop3  { }
 
permutation wait1 cancel3(wait1) noop3 wait2 wakeup3 noop2 detach3
 
# The terminate permutation has to stay last: s1's connection is dead
# afterwards, and the tester never reconnects a session.
permutation wait1 terminate3(wait1) noop3 wait2 wakeup3 noop2 detach3