summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2017-07-06 03:59:20 +0000
committerTom Lane2017-07-06 03:59:20 +0000
commitec86af917551f52246848dd148885df034273f3d (patch)
tree7b11b9626ce60a4e6ae4642e161a42949b00676c
parentff68e909acd924b532e58c7699e93a1aff71654a (diff)
Fix another race-condition-ish issue in recovery/t/001_stream_rep.pl.
Buildfarm members hornet and sungazer have shown multiple instances of "Failed test 'xmin of non-cascaded slot with hs feedback has changed'". The reason seems to be that the test is checking the current xmin of the master server's replication slot against a past xmin of the first slave server's replication slot. Even though the latter slot is downstream of the former, it's possible for its reported xmin to be ahead of the former's reported xmin, because those numbers are updated whenever the respective downstream walreceiver feels like it (see logic in WalReceiverMain). Instrumenting this test shows that indeed the slave slot's xmin does often advance before the master's does, especially if an autovacuum transaction manages to occur during the relevant window. If we happen to capture such an advanced xmin as $xmin, then the subsequent wait_slot_xmins call can fall through before the master's xmin has advanced at all, and then if it advances before the get_slot_xmins call, we can get the observed failure. Yeah, that's a bit of a long chain of deduction, but it's hard to explain any other way how the test can get past an "xmin <> '$xmin'" check only to have the next query find that xmin does equal $xmin. Fix by keeping separate images of the master and slave slots' xmins and testing their has-xmin-advanced conditions independently.
-rw-r--r--src/test/recovery/t/001_stream_rep.pl14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/test/recovery/t/001_stream_rep.pl b/src/test/recovery/t/001_stream_rep.pl
index 15ace5f51c..3590516425 100644
--- a/src/test/recovery/t/001_stream_rep.pl
+++ b/src/test/recovery/t/001_stream_rep.pl
@@ -220,9 +220,9 @@ isnt($xmin, '', 'xmin of non-cascaded slot non-null with hs feedback');
is($catalog_xmin, '',
'catalog xmin of non-cascaded slot still null with hs_feedback');
-($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
-isnt($xmin, '', 'xmin of cascaded slot non-null with hs feedback');
-is($catalog_xmin, '', 'catalog xmin of cascaded slot still null with hs_feedback');
+my ($xmin1, $catalog_xmin1) = get_slot_xmins($node_standby_1, $slotname_2);
+isnt($xmin1, '', 'xmin of cascaded slot non-null with hs feedback');
+is($catalog_xmin1, '', 'catalog xmin of cascaded slot still null with hs_feedback');
note "doing some work to advance xmin";
$node_master->safe_psql('postgres', q{
@@ -245,16 +245,16 @@ $node_master->safe_psql('postgres', 'CHECKPOINT;');
wait_slot_xmins($node_master, $slotname_1, "xmin <> '$xmin'");
my ($xmin2, $catalog_xmin2) = get_slot_xmins($node_master, $slotname_1);
-note "new xmin $xmin2, old xmin $xmin";
+note "master slot's new xmin $xmin2, old xmin $xmin";
isnt($xmin2, $xmin, 'xmin of non-cascaded slot with hs feedback has changed');
is($catalog_xmin2, '',
'catalog xmin of non-cascaded slot still null with hs_feedback unchanged');
-wait_slot_xmins($node_standby_1, $slotname_2, "xmin <> '$xmin'");
+wait_slot_xmins($node_standby_1, $slotname_2, "xmin <> '$xmin1'");
($xmin2, $catalog_xmin2) = get_slot_xmins($node_standby_1, $slotname_2);
-note "new xmin $xmin2, old xmin $xmin";
-isnt($xmin2, $xmin, 'xmin of cascaded slot with hs feedback has changed');
+note "standby_1 slot's new xmin $xmin2, old xmin $xmin1";
+isnt($xmin2, $xmin1, 'xmin of cascaded slot with hs feedback has changed');
is($catalog_xmin2, '',
'catalog xmin of cascaded slot still null with hs_feedback unchanged');