# Copyright (c) 2026, QDB Development Group
|
#
|
# A TOAST owner lookup must not invalidate a borrowed storage handle.
|
use strict;
|
use warnings FATAL => 'all';
|
use PostgreSQL::Test::Cluster;
|
use PostgreSQL::Test::Utils;
|
use Test::More;
|
|
my $node = PostgreSQL::Test::Cluster->new('cfs_relcache');
|
$node->init;
|
$node->start;
|
$node->safe_psql('postgres', 'CREATE EXTENSION test_cfs');
|
my $ts = $node->basedir() . '/ts';
|
mkdir($ts) or die "mkdir $ts: $!";
|
$ts =~ s/'/''/g;
|
$node->safe_psql('postgres', "CREATE TABLESPACE cfs_ts LOCATION '$ts'");
|
my @checks;
|
|
my $discard_max = $node->safe_psql('postgres',
|
q{SELECT max_val FROM pg_settings WHERE name = 'debug_discard_caches'});
|
my @discard_modes = (0);
|
push @discard_modes, 1 if $discard_max >= 1;
|
diag('debug_discard_caches=1 requires assertion build') if $discard_max < 1;
|
|
for my $discard (@discard_modes)
|
{
|
for my $codec (qw(pglz zlib lz4 zstd))
|
{
|
subtest "$codec discard=$discard" => sub {
|
plan skip_all => "$codec unavailable"
|
unless $node->safe_psql('postgres',
|
"SELECT test_cfs_codec_available('$codec')") eq 't';
|
my $tab = "cfs_" . $discard . "_" . $codec;
|
my $idx = $tab . '_pkey';
|
my $set = "SET debug_discard_caches = $discard;";
|
my $check = "SELECT count(*) = 32 AND bool_and(payload = repeat(md5(id::text),256)) FROM $tab";
|
$node->safe_psql('postgres', $set . qq[
|
CREATE TABLE $tab (id int PRIMARY KEY, payload text) WITH (algorithm='$codec');
|
ALTER TABLE $tab ALTER COLUMN payload SET STORAGE EXTERNAL;
|
INSERT INTO $tab SELECT g, repeat(md5(g::text),256) FROM generate_series(1,32) g;
|
VACUUM $tab;
|
]);
|
is($node->safe_psql('postgres', $set . $check), 't',
|
'TOAST data after vacuum');
|
$node->safe_psql('postgres', $set . qq[
|
ALTER TABLE $tab SET TABLESPACE cfs_ts;
|
ALTER INDEX $idx SET TABLESPACE cfs_ts;
|
REINDEX TABLE $tab;
|
CHECKPOINT;
|
]);
|
is($node->safe_psql('postgres', $set . $check), 't',
|
'TOAST data after copy and reindex');
|
is($node->safe_psql('postgres', $set .
|
"SELECT ok, errors FROM pg_cfs_check('$tab', true)"),
|
't|0', 'valid CFS storage');
|
push @checks, [$tab, $set . $check];
|
};
|
}
|
}
|
$node->restart;
|
for my $case (@checks)
|
{
|
is($node->safe_psql('postgres', $case->[1]), 't',
|
$case->[0] . ' data after restart');
|
$node->safe_psql('postgres', 'DROP TABLE ' . $case->[0]);
|
}
|
$node->safe_psql('postgres', 'DROP TABLESPACE cfs_ts');
|
$node->stop;
|
done_testing();
|