Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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();