Change recently added test code for stability
authorAlvaro Herrera <[email protected]>
Wed, 13 Oct 2021 21:49:27 +0000 (18:49 -0300)
committerAlvaro Herrera <[email protected]>
Wed, 13 Oct 2021 21:49:27 +0000 (18:49 -0300)
The test code added with ff9f111bce24 fails under valgrind, and probably
other slow cases too, because if (say) autovacuum runs in between and
produces WAL of its own, the large INSERT fails to account for that in
the LSN calculations.  Rewrite to use a DO loop.

Per complaint from Andres Freund

Backpatch to all branches.

Discussion: https://postgr.es/m/20211013180338[email protected]

src/test/recovery/t/026_overwrite_contrecord.pl

index 543e21640f2cd0adc6bce8d0d99f716de1f7179b..106360869c451dcf9fbd45556e0749de1a574f5c 100644 (file)
@@ -22,38 +22,34 @@ $node->init(allows_streaming => 1);
 $node->append_conf('postgresql.conf', 'wal_keep_segments=16');
 $node->start;
 
-$node->safe_psql('postgres', 'create table filler (a int)');
-
-# First, measure how many bytes does the insertion of 1000 rows produce
-my $start_lsn = $node->safe_psql('postgres',
-   q{select pg_current_xlog_insert_location() - '0/0'});
-$node->safe_psql('postgres',
-   'insert into filler select * from generate_series(1, 1000)');
-my $end_lsn = $node->safe_psql('postgres',
-   q{select pg_current_xlog_insert_location() - '0/0'});
-my $rows_walsize = $end_lsn - $start_lsn;
-note "rows walsize $rows_walsize";
-
-note "before fill ",
-  $node->safe_psql('postgres', 'select pg_current_xlog_insert_location()');
+$node->safe_psql('postgres', 'create table filler (a int, b text)');
 
 # Now consume all remaining room in the current WAL segment, leaving
 # space enough only for the start of a largish record.
 $node->safe_psql(
-   'postgres', qq{
-WITH segsize AS (
-  SELECT setting::int
-    FROM pg_settings WHERE name = 'wal_segment_size'
-), walblksz AS (
-  SELECT setting::int
-    FROM pg_settings WHERE name = 'wal_block_size'
-), setting AS (
-  SELECT segsize.setting * walblksz.setting AS wal_segsize
-    FROM segsize, walblksz
-)
-INSERT INTO filler
-SELECT g FROM setting,
-  generate_series(1, 1000 * (wal_segsize - ((pg_current_xlog_insert_location() - '0/0') % wal_segsize)) / $rows_walsize) g
+   'postgres', q{
+DO $$
+DECLARE
+    wal_segsize int :=
+        (max(setting) filter (where name = 'wal_segment_size'))::int *
+        (max(setting) filter (where name = 'wal_block_size'))::int from pg_settings ;
+    remain int;
+    iters  int := 0;
+BEGIN
+    LOOP
+        INSERT into filler
+        select g, repeat(md5(g::text), (random() * 60 + 1)::int)
+        from generate_series(1, 10) g;
+
+        remain := wal_segsize - (pg_current_xlog_insert_location() - '0/0') % wal_segsize;
+        IF remain < 2 * setting::int from pg_settings where name = 'block_size' THEN
+            RAISE log 'exiting after % iterations, % bytes to end of WAL segment', iters, remain;
+            EXIT;
+        END IF;
+        iters := iters + 1;
+    END LOOP;
+END
+$$;
 });
 
 note "start ",