mirror of
https://github.com/postgres/postgres.git
synced 2025-06-22 02:52:08 +03:00
Clean up misuse and nonuse of poll_query_until().
Several callers of PostgresNode::poll_query_until() neglected to check for failure; I do not think that's optional. Also, rewrite one place that had reinvented poll_query_until() for no very good reason.
This commit is contained in:
@ -55,7 +55,8 @@ $master->append_conf('postgresql.conf', 'track_commit_timestamp = off');
|
|||||||
$master->restart;
|
$master->restart;
|
||||||
|
|
||||||
system_or_bail('pg_ctl', '-D', $standby->data_dir, 'promote');
|
system_or_bail('pg_ctl', '-D', $standby->data_dir, 'promote');
|
||||||
$standby->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true");
|
$standby->poll_query_until('postgres', "SELECT NOT pg_is_in_recovery()")
|
||||||
|
or die "standby never exited recovery";
|
||||||
|
|
||||||
$standby->safe_psql('postgres', "create table t11()");
|
$standby->safe_psql('postgres', "create table t11()");
|
||||||
my $standby_ts = $standby->safe_psql('postgres',
|
my $standby_ts = $standby->safe_psql('postgres',
|
||||||
|
@ -43,7 +43,7 @@ PostgresNode - class representing PostgreSQL server instance
|
|||||||
# run query every second until it returns 't'
|
# run query every second until it returns 't'
|
||||||
# or times out
|
# or times out
|
||||||
$node->poll_query_until('postgres', q|SELECT random() < 0.1;|')
|
$node->poll_query_until('postgres', q|SELECT random() < 0.1;|')
|
||||||
or print "timed out";
|
or die "timed out";
|
||||||
|
|
||||||
# Do an online pg_basebackup
|
# Do an online pg_basebackup
|
||||||
my $ret = $node->backup('testbackup1');
|
my $ret = $node->backup('testbackup1');
|
||||||
|
@ -156,7 +156,8 @@ sub wait_slot_xmins
|
|||||||
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 = '$slot_name';
|
||||||
]);
|
])
|
||||||
|
or die "Timed out waiting for slot xmins to advance";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetch xmin columns from slot's pg_replication_slots row
|
# Fetch xmin columns from slot's pg_replication_slots row
|
||||||
|
@ -44,23 +44,9 @@ $node_master->safe_psql('postgres',
|
|||||||
my $until_lsn =
|
my $until_lsn =
|
||||||
$node_master->safe_psql('postgres', "SELECT pg_current_wal_lsn()");
|
$node_master->safe_psql('postgres', "SELECT pg_current_wal_lsn()");
|
||||||
|
|
||||||
my $remaining = 90;
|
$node_standby->poll_query_until('postgres',
|
||||||
while ($remaining-- > 0)
|
"SELECT (pg_last_wal_replay_lsn() - '$until_lsn'::pg_lsn) >= 0")
|
||||||
{
|
or die "standby never caught up";
|
||||||
|
|
||||||
# Done waiting?
|
|
||||||
my $replay_status = $node_standby->safe_psql('postgres',
|
|
||||||
"SELECT (pg_last_wal_replay_lsn() - '$until_lsn'::pg_lsn) >= 0");
|
|
||||||
last if $replay_status eq 't';
|
|
||||||
|
|
||||||
# No, sleep some more.
|
|
||||||
my $sleep = $master_insert_time + $delay - time();
|
|
||||||
$sleep = 1 if $sleep < 1;
|
|
||||||
sleep $sleep;
|
|
||||||
}
|
|
||||||
|
|
||||||
die "Maximum number of attempts reached ($remaining remain)"
|
|
||||||
if $remaining < 0;
|
|
||||||
|
|
||||||
# This test is successful if and only if the LSN has been applied with at least
|
# This test is successful if and only if the LSN has been applied with at least
|
||||||
# the configured apply delay.
|
# the configured apply delay.
|
||||||
|
@ -111,9 +111,10 @@ SKIP:
|
|||||||
'-S', 'otherdb_slot', '-f', '-', '--start' ]);
|
'-S', 'otherdb_slot', '-f', '-', '--start' ]);
|
||||||
$node_master->poll_query_until('otherdb',
|
$node_master->poll_query_until('otherdb',
|
||||||
"SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NOT NULL)"
|
"SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NOT NULL)"
|
||||||
);
|
)
|
||||||
|
or die "slot never became active";
|
||||||
is($node_master->psql('postgres', 'DROP DATABASE otherdb'),
|
is($node_master->psql('postgres', 'DROP DATABASE otherdb'),
|
||||||
3, 'dropping a DB with inactive logical slots fails');
|
3, 'dropping a DB with active logical slots fails');
|
||||||
$pg_recvlogical->kill_kill;
|
$pg_recvlogical->kill_kill;
|
||||||
is($node_master->slot('otherdb_slot')->{'slot_name'},
|
is($node_master->slot('otherdb_slot')->{'slot_name'},
|
||||||
undef, 'logical slot still exists');
|
undef, 'logical slot still exists');
|
||||||
@ -121,7 +122,9 @@ SKIP:
|
|||||||
|
|
||||||
$node_master->poll_query_until('otherdb',
|
$node_master->poll_query_until('otherdb',
|
||||||
"SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NULL)"
|
"SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NULL)"
|
||||||
);
|
)
|
||||||
|
or die "slot never became inactive";
|
||||||
|
|
||||||
is($node_master->psql('postgres', 'DROP DATABASE otherdb'),
|
is($node_master->psql('postgres', 'DROP DATABASE otherdb'),
|
||||||
0, 'dropping a DB with inactive logical slots succeeds');
|
0, 'dropping a DB with inactive logical slots succeeds');
|
||||||
is($node_master->slot('otherdb_slot')->{'slot_name'},
|
is($node_master->slot('otherdb_slot')->{'slot_name'},
|
||||||
|
@ -117,7 +117,9 @@ $node_master->poll_query_until(
|
|||||||
SELECT catalog_xmin IS NOT NULL
|
SELECT catalog_xmin IS NOT NULL
|
||||||
FROM pg_replication_slots
|
FROM pg_replication_slots
|
||||||
WHERE slot_name = 'phys_slot'
|
WHERE slot_name = 'phys_slot'
|
||||||
]);
|
])
|
||||||
|
or die "slot's catalog_xmin never became set";
|
||||||
|
|
||||||
my $phys_slot = $node_master->slot('phys_slot');
|
my $phys_slot = $node_master->slot('phys_slot');
|
||||||
isnt($phys_slot->{'xmin'}, '', 'xmin assigned on physical slot of master');
|
isnt($phys_slot->{'xmin'}, '', 'xmin assigned on physical slot of master');
|
||||||
isnt($phys_slot->{'catalog_xmin'},
|
isnt($phys_slot->{'catalog_xmin'},
|
||||||
@ -137,7 +139,8 @@ $node_master->stop('immediate');
|
|||||||
$node_replica->promote;
|
$node_replica->promote;
|
||||||
print "waiting for replica to come up\n";
|
print "waiting for replica to come up\n";
|
||||||
$node_replica->poll_query_until('postgres',
|
$node_replica->poll_query_until('postgres',
|
||||||
"SELECT NOT pg_is_in_recovery();");
|
"SELECT NOT pg_is_in_recovery();")
|
||||||
|
or die "replica never exited recovery";
|
||||||
|
|
||||||
$node_replica->safe_psql('postgres',
|
$node_replica->safe_psql('postgres',
|
||||||
"INSERT INTO decoding(blah) VALUES ('after failover');");
|
"INSERT INTO decoding(blah) VALUES ('after failover');");
|
||||||
|
Reference in New Issue
Block a user