Skip to content

Commit a1acdac

Browse files
committed
Add wait_for_replay_catchup wrapper to Cluster.pm
This simplifies a few lines of Perl test code a bit. Author: Bertrand Drouvot Discussion: https://postgr.es/m/846724b5-0723-f4c2-8b13-75301ec7509e@gmail.com
1 parent ec5a010 commit a1acdac

File tree

8 files changed

+51
-51
lines changed

8 files changed

+51
-51
lines changed

src/bin/pg_rewind/t/007_standby_source.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
$node_a->safe_psql('postgres',
161161
"INSERT INTO tbl1 values ('in A, after rewind')");
162162

163-
$node_b->wait_for_catchup('node_c', 'replay', $node_a->lsn('write'));
163+
$node_b->wait_for_replay_catchup('node_c', $node_a);
164164

165165
check_query(
166166
'SELECT * FROM tbl1',

src/test/modules/brin/t/02_wal_consistency.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@
7070
});
7171
cmp_ok($out, '>=', 1);
7272

73-
$whiskey->wait_for_catchup($charlie, 'replay', $whiskey->lsn('insert'));
73+
$whiskey->wait_for_replay_catchup($charlie);
7474

7575
done_testing();

src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,29 @@ sub wait_for_catchup
27112711

27122712
=pod
27132713
2714+
=item $node->wait_for_replay_catchup($standby_name [, $base_node ])
2715+
2716+
Wait for the replication connection with application_name I<$standby_name>
2717+
until its B<replay> replication column in pg_stat_replication in I<$node>
2718+
equals or passes the I<$base_node>'s B<replay_lsn>. If I<$base_node> is
2719+
omitted, the LSN to wait for is obtained from I<$node>.
2720+
2721+
The replication connection must be in a streaming state.
2722+
2723+
Requires that the 'postgres' db exists and is accessible.
2724+
2725+
This is not a test. It die()s on failure.
2726+
2727+
=cut
2728+
2729+
sub wait_for_replay_catchup
2730+
{
2731+
my ($self, $standby_name, $node) = @_;
2732+
$node = defined($node) ? $node : $self;
2733+
2734+
$self->wait_for_catchup($standby_name, 'replay', $node->lsn('flush'));
2735+
}
2736+
27142737
=item $node->wait_for_slot_catchup(slot_name, mode, target_lsn)
27152738
27162739
Wait for the named replication slot to equal or pass the supplied target_lsn.

src/test/recovery/t/001_stream_rep.pl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@
4747
"CREATE TABLE tab_int AS SELECT generate_series(1,1002) AS a");
4848

4949
# Wait for standbys to catch up
50-
my $primary_lsn = $node_primary->lsn('write');
51-
$node_primary->wait_for_catchup($node_standby_1, 'replay', $primary_lsn);
52-
$node_standby_1->wait_for_catchup($node_standby_2, 'replay', $primary_lsn);
50+
$node_primary->wait_for_replay_catchup($node_standby_1);
51+
$node_standby_1->wait_for_replay_catchup($node_standby_2, $node_primary);
5352

5453
my $result =
5554
$node_standby_1->safe_psql('postgres', "SELECT count(*) FROM tab_int");
@@ -66,9 +65,8 @@
6665
"CREATE SEQUENCE seq1; SELECT nextval('seq1')");
6766

6867
# Wait for standbys to catch up
69-
$primary_lsn = $node_primary->lsn('write');
70-
$node_primary->wait_for_catchup($node_standby_1, 'replay', $primary_lsn);
71-
$node_standby_1->wait_for_catchup($node_standby_2, 'replay', $primary_lsn);
68+
$node_primary->wait_for_replay_catchup($node_standby_1);
69+
$node_standby_1->wait_for_replay_catchup($node_standby_2, $node_primary);
7270

7371
$result = $node_standby_1->safe_psql('postgres', "SELECT * FROM seq1");
7472
print "standby 1: $result\n";
@@ -372,10 +370,8 @@ sub replay_check
372370
my $newval = $node_primary->safe_psql('postgres',
373371
'INSERT INTO replayed(val) SELECT coalesce(max(val),0) + 1 AS newval FROM replayed RETURNING val'
374372
);
375-
my $primary_lsn = $node_primary->lsn('write');
376-
$node_primary->wait_for_catchup($node_standby_1, 'replay', $primary_lsn);
377-
$node_standby_1->wait_for_catchup($node_standby_2, 'replay',
378-
$primary_lsn);
373+
$node_primary->wait_for_replay_catchup($node_standby_1);
374+
$node_standby_1->wait_for_replay_catchup($node_standby_2, $node_primary);
379375

