Исходный код СУБД 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
# QDB-1507 (U7): the SQLSTATE of an injected .cfp read failure on the
# synchronous read path (io_method=sync -> cfs_smgr_readv, the first of the
# three read-failure report sites).  The regress test cfs_io_error.sql
# covers the default io_method=worker route (aio_cfs_readv_report); this
# TAP test pins the same 58030 on the sync route.
 
use strict;
use warnings;
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
 
plan tests => 4;
 
my $node = PostgreSQL::Test::Cluster->new('cfs_io_error_sync');
# io_method is postmaster-level: set it before the first start so every
# read of the test goes through the synchronous cfs_smgr_readv path.
$node->init;
$node->append_conf('postgresql.conf', "io_method = sync");
$node->start;
 
$node->safe_psql(
    'postgres', qq{
    CREATE TABLE t_sync (id int, v text) WITH (algorithm='zstd');
    INSERT INTO t_sync
      SELECT g, md5(g::text) FROM generate_series(1, 1000) g;
    CHECKPOINT;
});
 
# Evict the pages so the SELECT really goes to the CFS smgr path.
$node->safe_psql('postgres',
    "CREATE EXTENSION pg_buffercache;
     SELECT pg_buffercache_evict_relation('t_sync')");
 
# Inject one pread failure; PGC_SIGHUP, so reload (a fresh session after a
# reload also works, t/502 does the same).
$node->safe_psql('postgres', 'ALTER SYSTEM SET cfs_debug_fail_read = 1');
$node->reload;
 
my ($ret, $stdout, $stderr) = $node->psql(
    'postgres', 'SELECT count(*) FROM t_sync',
    extra_params => ['-v', 'VERBOSITY=verbose']);
isnt($ret, 0, 'SELECT fails on the injected pread failure');
like($stderr, qr/CFS: could not read block/, 'read failure reported');
# psql prefixes stdin statements ("psql:<stdin>:1:"), so anchor on the
# verbose ERROR field, not on the line start.
like($stderr, qr/ERROR:\s+58030:/,
    'SQLSTATE is 58030 (ERRCODE_IO_ERROR) on the sync read path');
 
$node->safe_psql('postgres', 'ALTER SYSTEM RESET cfs_debug_fail_read');
$node->reload;
 
# The server survived the IO error and reads work again.
is($node->safe_psql('postgres', 'SELECT count(*) FROM t_sync'),
    1000, 'server survives, next read succeeds');
 
$node->stop;
done_testing();