# 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();
|