4
4
use Config;
5
5
use PostgresNode;
6
6
use TestLib;
7
- use Test::Moretests => 59 ;
7
+ use Test::Moretests => 76 ;
8
8
9
9
use constant
10
10
{
11
- READ_COMMITTED => 0,
12
- REPEATABLE_READ => 1,
13
- SERIALIZABLE => 2,
11
+ READ_UNCOMMITTED => 0,
12
+ READ_COMMITTED => 1,
13
+ REPEATABLE_READ => 2,
14
+ SERIALIZABLE => 3,
14
15
};
15
16
16
- my @isolation_level_sql = (' read committed' ,' repeatable read' ,' serializable' );
17
- my @isolation_level_abbreviations = (' RC' ,' RR' ,' S' );
17
+ my @isolation_level_sql = (
18
+ ' read uncommitted' ,
19
+ ' read committed' ,
20
+ ' repeatable read' ,
21
+ ' serializable' );
22
+ my @isolation_level_abbreviations = (' RUC' ,' RC' ,' RR' ,' S' );
18
23
19
24
# The keys of advisory locks for testing deadlock failures:
20
25
use constant
21
26
{
22
- TRANSACTION_BEGINS => 3 ,
23
- DEADLOCK_1 => 4 ,
24
- WAIT_PGBENCH_2 => 5 ,
25
- DEADLOCK_2 => 6 ,
26
- TRANSACTION_ENDS => 7 ,
27
+ TRANSACTION_BEGINS => 4 ,
28
+ DEADLOCK_1 => 5 ,
29
+ WAIT_PGBENCH_2 => 6 ,
30
+ DEADLOCK_2 => 7 ,
31
+ TRANSACTION_ENDS => 8 ,
27
32
};
28
33
29
34
# Test concurrent update in table row with different default transaction
33
38
$node -> start;
34
39
$node -> safe_psql(' postgres' ,
35
40
' CREATE UNLOGGED TABLE xy (x integer, y integer);'
36
- .' INSERT INTO xy VALUES (1, 2), (2, 3) ;' );
41
+ .' INSERT INTO xy VALUES (1, 2);' );
37
42
38
43
my $script_serialization =$node -> basedir .' /pgbench_script_serialization' ;
39
44
append_to_file($script_serialization ,
@@ -111,7 +116,8 @@ sub test_pgbench_default_transaction_isolation_level_and_serialization_failures
111
116
\$err_pgbench ;
112
117
113
118
# Wait until pgbench also tries to acquire the same advisory lock:
114
- do {
119
+ do
120
+ {
115
121
$in_psql =
116
122
" select * from pg_locks where"
117
123
." locktype = 'advisory' and"
@@ -169,19 +175,32 @@ sub test_pgbench_default_transaction_isolation_level_and_serialization_failures
169
175
.$isolation_level_sql
170
176
." : check processed transactions" );
171
177
172
- my $regex =
173
- ($isolation_level == READ_COMMITTED)
174
- ?qr { ^((?!number of failures)(.|\n ))*$}
175
- :qr { number of failures: [1-9]\d *\( [1-9]\d *\.\d * %\) } ;
178
+ my ($regex );
179
+
180
+ if ($isolation_level == READ_UNCOMMITTED ||
181
+ $isolation_level == READ_COMMITTED)
182
+ {
183
+ $regex =qr { ^((?!number of failures)(.|\n ))*$} ;
184
+ }
185
+ else
186
+ {
187
+ $regex =qr { number of failures: [1-9]\d *\( [1-9]\d *\.\d * %\) } ;
188
+ }
176
189
177
190
like($out_pgbench ,
178
191
$regex ,
179
192
" concurrent update:$isolation_level_sql : check failures" );
180
193
181
- $regex =
182
- ($isolation_level == READ_COMMITTED)
183
- ?qr { ^((?!client 0 got a serialization failure\( try 1/1\) )(.|\n ))*$}
184
- :qr { client 0 got a serialization failure\( try 1/1\) } ;
194
+ if ($isolation_level == READ_UNCOMMITTED ||
195
+ $isolation_level == READ_COMMITTED)
196
+ {
197
+ $regex =
198
+ qr { ^((?!client 0 got a serialization failure\( try 1/1\) )(.|\n ))*$} ;
199
+ }
200
+ else
201
+ {
202
+ $regex =qr { client 0 got a serialization failure\( try 1/1\) } ;
203
+ }
185
204
186
205
like($err_pgbench ,
187
206
$regex ,
@@ -228,7 +247,8 @@ sub test_pgbench_serialization_failures_retry
228
247
\$err_pgbench ;
229
248
230
249
# Wait until pgbench also tries to acquire the same advisory lock:
231
- do {
250
+ do
251
+ {
232
252
$in_psql =
233
253
" select * from pg_locks where"
234
254
." locktype = 'advisory' and"
@@ -341,7 +361,8 @@ sub test_pgbench_deadlock_failures
341
361
$h1 = IPC::Run::start \@command1 , \$in1 , \$out1 , \$err1 ;
342
362
343
363
# Wait until the first pgbench also tries to acquire the same advisory lock:
344
- do {
364
+ do
365
+ {
345
366
$in_psql =
346
367
" select case count(*)"
347
368
." when 0 then '" . WAIT_PGBENCH_2 ." _zero'"
@@ -369,7 +390,8 @@ sub test_pgbench_deadlock_failures
369
390
370
391
# Wait until the second pgbench tries to acquire the lock held by the first
371
392
# pgbench:
372
- do {
393
+ do
394
+ {
373
395
$in_psql =
374
396
" select case count(*)"
375
397
." when 0 then '" . DEADLOCK_1 ." _zero'"
@@ -486,7 +508,8 @@ sub test_pgbench_deadlock_failures_retry
486
508
$h1 = IPC::Run::start \@command1 , \$in1 , \$out1 , \$err1 ;
487
509
488
510
# Wait until the first pgbench also tries to acquire the same advisory lock:
489
- do {
511
+ do
512
+ {
490
513
$in_psql =
491
514
" select case count(*)"
492
515
." when 0 then '" . WAIT_PGBENCH_2 ." _zero'"
@@ -514,7 +537,8 @@ sub test_pgbench_deadlock_failures_retry
514
537
515
538
# Wait until the second pgbench tries to acquire the lock held by the first
516
539
# pgbench:
517
- do {
540
+ do
541
+ {
518
542
$in_psql =
519
543
" select case count(*)"
520
544
." when 0 then '" . DEADLOCK_1 ." _zero'"
@@ -557,7 +581,8 @@ sub test_pgbench_deadlock_failures_retry
557
581
$h_psql -> pump()until $out_psql =~/ pg_advisory_unlock_@{[ WAIT_PGBENCH_2 ]}/ ;
558
582
559
583
# Wait until pgbenches try to acquire the locks held by the psql session:
560
- do {
584
+ do
585
+ {
561
586
$in_psql =
562
587
" select case count(*)"
563
588
." when 0 then '" . TRANSACTION_BEGINS ." _zero'"
@@ -573,7 +598,8 @@ sub test_pgbench_deadlock_failures_retry
573
598
$h_psql -> pump()while length $in_psql ;
574
599
}while ($out_psql !~/ @{[ TRANSACTION_BEGINS ]}_not_zero/ );
575
600
576
- do {
601
+ do
602
+ {
577
603
$in_psql =
578
604
" select case count(*)"
579
605
." when 0 then '" . TRANSACTION_ENDS ." _zero'"
@@ -678,6 +704,8 @@ sub test_pgbench_deadlock_failures_retry
678
704
." : check the retried transaction" );
679
705
}
680
706
707
+ test_pgbench_default_transaction_isolation_level_and_serialization_failures(
708
+ READ_UNCOMMITTED);
681
709
test_pgbench_default_transaction_isolation_level_and_serialization_failures(
682
710
READ_COMMITTED);
683
711
test_pgbench_default_transaction_isolation_level_and_serialization_failures(
@@ -688,10 +716,12 @@ sub test_pgbench_deadlock_failures_retry
688
716
test_pgbench_serialization_failures_retry(REPEATABLE_READ);
689
717
test_pgbench_serialization_failures_retry(SERIALIZABLE);
690
718
719
+ test_pgbench_deadlock_failures(READ_UNCOMMITTED);
691
720
test_pgbench_deadlock_failures(READ_COMMITTED);
692
721
test_pgbench_deadlock_failures(REPEATABLE_READ);
693
722
test_pgbench_deadlock_failures(SERIALIZABLE);
694
723
724
+ test_pgbench_deadlock_failures_retry(READ_UNCOMMITTED);
695
725
test_pgbench_deadlock_failures_retry(READ_COMMITTED);
696
726
test_pgbench_deadlock_failures_retry(REPEATABLE_READ);
697
727
test_pgbench_deadlock_failures_retry(SERIALIZABLE);