Fix test to work with non-8kB block sizes
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 5 Dec 2025 21:39:01 +0000 (23:39 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 5 Dec 2025 21:39:01 +0000 (23:39 +0200)
Author: Maxim Orlov <orlovmg@gmail.com>
Discussion: https://www.postgresql.org/message-id/CACG%3Dezbtm%2BLOzEMyLX7rzGcAv3ez3F6nNpSJjvZeMzed0Oe6Pw%40mail.gmail.com

src/test/modules/test_slru/t/002_multixact_wraparound.pl

index de37d845b11e3d3f782f0bda9339bca4429f94aa..169333fc564783da1aa49a1005adde6608e27a8a 100644 (file)
@@ -25,19 +25,31 @@ command_ok(
    ],
    "set the cluster's next multitransaction to 0xFFFFFFF8");
 
+# Extract a few values from pg_resetwal --dry-run output that we need for
+# the calculations below
+my $out = (run_command([ 'pg_resetwal', '--dry-run', $node->data_dir ]))[0];
+$out =~ /^Database block size: *(\d+)$/m or die;
+my $blcksz = $1;
+$out =~ /^Pages per SLRU segment: *(\d+)$/m or die;
+my $slru_pages_per_segment = $1;
+
 # Fixup the SLRU files to match the state we reset to.
 
-# initialize SLRU file with zeros (65536 entries * 4 bytes = 262144 bytes)
-my $slru_file = "$node_pgdata/pg_multixact/offsets/FFFF";
+# initialize the 'offsets' SLRU file containing the new next multixid
+# with zeros
+my $multixact_offsets_per_page = $blcksz / 4;   # sizeof(MultiXactOffset) == 4
+my $segno =
+  int(0xFFFFFFF8 / $multixact_offsets_per_page / $slru_pages_per_segment);
+my $slru_file = sprintf('%s/pg_multixact/offsets/%04X', $node_pgdata, $segno);
 open my $fh, ">", $slru_file
   or die "could not open \"$slru_file\": $!";
 binmode $fh;
-# Write 65536 entries of 4 bytes each (all zeros)
-syswrite($fh, "\0" x 262144) == 262144
+my $bytes_per_seg = $slru_pages_per_segment * $blcksz;
+syswrite($fh, "\0" x $bytes_per_seg) == $bytes_per_seg
   or die "could not write to \"$slru_file\": $!";
 close $fh;
 
-# remove old SLRU file
+# remove old file
 unlink("$node_pgdata/pg_multixact/offsets/0000")
   or die "could not unlink \"$node_pgdata/pg_multixact/offsets/0000\": $!";