From b1086767087efe437131b9059fc6f2d3b7c7ecc2 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Sat, 23 Feb 2019 08:19:31 +0900 Subject: [PATCH] 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 --- src/test/recovery/t/009_twophase.pl | 56 ++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/test/recovery/t/009_twophase.pl b/src/test/recovery/t/009_twophase.pl index 2be1afcd8b..1b748ad857 100644 --- a/src/test/recovery/t/009_twophase.pl +++ b/src/test/recovery/t/009_twophase.pl @@ -4,7 +4,7 @@ use warnings; use PostgresNode; use TestLib; -use Test::More tests => 20; +use Test::More tests => 24; my $psql_out = ''; my $psql_rc = ''; @@ -334,6 +334,60 @@ $cur_standby->psql( stdout => \$psql_out); is($psql_out, '1', "Replay prepared transaction with DDL"); +############################################################################### +# Check recovery of prepared transaction with DDL inside after a hard restart +# of the master. +############################################################################### + +$cur_master->psql( + 'postgres', " + BEGIN; + CREATE TABLE t_009_tbl3 (id int, msg text); + SAVEPOINT s1; + INSERT INTO t_009_tbl3 VALUES (28, 'issued to ${cur_master_name}'); + PREPARE TRANSACTION 'xact_009_14'; + BEGIN; + CREATE TABLE t_009_tbl4 (id int, msg text); + SAVEPOINT s1; + INSERT INTO t_009_tbl4 VALUES (29, 'issued to ${cur_master_name}'); + PREPARE TRANSACTION 'xact_009_15';"); + +$cur_master->teardown_node; +$cur_master->start; + +$psql_rc = $cur_master->psql('postgres', "COMMIT PREPARED 'xact_009_14'"); +is($psql_rc, '0', 'Commit prepared transaction after teardown'); + +$psql_rc = $cur_master->psql('postgres', "ROLLBACK PREPARED 'xact_009_15'"); +is($psql_rc, '0', 'Rollback prepared transaction after teardown'); + +############################################################################### +# Check recovery of prepared transaction with DDL inside after a soft restart +# of the master. +############################################################################### + +$cur_master->psql( + 'postgres', " + BEGIN; + CREATE TABLE t_009_tbl5 (id int, msg text); + SAVEPOINT s1; + INSERT INTO t_009_tbl5 VALUES (30, 'issued to ${cur_master_name}'); + PREPARE TRANSACTION 'xact_009_16'; + BEGIN; + CREATE TABLE t_009_tbl6 (id int, msg text); + SAVEPOINT s1; + INSERT INTO t_009_tbl6 VALUES (31, 'issued to ${cur_master_name}'); + PREPARE TRANSACTION 'xact_009_17';"); + +$cur_master->stop; +$cur_master->start; + +$psql_rc = $cur_master->psql('postgres', "COMMIT PREPARED 'xact_009_16'"); +is($psql_rc, '0', 'Commit prepared transaction after restart'); + +$psql_rc = $cur_master->psql('postgres', "ROLLBACK PREPARED 'xact_009_17'"); +is($psql_rc, '0', 'Rollback prepared transaction after restart'); + ############################################################################### # Verify expected data appears on both servers. ############################################################################### -- 2.30.2