Debian Codegraph @

mysql-test/suite/ndb/t/ndb_tc_state.test

raw
1 -- source include/have_ndb.inc
2
3 # Regression test for TC state problem fixes
4 # Problem where TC retains state from previous aborted transactions
5 # which used deferred triggers for FK/UK maintenance.
6 # That state causes an issue for subsequent autocommit
7 # transactions where
8 # a The operation request has IgnoreError and Commit flags
9 # b The operation fails
10 #
11 # This test case reproduces the problem by :
12 # 1. Issuing a number of transactions which require deferred trigger
13 # maintenance (due to commit-time-checked FKs), but fail before
14 # commit (due to some other reason)
15 # 2. Issuing a number of autocommit transactions which meet the
16 # criteria a+b using both PK and UK access methods.
17
18 use test;
19
20 # Create tables in FK relationship to cause
21 # commit-time deferred trigger usage
22 #
23 create table parent (a int primary key, b int) engine=ndb;
24 create table child (a int primary key, b int, foreign key (a) references
25 parent(a)) engine=ndb;
26
27 # Create table using unique key
28 create table t1 (a int primary key, b int, c int, unique(b)) engine=ndb;
29
30 # Create one valid parent row
31 insert into parent values (1,1);
32
33
34 --let $cases=6
35 --let $case=0
36 # No PK insert case as MySQLD does not have a route to issuing
37 # an insert with IgnoreError and Commit flags set
38 # Can be done from NdbApi.
39
40 while ($case < $cases)
41 {
42 if ($case==0)
43 {
44 # PK update
45 --let $autocommit_stmt=update t1 set c=10 where a=
46 }
47 if ($case==1)
48 {
49 # PK delete
50 --let $autocommit_stmt=delete from t1 where a=
51 }
52 if ($case==2)
53 {
54 # PK select
55 --let $autocommit_stmt=select c from t1 where a=
56 }
57 if ($case==3)
58 {
59 # UK update
60 --let $autocommit_stmt=update t1 set c=20 where b=
61 }
62 if ($case==4)
63 {
64 # UK delete
65 --let $autocommit_stmt=delete from t1 where b=
66 }
67 if ($case==5)
68 {
69 # UK select
70 --let $autocommit_stmt=select c from t1 where b=
71 }
72
73 --echo Testing case $case : $autocommit_stmt
74
75
76 # Issue 10x transactions which fail + rollback due to duplicate PK.
77 # The first insert in each succeeds, and sets the ApiConnectRecord's
78 # TF_DEFERRED_FK flag indicating pre-commit deferred triggers should
79 # be fired.
80 # Initial (failing) select with varying key is done to give varied
81 # hinting.
82 # 10x is done to ensure that most transaction objects this session
83 # might pick up later are affected
84
85 let $i=10;
86 while ($i)
87 {
88 begin;
89 # Hint to somewhere
90 --eval select * from child where a=$i
91 insert into child values (1,1);
92 --error 1062
93 # Cause failure + rollback due to existing key
94 insert into child values (1,1);
95 dec $i;
96 }
97
98 # Now issue an autocommit operation which may reuse the TC side
99 # transaction object from above
100
101 # Multiple times to offset hinting effects
102 let $i=10;
103 while ($i)
104 {
105 --eval $autocommit_stmt$i
106 dec $i;
107 }
108
109 inc $case;
110 }
111
112 drop table t1;
113 drop table child;
114 drop table parent;
115