Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 66a6cac

Browse files
committed
fix recovery of 3pc state on reboot and add test for that
1 parent 36d0287 commit 66a6cac

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

t/0000_precommit.pl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use strict;
2+
use warnings;
3+
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 2;
7+
8+
my $psql_out = '';
9+
my $psql_rc = '';
10+
11+
my $node = get_new_node("london");
12+
$node->init(allows_streaming => 1);
13+
$node->append_conf(
14+
'postgresql.conf', qq(
15+
max_prepared_transactions = 10
16+
log_checkpoints = true
17+
));
18+
$node->start;
19+
20+
# Create table we'll use in the test transactions
21+
$node->psql('postgres', "CREATE TABLE t_precommit_tbl (id int, msg text)");
22+
23+
###############################################################################
24+
# Check ordinary restart
25+
###############################################################################
26+
27+
$node->psql(
28+
'postgres', "
29+
BEGIN;
30+
INSERT INTO t_precommit_tbl VALUES (1, 'x');
31+
PREPARE TRANSACTION 'xact_prepared';
32+
33+
BEGIN;
34+
INSERT INTO t_precommit_tbl VALUES (2, 'x');
35+
PREPARE TRANSACTION 'xact_precommited';
36+
37+
SELECT pg_precommit_prepared('xact_precommited', 'precommited');");
38+
$node->stop;
39+
$node->start;
40+
41+
42+
$node->psql(
43+
'postgres',
44+
"SELECT count(*) FROM pg_prepared_xacts WHERE state3pc = 'precommited'",
45+
stdout => \$psql_out);
46+
is($psql_out, '1',
47+
"Check that state3pc preserved during reboot");
48+
49+
###############################################################################
50+
# Check crash/recover
51+
###############################################################################
52+
53+
$node->psql(
54+
'postgres', "
55+
BEGIN;
56+
INSERT INTO t_precommit_tbl VALUES (3, 'x');
57+
PREPARE TRANSACTION 'xact_prepared_2';
58+
59+
BEGIN;
60+
INSERT INTO t_precommit_tbl VALUES (4, 'x');
61+
PREPARE TRANSACTION 'xact_precommited_2';
62+
63+
SELECT pg_precommit_prepared('xact_precommited_2', 'precommited');");
64+
$node->stop("immediate");
65+
$node->start;
66+
67+
68+
$node->psql(
69+
'postgres',
70+
"SELECT count(*) FROM pg_prepared_xacts WHERE state3pc = 'precommited'",
71+
stdout => \$psql_out);
72+
is($psql_out, '2',
73+
"Check that state3pc preserved during reboot");

0 commit comments

Comments
 (0)