380376
$node_standby_1->safe_psql('postgres',
381377
qq[SELECT 1 FROM replayed WHERE val = $newval])

src/test/recovery/t/027_stream_regress.pl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@
8686
"select setval(seqrelid, nextval(seqrelid)) from pg_sequence");
8787

8888
# Wait for standby to catch up
89-
$node_primary->wait_for_catchup($node_standby_1, 'replay',
90-
$node_primary->lsn('insert'));
89+
$node_primary->wait_for_replay_catchup($node_standby_1);
9190

9291
# Perform a logical dump of primary and standby, and check that they match
9392
command_ok(

src/test/recovery/t/030_stats_cleanup_replica.pl

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
drop_function_by_oid('postgres', $funcoid);
3939

4040
$sect = 'post drop';
41-
my $primary_lsn = $node_primary->lsn('flush');
42-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
41+
$node_primary->wait_for_replay_catchup($node_standby);
4342
test_standby_func_tab_stats_status('postgres',
4443
$dboid, $tableoid, $funcoid, 'f');
4544

@@ -49,8 +48,7 @@
4948
$sect = "schema creation";
5049

5150
$node_primary->safe_psql('postgres', "CREATE SCHEMA drop_schema_test1");
52-
$primary_lsn = $node_primary->lsn('flush');
53-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
51+
$node_primary->wait_for_replay_catchup($node_standby);
5452

5553
($dboid, $tableoid, $funcoid) =
5654
populate_standby_stats('postgres', 'drop_schema_test1');
@@ -61,8 +59,7 @@
6159

6260
$sect = "post schema drop";
6361

64-
$primary_lsn = $node_primary->lsn('flush');
65-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
62+
$node_primary->wait_for_replay_catchup($node_standby);
6663

6764
# verify table and function stats removed from standby
6865
test_standby_func_tab_stats_status('postgres',
@@ -74,8 +71,7 @@
7471
$sect = "createdb";
7572

7673
$node_primary->safe_psql('postgres', "CREATE DATABASE test");
77-
$primary_lsn = $node_primary->lsn('flush');
78-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
74+
$node_primary->wait_for_replay_catchup($node_standby);
7975

8076
($dboid, $tableoid, $funcoid) = populate_standby_stats('test', 'public');
8177

@@ -84,9 +80,8 @@
8480
test_standby_db_stats_status('test', $dboid, 't');
8581

8682
$node_primary->safe_psql('postgres', "DROP DATABASE test");
87-
$sect = "post dropdb";
88-
$primary_lsn = $node_primary->lsn('flush');
89-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
83+
$sect = "post dropdb";
84+
$node_primary->wait_for_replay_catchup($node_standby);
9085

9186
# Test that the stats were cleaned up on standby
9287
# Note that this connects to 'postgres' but provides the dboid of dropped db
@@ -137,8 +132,7 @@ sub populate_standby_stats
137132
$node_primary->safe_psql($connect_db,
138133
"CREATE FUNCTION $schema.drop_func_test1() RETURNS VOID AS 'select 2;' LANGUAGE SQL IMMUTABLE"
139134
);
140-
my $primary_lsn = $node_primary->lsn('flush');
141-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
135+
$node_primary->wait_for_replay_catchup($node_standby);
142136

143137
# collect object oids
144138
my $dboid = $node_standby->safe_psql($connect_db,

src/test/recovery/t/031_recovery_conflict.pl

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
INSERT INTO $table1 SELECT i % 3, 0 FROM generate_series(1,20) i;
6464
CREATE TABLE ${table2}(a int, b int);
6565
]);
66-
my $primary_lsn = $node_primary->lsn('flush');
67-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
66+
$node_primary->wait_for_replay_catchup($node_standby);
6867

6968

7069
# a longrunning psql that we can use to trigger conflicts
@@ -97,8 +96,7 @@
9796
BEGIN; LOCK $table1; COMMIT;
9897
]);
9998

100-
$primary_lsn = $node_primary->lsn('flush');
101-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
99+
$node_primary->wait_for_replay_catchup($node_standby);
102100

103101
my $cursor1 = "test_recovery_conflict_cursor";
104102

