Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 75212a8

Browse filesBrowse files
committed
Back-port a few PostgresNode.pm methods.
The 'lsn' and 'wait_for_catchup' methods only exist in v10 and higher, but are needed in order to support a test planned test case for a bug that exists all the way back to v9.6. To minimize cross-branch differences in the test case, back-port these methods. Discussion: http://postgr.es/m/CA+TgmoaG5dmA_8Xc1WvbvftPjtwx5uzkGEHxE7MiJ+im9jynmw@mail.gmail.com
1 parent 954ee4b commit 75212a8
Copy full SHA for 75212a8

File tree

Expand file treeCollapse file tree

1 file changed

+83
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+83
-0
lines changed

‎src/test/perl/PostgresNode.pm

Copy file name to clipboardExpand all lines: src/test/perl/PostgresNode.pm
+83Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,89 @@ sub issues_sql_like
14721472

14731473
=pod
14741474
1475+
=item $node->lsn(mode)
1476+
1477+
Look up WAL locations on the server:
1478+
1479+
* insert location (master only, error on replica)
1480+
* write location (master only, error on replica)
1481+
* flush location (master only, error on replica)
1482+
* receive location (always undef on master)
1483+
* replay location (always undef on master)
1484+
1485+
mode must be specified.
1486+
1487+
=cut
1488+
1489+
sub lsn
1490+
{
1491+
my ($self, $mode) = @_;
1492+
my %modes = (
1493+
'insert' => 'pg_current_xlog_insert_location()',
1494+
'flush' => 'pg_current_xlog_flush_location()',
1495+
'write' => 'pg_current_xlog_location()',
1496+
'receive' => 'pg_last_xlog_receive_location()',
1497+
'replay' => 'pg_last_xlog_replay_location()');
1498+
1499+
$mode = '<undef>' if !defined($mode);
1500+
die "unknown mode for 'lsn': '$mode', valid modes are "
1501+
. join(', ', keys %modes)
1502+
if !defined($modes{$mode});
1503+
1504+
my $result = $self->safe_psql('postgres', "SELECT $modes{$mode}");
1505+
chomp($result);
1506+
if ($result eq '')
1507+
{
1508+
return;
1509+
}
1510+
else
1511+
{
1512+
return $result;
1513+
}
1514+
}
1515+
1516+
=pod
1517+
1518+
=item $node->wait_for_catchup(standby_name, mode, target_lsn)
1519+
1520+
Wait for the node with application_name standby_name (usually from node->name)
1521+
until its replication position in pg_stat_replication equals or passes the
1522+
upstream's xlog insert point at the time this function is called. By default
1523+
the replay_location is waited for, but 'mode' may be specified to wait for any
1524+
of sent|write|flush|replay.
1525+
1526+
If there is no active replication connection from this peer, waits until
1527+
poll_query_until timeout.
1528+
1529+
Requires that the 'postgres' db exists and is accessible.
1530+
1531+
target_lsn may be any arbitrary lsn, but is typically $master_node->lsn('insert').
1532+
1533+
This is not a test. It die()s on failure.
1534+
1535+
=cut
1536+
1537+
sub wait_for_catchup
1538+
{
1539+
my ($self, $standby_name, $mode, $target_lsn) = @_;
1540+
$mode = defined($mode) ? $mode : 'replay';
1541+
my %valid_modes = ( 'sent' => 1, 'write' => 1, 'flush' => 1, 'replay' => 1 );
1542+
die "unknown mode $mode for 'wait_for_catchup', valid modes are " . join(', ', keys(%valid_modes)) unless exists($valid_modes{$mode});
1543+
# Allow passing of a PostgresNode instance as shorthand
1544+
if ( blessed( $standby_name ) && $standby_name->isa("PostgresNode") )
1545+
{
1546+
$standby_name = $standby_name->name;
1547+
}
1548+
die 'target_lsn must be specified' unless defined($target_lsn);
1549+
print "Waiting for replication conn " . $standby_name . "'s " . $mode . "_location to pass " . $target_lsn . " on " . $self->name . "\n";
1550+
my $query = qq[SELECT '$target_lsn' <= ${mode}_location FROM pg_catalog.pg_stat_replication WHERE application_name = '$standby_name';];
1551+
$self->poll_query_until('postgres', $query)
1552+
or die "timed out waiting for catchup, current position is " . ($self->safe_psql('postgres', $query) || '(unknown)');
1553+
print "done\n";
1554+
}
1555+
1556+
=pod
1557+
14751558
=back
14761559
14771560
=cut

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.