mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Simplify fetch-slot-xmins logic in recovery TAP tests.
Merge wait_slot_xmins() into get_slot_xmins(). At this point the only place that wasn't doing a wait was the initial-state test, and a wait there seems pretty harmless. Michael Paquier Discussion: https://postgr.es/m/CAB7nPqSp_SLQb2uU7am+sn4V3g1UKv8j3yZU385oAG1cG_BN9Q@mail.gmail.com
This commit is contained in:
parent
d6ecad812f
commit
3043c1ddd1
@ -146,35 +146,32 @@ $node_standby_2->append_conf('postgresql.conf',
|
|||||||
"wal_receiver_status_interval = 1");
|
"wal_receiver_status_interval = 1");
|
||||||
$node_standby_2->restart;
|
$node_standby_2->restart;
|
||||||
|
|
||||||
# Wait for given condition on slot's pg_replication_slots row --- useful for
|
# Fetch xmin columns from slot's pg_replication_slots row, after waiting for
|
||||||
# ensuring we've reached a quiescent condition for reading slot xmins
|
# given boolean condition to be true to ensure we've reached a quiescent state
|
||||||
sub wait_slot_xmins
|
sub get_slot_xmins
|
||||||
{
|
{
|
||||||
my ($node, $slot_name, $check_expr) = @_;
|
my ($node, $slotname, $check_expr) = @_;
|
||||||
|
|
||||||
$node->poll_query_until('postgres', qq[
|
$node->poll_query_until('postgres', qq[
|
||||||
SELECT $check_expr
|
SELECT $check_expr
|
||||||
FROM pg_catalog.pg_replication_slots
|
FROM pg_catalog.pg_replication_slots
|
||||||
WHERE slot_name = '$slot_name';
|
WHERE slot_name = '$slotname';
|
||||||
])
|
])
|
||||||
or die "Timed out waiting for slot xmins to advance";
|
or die "Timed out waiting for slot xmins to advance";
|
||||||
}
|
|
||||||
|
|
||||||
# Fetch xmin columns from slot's pg_replication_slots row
|
|
||||||
sub get_slot_xmins
|
|
||||||
{
|
|
||||||
my ($node, $slotname) = @_;
|
|
||||||
my $slotinfo = $node->slot($slotname);
|
my $slotinfo = $node->slot($slotname);
|
||||||
return ($slotinfo->{'xmin'}, $slotinfo->{'catalog_xmin'});
|
return ($slotinfo->{'xmin'}, $slotinfo->{'catalog_xmin'});
|
||||||
}
|
}
|
||||||
|
|
||||||
# There's no hot standby feedback and there are no logical slots on either peer
|
# There's no hot standby feedback and there are no logical slots on either peer
|
||||||
# so xmin and catalog_xmin should be null on both slots.
|
# so xmin and catalog_xmin should be null on both slots.
|
||||||
my ($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
|
my ($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1,
|
||||||
|
"xmin IS NULL AND catalog_xmin IS NULL");
|
||||||
is($xmin, '', 'xmin of non-cascaded slot null with no hs_feedback');
|
is($xmin, '', 'xmin of non-cascaded slot null with no hs_feedback');
|
||||||
is($catalog_xmin, '', 'catalog xmin of non-cascaded slot null with no hs_feedback');
|
is($catalog_xmin, '', 'catalog xmin of non-cascaded slot null with no hs_feedback');
|
||||||
|
|
||||||
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
|
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2,
|
||||||
|
"xmin IS NULL AND catalog_xmin IS NULL");
|
||||||
is($xmin, '', 'xmin of cascaded slot null with no hs_feedback');
|
is($xmin, '', 'xmin of cascaded slot null with no hs_feedback');
|
||||||
is($catalog_xmin, '', 'catalog xmin of cascaded slot null with no hs_feedback');
|
is($catalog_xmin, '', 'catalog xmin of cascaded slot null with no hs_feedback');
|
||||||
|
|
||||||
@ -212,18 +209,14 @@ $node_standby_2->safe_psql('postgres',
|
|||||||
$node_standby_2->reload;
|
$node_standby_2->reload;
|
||||||
replay_check();
|
replay_check();
|
||||||
|
|
||||||
wait_slot_xmins($node_master, $slotname_1,
|
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1,
|
||||||
"xmin IS NOT NULL AND catalog_xmin IS NULL");
|
"xmin IS NOT NULL AND catalog_xmin IS NULL");
|
||||||
|
|
||||||
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
|
|
||||||
isnt($xmin, '', 'xmin of non-cascaded slot non-null with hs feedback');
|
isnt($xmin, '', 'xmin of non-cascaded slot non-null with hs feedback');
|
||||||
is($catalog_xmin, '',
|
is($catalog_xmin, '',
|
||||||
'catalog xmin of non-cascaded slot still null with hs_feedback');
|
'catalog xmin of non-cascaded slot still null with hs_feedback');
|
||||||
|
|
||||||
wait_slot_xmins($node_standby_1, $slotname_2,
|
my ($xmin1, $catalog_xmin1) = get_slot_xmins($node_standby_1, $slotname_2,
|
||||||
"xmin IS NOT NULL AND catalog_xmin IS NULL");
|
"xmin IS NOT NULL AND catalog_xmin IS NULL");
|
||||||
|
|
||||||
my ($xmin1, $catalog_xmin1) = get_slot_xmins($node_standby_1, $slotname_2);
|
|
||||||
isnt($xmin1, '', 'xmin of cascaded slot non-null with hs feedback');
|
isnt($xmin1, '', 'xmin of cascaded slot non-null with hs feedback');
|
||||||
is($catalog_xmin1, '',
|
is($catalog_xmin1, '',
|
||||||
'catalog xmin of cascaded slot still null with hs_feedback');
|
'catalog xmin of cascaded slot still null with hs_feedback');
|
||||||
@ -246,17 +239,15 @@ end$$;
|
|||||||
$node_master->safe_psql('postgres', 'VACUUM;');
|
$node_master->safe_psql('postgres', 'VACUUM;');
|
||||||
$node_master->safe_psql('postgres', 'CHECKPOINT;');
|
$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,
|
||||||
|
"xmin <> '$xmin'");
|
||||||
my ($xmin2, $catalog_xmin2) = get_slot_xmins($node_master, $slotname_1);
|
|
||||||
note "master slot's 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');
|
isnt($xmin2, $xmin, 'xmin of non-cascaded slot with hs feedback has changed');
|
||||||
is($catalog_xmin2, '',
|
is($catalog_xmin2, '',
|
||||||
'catalog xmin of non-cascaded slot still null with hs_feedback unchanged');
|
'catalog xmin of non-cascaded slot still null with hs_feedback unchanged');
|
||||||
|
|
||||||
wait_slot_xmins($node_standby_1, $slotname_2, "xmin <> '$xmin1'");
|
($xmin2, $catalog_xmin2) = get_slot_xmins($node_standby_1, $slotname_2,
|
||||||
|
"xmin <> '$xmin1'");
|
||||||
($xmin2, $catalog_xmin2) = get_slot_xmins($node_standby_1, $slotname_2);
|
|
||||||
note "standby_1 slot's new xmin $xmin2, old xmin $xmin1";
|
note "standby_1 slot's new xmin $xmin2, old xmin $xmin1";
|
||||||
isnt($xmin2, $xmin1, 'xmin of cascaded slot with hs feedback has changed');
|
isnt($xmin2, $xmin1, 'xmin of cascaded slot with hs feedback has changed');
|
||||||
is($catalog_xmin2, '',
|
is($catalog_xmin2, '',
|
||||||
@ -273,18 +264,14 @@ $node_standby_2->safe_psql('postgres',
|
|||||||
$node_standby_2->reload;
|
$node_standby_2->reload;
|
||||||
replay_check();
|
replay_check();
|
||||||
|
|
||||||
wait_slot_xmins($node_master, $slotname_1,
|
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1,
|
||||||
"xmin IS NULL AND catalog_xmin IS NULL");
|
"xmin IS NULL AND catalog_xmin IS NULL");
|
||||||
|
|
||||||
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
|
|
||||||
is($xmin, '', 'xmin of non-cascaded slot null with hs feedback reset');
|
is($xmin, '', 'xmin of non-cascaded slot null with hs feedback reset');
|
||||||
is($catalog_xmin, '',
|
is($catalog_xmin, '',
|
||||||
'catalog xmin of non-cascaded slot still null with hs_feedback reset');
|
'catalog xmin of non-cascaded slot still null with hs_feedback reset');
|
||||||
|
|
||||||
wait_slot_xmins($node_standby_1, $slotname_2,
|
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2,
|
||||||
"xmin IS NULL AND catalog_xmin IS NULL");
|
"xmin IS NULL AND catalog_xmin IS NULL");
|
||||||
|
|
||||||
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
|
|
||||||
is($xmin, '', 'xmin of cascaded slot null with hs feedback reset');
|
is($xmin, '', 'xmin of cascaded slot null with hs feedback reset');
|
||||||
is($catalog_xmin, '',
|
is($catalog_xmin, '',
|
||||||
'catalog xmin of cascaded slot still null with hs_feedback reset');
|
'catalog xmin of cascaded slot still null with hs_feedback reset');
|
||||||
@ -301,16 +288,14 @@ $node_standby_2->safe_psql('postgres',
|
|||||||
'ALTER SYSTEM SET hot_standby_feedback = off;');
|
'ALTER SYSTEM SET hot_standby_feedback = off;');
|
||||||
$node_standby_2->stop;
|
$node_standby_2->stop;
|
||||||
|
|
||||||
wait_slot_xmins($node_standby_1, $slotname_2, "xmin IS NOT NULL");
|
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2,
|
||||||
|
"xmin IS NOT NULL");
|
||||||
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
|
|
||||||
isnt($xmin, '', 'xmin of cascaded slot non-null with postgres shut down');
|
isnt($xmin, '', 'xmin of cascaded slot non-null with postgres shut down');
|
||||||
|
|
||||||
# Xmin from a previous run should be cleared on startup.
|
# Xmin from a previous run should be cleared on startup.
|
||||||
$node_standby_2->start;
|
$node_standby_2->start;
|
||||||
|
|
||||||
wait_slot_xmins($node_standby_1, $slotname_2, "xmin IS NULL");
|
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2,
|
||||||
|
"xmin IS NULL");
|
||||||
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
|
|
||||||
is($xmin, '',
|
is($xmin, '',
|
||||||
'xmin of cascaded slot reset after startup with hs feedback reset');
|
'xmin of cascaded slot reset after startup with hs feedback reset');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user