@@ -124,8 +122,7 @@
124122
# finished, so waiting for catchup ensures that there is no race between
125123
# encountering the recovery conflict which causes the disconnect and checking
126124
# the logfile for the terminated connection.
127-
$primary_lsn = $node_primary->lsn('flush');
128-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
125+
$node_primary->wait_for_replay_catchup($node_standby);
129126

130127
check_conflict_log("User was holding shared buffer pin for too long");
131128
reconnect_and_clear();
@@ -138,8 +135,7 @@
138135

139136
$node_primary->safe_psql($test_db,
140137
qq[INSERT INTO $table1 SELECT i, 0 FROM generate_series(1,20) i]);
141-
$primary_lsn = $node_primary->lsn('flush');
142-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
138+
$node_primary->wait_for_replay_catchup($node_standby);
143139

144140
# DECLARE and FETCH from cursor on the standby
145141
$psql_standby{stdin} .= qq[
@@ -160,8 +156,7 @@
160156
$node_primary->safe_psql($test_db, qq[VACUUM $table1;]);
161157

162158
# Wait for attempted replay of PRUNE records
163-
$primary_lsn = $node_primary->lsn('flush');
164-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
159+
$node_primary->wait_for_replay_catchup($node_standby);
165160

166161
check_conflict_log(
167162
"User query might have needed to see row versions that must be removed");
@@ -184,8 +179,7 @@
184179
# DROP TABLE containing block which standby has in a pinned buffer
185180
$node_primary->safe_psql($test_db, qq[DROP TABLE $table1;]);
186181

187-
$primary_lsn = $node_primary->lsn('flush');
188-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
182+
$node_primary->wait_for_replay_catchup($node_standby);
189183

190184
check_conflict_log("User was holding a relation lock for too long");
191185
reconnect_and_clear();
@@ -213,8 +207,7 @@
213207
# standby
214208
$node_primary->safe_psql($test_db, qq[DROP TABLESPACE $tablespace1;]);
215209

216-
$primary_lsn = $node_primary->lsn('flush');
217-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
210+
$node_primary->wait_for_replay_catchup($node_standby);
218211

219212
check_conflict_log(
220213
"User was or might have been using tablespace that must be dropped");
@@ -255,8 +248,7 @@
255248
SELECT txid_current();
256249
]);
257250

258-
$primary_lsn = $node_primary->lsn('flush');
259-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
251+
$node_primary->wait_for_replay_catchup($node_standby);
260252

261253
$psql_standby{stdin} .= qq[
262254
BEGIN;
@@ -282,8 +274,7 @@
282274
# VACUUM will prune away rows, causing a buffer pin conflict, while standby
283275
# psql is waiting on lock
284276
$node_primary->safe_psql($test_db, qq[VACUUM $table1;]);
285-
$primary_lsn = $node_primary->lsn('flush');
286-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
277+
$node_primary->wait_for_replay_catchup($node_standby);
287278

288279
check_conflict_log("User transaction caused buffer deadlock with recovery.");
289280
reconnect_and_clear();
@@ -311,8 +302,7 @@
311302

312303
$node_primary->safe_psql('postgres', qq[DROP DATABASE $test_db;]);
313304

314-
$primary_lsn = $node_primary->lsn('flush');
315-
$node_primary->wait_for_catchup($node_standby, 'replay', $primary_lsn);
305+
$node_primary->wait_for_replay_catchup($node_standby);
316306

317307
check_conflict_log("User was connected to a database that must be dropped");
318308

src/test/recovery/t/033_replay_tsp_drops.pl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ sub test_tablespace
4242
$node_standby->start;
4343

4444
# Make sure the connection is made
45-
$node_primary->wait_for_catchup($node_standby, 'write',
46-
$node_primary->lsn('write'));
45+
$node_primary->wait_for_catchup($node_standby, 'write');
4746

4847
# Do immediate shutdown just after a sequence of CREATE DATABASE / DROP
4948
# DATABASE / DROP TABLESPACE. This causes CREATE DATABASE WAL records
@@ -65,8 +64,7 @@ sub test_tablespace
6564
$query =~ s/<STRATEGY>/$strategy/g;
6665

6766
$node_primary->safe_psql('postgres', $query);
68-
$node_primary->wait_for_catchup($node_standby, 'write',
69-
$node_primary->lsn('write'));
67+
$node_primary->wait_for_catchup($node_standby, 'write');
7068

7169
# show "create missing directory" log message
7270
$node_standby->safe_psql('postgres',

0 commit comments

Comments
 (0)