|
4 | 4 |
|
5 | 5 | use PostgresNode; |
6 | 6 | use TestLib; |
7 | | -use Test::More tests => 17; |
| 7 | +use Test::More tests => 20; |
8 | 8 |
|
9 | 9 | my $psql_out = ''; |
10 | 10 | my $psql_rc = ''; |
11 | 11 |
|
| 12 | +sub configure_and_reload |
| 13 | +{ |
| 14 | + my ($node, $parameter) = @_; |
| 15 | + my $name = $node->name; |
| 16 | + |
| 17 | + $node->append_conf( |
| 18 | + 'postgresql.conf', qq( |
| 19 | + $parameter |
| 20 | + )); |
| 21 | + $node->psql('postgres', "SELECT pg_reload_conf()", |
| 22 | + stdout => \$psql_out); |
| 23 | + is($psql_out, 't', "reload node $name with $parameter"); |
| 24 | +} |
| 25 | + |
12 | 26 | # Set up two nodes, which will alternately be master and replication slave. |
13 | 27 |
|
14 | 28 | # Setup london node |
|
28 | 42 | has_streaming => 1); |
29 | 43 | $node_paris->start; |
30 | 44 |
|
31 | | -# Switch to synchronous replication |
32 | | -$node_london->append_conf( |
33 | | - 'postgresql.conf', qq( |
34 | | - synchronous_standby_names = '*' |
35 | | -)); |
36 | | -$node_london->psql('postgres', "SELECT pg_reload_conf()", |
37 | | - stdout => \$psql_out); |
38 | | -is($psql_out, 't', 'Enable synchronous replication'); |
| 45 | +# Switch to synchronous replication in both directions |
| 46 | +configure_and_reload($node_london, "synchronous_standby_names = 'paris'"); |
| 47 | +configure_and_reload($node_paris, "synchronous_standby_names = 'london'"); |
39 | 48 |
|
| 49 | +# Set up nonce names for current master and slave nodes |
40 | 50 | note "Initially, london is master and paris is slave"; |
41 | 51 | my ($cur_master, $cur_slave) = ($node_london, $node_paris); |
42 | 52 | my $cur_master_name = $cur_master->name; |
|
213 | 223 | ($cur_master, $cur_slave) = ($node_paris, $node_london); |
214 | 224 | $cur_master_name = $cur_master->name; |
215 | 225 |
|
216 | | -$psql_rc = $cur_master->psql('postgres', "COMMIT PREPARED 'xact_009_10'"); |
| 226 | +# because london is not running at this point, we can't use syncrep commit |
| 227 | +# on this command |
| 228 | +$psql_rc = $cur_master->psql('postgres', |
| 229 | + "SET synchronous_commit = off; COMMIT PREPARED 'xact_009_10'"); |
217 | 230 | is($psql_rc, '0', "Restore of prepared transaction on promoted slave"); |
218 | 231 |
|
219 | 232 | # restart old master as new slave |
|
309 | 322 | $cur_master->psql('postgres', "COMMIT PREPARED 'xact_009_12'"); |
310 | 323 |
|
311 | 324 | ############################################################################### |
312 | | -# Check for a lock conflict between prepared transaction with DDL inside and replay of |
313 | | -# XLOG_STANDBY_LOCK wal record. |
| 325 | +# Check for a lock conflict between prepared transaction with DDL inside and |
| 326 | +# replay of XLOG_STANDBY_LOCK wal record. |
314 | 327 | ############################################################################### |
315 | 328 |
|
316 | 329 | $cur_master->psql( |
|
327 | 340 |
|
328 | 341 | $cur_slave->psql( |
329 | 342 | 'postgres', |
330 | | - "SELECT count(*) FROM pg_prepared_xacts", |
| 343 | + "SELECT count(*) FROM t_009_tbl2", |
331 | 344 | stdout => \$psql_out); |
332 | | -is($psql_out, '0', "Replay prepared transaction with DDL"); |
| 345 | +is($psql_out, '1', "Replay prepared transaction with DDL"); |
333 | 346 |
|
334 | 347 | ############################################################################### |
335 | 348 | # Verify expected data appears on both servers. |
336 | 349 | ############################################################################### |
337 | 350 |
|
| 351 | +$cur_master->psql( |
| 352 | + 'postgres', |
| 353 | + "SELECT count(*) FROM pg_prepared_xacts", |
| 354 | + stdout => \$psql_out); |
| 355 | +is($psql_out, '0', "No uncommitted prepared transactions on master"); |
| 356 | + |
338 | 357 | $cur_master->psql( |
339 | 358 | 'postgres', |
340 | 359 | "SELECT * FROM t_009_tbl ORDER BY id", |
|
370 | 389 | is($psql_out, qq{27|issued to paris}, |
371 | 390 | "Check expected t_009_tbl2 data on master"); |
372 | 391 |
|
| 392 | +$cur_slave->psql( |
| 393 | + 'postgres', |
| 394 | + "SELECT count(*) FROM pg_prepared_xacts", |
| 395 | + stdout => \$psql_out); |
| 396 | +is($psql_out, '0', "No uncommitted prepared transactions on slave"); |
| 397 | + |
373 | 398 | $cur_slave->psql( |
374 | 399 | 'postgres', |
375 | 400 | "SELECT * FROM t_009_tbl ORDER BY id", |
|
0 commit comments