Skip to content

Commit b108676

Browse files
committed
Add TAP tests for 2PC post-commit callbacks of multixacts at recovery
The current set of TAP tests for two-phase transactions include some coverage for post-commit callbacks of multixact, but it lacked tests for testing the recovery of those callbacks. This commit adds some tests with soft and hard restarts in this case, using transactions which include DDLs. Author: Michael Paquier Reviewed-by: Oleksii Kliukin Discussion: https://postgr.es/m/20190221055431.GO15532@paquier.xyz
1 parent ab5fcf2 commit b108676

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

src/test/recovery/t/009_twophase.pl

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PostgresNode;
66
use TestLib;
7-
use Test::More tests => 20;
7+
use Test::More tests => 24;
88

99
my $psql_out = '';
1010
my $psql_rc = '';
@@ -334,6 +334,60 @@ sub configure_and_reload
334334
stdout => \$psql_out);
335335
is($psql_out, '1', "Replay prepared transaction with DDL");
336336

337+
###############################################################################
338+
# Check recovery of prepared transaction with DDL inside after a hard restart
339+
# of the master.
340+
###############################################################################
341+
342+
$cur_master->psql(
343+
'postgres', "
344+
BEGIN;
345+
CREATE TABLE t_009_tbl3 (id int, msg text);
346+
SAVEPOINT s1;
347+
INSERT INTO t_009_tbl3 VALUES (28, 'issued to ${cur_master_name}');
348+
PREPARE TRANSACTION 'xact_009_14';
349+
BEGIN;
350+
CREATE TABLE t_009_tbl4 (id int, msg text);
351+
SAVEPOINT s1;
352+
INSERT INTO t_009_tbl4 VALUES (29, 'issued to ${cur_master_name}');
353+
PREPARE TRANSACTION 'xact_009_15';");
354+
355+
$cur_master->teardown_node;
356+
$cur_master->start;
357+
358+
$psql_rc = $cur_master->psql('postgres', "COMMIT PREPARED 'xact_009_14'");
359+
is($psql_rc, '0', 'Commit prepared transaction after teardown');
360+
361+
$psql_rc = $cur_master->psql('postgres', "ROLLBACK PREPARED 'xact_009_15'");
362+
is($psql_rc, '0', 'Rollback prepared transaction after teardown');
363+
364+
###############################################################################
365+
# Check recovery of prepared transaction with DDL inside after a soft restart
366+
# of the master.
367+
###############################################################################
368+
369+
$cur_master->psql(
370+
'postgres', "
371+
BEGIN;
372+
CREATE TABLE t_009_tbl5 (id int, msg text);
373+
SAVEPOINT s1;
374+
INSERT INTO t_009_tbl5 VALUES (30, 'issued to ${cur_master_name}');
375+
PREPARE TRANSACTION 'xact_009_16';
376+
BEGIN;
377+
CREATE TABLE t_009_tbl6 (id int, msg text);
378+
SAVEPOINT s1;
379+
INSERT INTO t_009_tbl6 VALUES (31, 'issued to ${cur_master_name}');
380+
PREPARE TRANSACTION 'xact_009_17';");
381+
382+
$cur_master->stop;
383+
$cur_master->start;
384+
385+
$psql_rc = $cur_master->psql('postgres', "COMMIT PREPARED 'xact_009_16'");
386+
is($psql_rc, '0', 'Commit prepared transaction after restart');
387+
388+
$psql_rc = $cur_master->psql('postgres', "ROLLBACK PREPARED 'xact_009_17'");
389+
is($psql_rc, '0', 'Rollback prepared transaction after restart');
390+
337391
###############################################################################
338392
# Verify expected data appears on both servers.
339393
###############################################################################

0 commit comments

Comments
 (0)