Debian Codegraph @

src/test/isolation/specs/tuplelock-upgrade-no-deadlock.spec

raw
1 # This test checks that multiple sessions locking a single row in a table
2 # do not deadlock each other when one of them upgrades its existing lock
3 # while the others are waiting for it.
4
5 setup
6 {
7 drop table if exists tlu_job;
8 create table tlu_job (id integer primary key, name text);
9
10 insert into tlu_job values(1, 'a');
11 }
12
13
14 teardown
15 {
16 drop table tlu_job;
17 }
18
19 session s0
20 step s0_begin { begin; }
21 step s0_keyshare { select id from tlu_job where id = 1 for key share;}
22 step s0_rollback { rollback; }
23
24 session s1
25 setup { begin; }
26 step s1_keyshare { select id from tlu_job where id = 1 for key share;}
27 step s1_share { select id from tlu_job where id = 1 for share; }
28 step s1_fornokeyupd { select id from tlu_job where id = 1 for no key update; }
29 step s1_update { update tlu_job set name = 'b' where id = 1; }
30 step s1_savept_e { savepoint s1_e; }
31 step s1_savept_f { savepoint s1_f; }
32 step s1_rollback_e { rollback to s1_e; }
33 step s1_rollback_f { rollback to s1_f; }
34 step s1_rollback { rollback; }
35 step s1_commit { commit; }
36
37 session s2
38 setup { begin; }
39 step s2_for_keyshare { select id from tlu_job where id = 1 for key share; }
40 step s2_fornokeyupd { select id from tlu_job where id = 1 for no key update; }
41 step s2_for_update { select id from tlu_job where id = 1 for update; }
42 step s2_update { update tlu_job set name = 'b' where id = 1; }
43 step s2_delete { delete from tlu_job where id = 1; }
44 step s2_rollback { rollback; }
45
46 session s3
47 setup { begin; }
48 step s3_keyshare { select id from tlu_job where id = 1 for key share; }
49 step s3_share { select id from tlu_job where id = 1 for share; }
50 step s3_for_update { select id from tlu_job where id = 1 for update; }
51 step s3_update { update tlu_job set name = 'c' where id = 1; }
52 step s3_delete { delete from tlu_job where id = 1; }
53 step s3_rollback { rollback; }
54 step s3_commit { commit; }
55
56 # test that s2 will not deadlock with s3 when s1 is rolled back
57 permutation s1_share s2_for_update s3_share s3_for_update s1_rollback s3_rollback s2_rollback
58 # test that update does not cause deadlocks if it can proceed
59 permutation s1_keyshare s2_for_update s3_keyshare s1_update s3_update s1_rollback s3_rollback s2_rollback
60 permutation s1_keyshare s2_for_update s3_keyshare s1_update s3_update s1_commit s3_rollback s2_rollback
61 # test that delete does not cause deadlocks if it can proceed
62 permutation s1_keyshare s2_for_update s3_keyshare s3_delete s1_rollback s3_rollback s2_rollback
63 permutation s1_keyshare s2_for_update s3_keyshare s3_delete s1_rollback s3_commit s2_rollback
64 # test that sessions that don't upgrade locks acquire them in order
65 permutation s1_share s2_for_update s3_for_update s1_rollback s2_rollback s3_rollback
66 permutation s1_share s2_update s3_update s1_rollback s2_rollback s3_rollback
67 permutation s1_share s2_delete s3_delete s1_rollback s2_rollback s3_rollback
68 # test s2 retrying the overall tuple lock algorithm after initially avoiding deadlock
69 permutation s1_keyshare s3_for_update s2_for_keyshare s1_savept_e s1_share s1_savept_f s1_fornokeyupd s2_fornokeyupd s0_begin s0_keyshare s1_rollback_f s0_keyshare s1_rollback_e s1_rollback s2_rollback s0_rollback s3_rollback