Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 08aed66

Browse files
committed
Eat XIDs more efficiently in recovery TAP test.
The point of this loop is to insert 1000 rows into the test table and consume 1000 XIDs. I can't see any good reason why it's useful to launch 1000 psqls and 1000 backend processes to accomplish that. Pushing the looping into a plpgsql DO block shaves about 10 seconds off the runtime of the src/test/recovery TAP tests on my machine; that's over 10% of the runtime of that test suite. It is, in fact, sufficiently more efficient that we now demonstrably need wait_slot_xmins() afterwards, or the slaves' xmins may not have moved yet.
1 parent 1ae8536 commit 08aed66

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,33 @@ sub replay_check
224224
is($catalog_xmin, '', 'catalog xmin of cascaded slot still null with hs_feedback');
225225

226226
note "doing some work to advance xmin";
227-
for my $i (10000 .. 11000)
228-
{
229-
$node_master->safe_psql('postgres', qq[INSERT INTO tab_int VALUES ($i);]);
230-
}
227+
$node_master->safe_psql('postgres', q{
228+
do $$
229+
begin
230+
for i in 10000..11000 loop
231+
-- use an exception block so that each iteration eats an XID
232+
begin
233+
insert into tab_int values (i);
234+
exception
235+
when division_by_zero then null;
236+
end;
237+
end loop;
238+
end$$;
239+
});
240+
231241
$node_master->safe_psql('postgres', 'VACUUM;');
232242
$node_master->safe_psql('postgres', 'CHECKPOINT;');
233243

244+
wait_slot_xmins($node_master, $slotname_1, "xmin <> '$xmin'");
245+
234246
my ($xmin2, $catalog_xmin2) = get_slot_xmins($node_master, $slotname_1);
235247
note "new xmin $xmin2, old xmin $xmin";
236248
isnt($xmin2, $xmin, 'xmin of non-cascaded slot with hs feedback has changed');
237249
is($catalog_xmin2, '',
238250
'catalog xmin of non-cascaded slot still null with hs_feedback unchanged');
239251

252+
wait_slot_xmins($node_standby_1, $slotname_2, "xmin <> '$xmin'");
253+
240254
($xmin2, $catalog_xmin2) = get_slot_xmins($node_standby_1, $slotname_2);
241255
note "new xmin $xmin2, old xmin $xmin";
242256
isnt($xmin2, $xmin, 'xmin of cascaded slot with hs feedback has changed');

0 commit comments

Comments
 (0)