Skip to content

Commit 3043c1d

Browse files
committed
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
1 parent d6ecad8 commit 3043c1d

File tree

1 file changed

+25
-40
lines changed

1 file changed

+25
-40
lines changed

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

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -146,35 +146,32 @@ sub test_target_session_attrs
146146
"wal_receiver_status_interval = 1");
147147
$node_standby_2->restart;
148148

149-
# Wait for given condition on slot's pg_replication_slots row --- useful for
150-
# ensuring we've reached a quiescent condition for reading slot xmins
151-
sub wait_slot_xmins
149+
# Fetch xmin columns from slot's pg_replication_slots row, after waiting for
150+
# given boolean condition to be true to ensure we've reached a quiescent state
151+
sub get_slot_xmins
152152
{
153-
my ($node, $slot_name, $check_expr) = @_;
153+
my ($node, $slotname, $check_expr) = @_;
154154

155155
$node->poll_query_until('postgres', qq[
156156
SELECT $check_expr
157157
FROM pg_catalog.pg_replication_slots
158-
WHERE slot_name = '$slot_name';
158+
WHERE slot_name = '$slotname';
159159
])
160160
or die "Timed out waiting for slot xmins to advance";
161-
}
162161

163-
# Fetch xmin columns from slot's pg_replication_slots row
164-
sub get_slot_xmins
165-
{
166-
my ($node, $slotname) = @_;
167162
my $slotinfo = $node->slot($slotname);
168163
return ($slotinfo->{'xmin'}, $slotinfo->{'catalog_xmin'});
169164
}
170165

171166
# There's no hot standby feedback and there are no logical slots on either peer
172167
# so xmin and catalog_xmin should be null on both slots.
173-
my ($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
168+
my ($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1,
169+
"xmin IS NULL AND catalog_xmin IS NULL");
174170
is($xmin, '', 'xmin of non-cascaded slot null with no hs_feedback');
175171
is($catalog_xmin, '', 'catalog xmin of non-cascaded slot null with no hs_feedback');
176172

177-
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
173+
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2,
174+
"xmin IS NULL AND catalog_xmin IS NULL");
178175
is($xmin, '', 'xmin of cascaded slot null with no hs_feedback');
179176
is($catalog_xmin, '', 'catalog xmin of cascaded slot null with no hs_feedback');
180177

@@ -212,18 +209,14 @@ sub replay_check
212209
$node_standby_2->reload;
213210
replay_check();
214211

215-
wait_slot_xmins($node_master, $slotname_1,
216-
"xmin IS NOT NULL AND catalog_xmin IS NULL");
217-
218-
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
212+
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1,
213+
"xmin IS NOT NULL AND catalog_xmin IS NULL");
219214
isnt($xmin, '', 'xmin of non-cascaded slot non-null with hs feedback');
220215
is($catalog_xmin, '',
221216
'catalog xmin of non-cascaded slot still null with hs_feedback');
222217

223-
wait_slot_xmins($node_standby_1, $slotname_2,
224-
"xmin IS NOT NULL AND catalog_xmin IS NULL");
225-
226-
my ($xmin1, $catalog_xmin1) = get_slot_xmins($node_standby_1, $slotname_2);
218+
my ($xmin1, $catalog_xmin1) = get_slot_xmins($node_standby_1, $slotname_2,
219+
"xmin IS NOT NULL AND catalog_xmin IS NULL");
227220
isnt($xmin1, '', 'xmin of cascaded slot non-null with hs feedback');
228221
is($catalog_xmin1, '',
229222
'catalog xmin of cascaded slot still null with hs_feedback');
@@ -246,17 +239,15 @@ sub replay_check
246239
$node_master->safe_psql('postgres', 'VACUUM;');
247240
$node_master->safe_psql('postgres', 'CHECKPOINT;');
248241

249-
wait_slot_xmins($node_master, $slotname_1, "xmin <> '$xmin'");
250-
251-
my ($xmin2, $catalog_xmin2) = get_slot_xmins($node_master, $slotname_1);
242+
my ($xmin2, $catalog_xmin2) = get_slot_xmins($node_master, $slotname_1,
243+
"xmin <> '$xmin'");
252244
note "master slot's new xmin $xmin2, old xmin $xmin";
253245
isnt($xmin2, $xmin, 'xmin of non-cascaded slot with hs feedback has changed');
254246
is($catalog_xmin2, '',
255247
'catalog xmin of non-cascaded slot still null with hs_feedback unchanged');
256248

257-
wait_slot_xmins($node_standby_1, $slotname_2, "xmin <> '$xmin1'");
258-
259-
($xmin2, $catalog_xmin2) = get_slot_xmins($node_standby_1, $slotname_2);
249+
($xmin2, $catalog_xmin2) = get_slot_xmins($node_standby_1, $slotname_2,
250+
"xmin <> '$xmin1'");
260251
note "standby_1 slot's new xmin $xmin2, old xmin $xmin1";
261252
isnt($xmin2, $xmin1, 'xmin of cascaded slot with hs feedback has changed');
262253
is($catalog_xmin2, '',
@@ -273,18 +264,14 @@ sub replay_check
273264
$node_standby_2->reload;
274265
replay_check();
275266

276-
wait_slot_xmins($node_master, $slotname_1,
277-
"xmin IS NULL AND catalog_xmin IS NULL");
278-
279-
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
267+
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1,
268+
"xmin IS NULL AND catalog_xmin IS NULL");
280269
is($xmin, '', 'xmin of non-cascaded slot null with hs feedback reset');
281270
is($catalog_xmin, '',
282271
'catalog xmin of non-cascaded slot still null with hs_feedback reset');
283272

284-
wait_slot_xmins($node_standby_1, $slotname_2,
285-
"xmin IS NULL AND catalog_xmin IS NULL");
286-
287-
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
273+
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2,
274+
"xmin IS NULL AND catalog_xmin IS NULL");
288275
is($xmin, '', 'xmin of cascaded slot null with hs feedback reset');
289276
is($catalog_xmin, '',
290277
'catalog xmin of cascaded slot still null with hs_feedback reset');
@@ -301,16 +288,14 @@ sub replay_check
301288
'ALTER SYSTEM SET hot_standby_feedback = off;');
302289
$node_standby_2->stop;
303290

304-
wait_slot_xmins($node_standby_1, $slotname_2, "xmin IS NOT NULL");
305-
306-
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
291+
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2,
292+
"xmin IS NOT NULL");
307293
isnt($xmin, '', 'xmin of cascaded slot non-null with postgres shut down');
308294

309295
# Xmin from a previous run should be cleared on startup.
310296
$node_standby_2->start;
311297

312-
wait_slot_xmins($node_standby_1, $slotname_2, "xmin IS NULL");
313-
314-
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
298+
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2,
299+
"xmin IS NULL");
315300
is($xmin, '',
316301
'xmin of cascaded slot reset after startup with hs feedback reset');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy