Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 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
-- ----------------------------------------------------------------------
-- SQLSTATE of an injected .cfp read (pread EIO) failure.
--
-- cfs_debug_fail_read makes the next record read of .cfp fail with EIO.
-- The low-level WARNING uses errcode_for_file_access() (58030 for EIO),
-- and the ERROR reported to the client must be ERRCODE_IO_ERROR (58030)
-- as well, like md.c for a failed read -- not XX000.  The corruption
-- route (checksum/format) is NOT covered here: it keeps its own
-- reporting (cfs_report_corruption, XX001 by default).
--
-- The GUC is PGC_SIGHUP: the in-session reload pattern follows
-- dia_plan_cache_index.sql (reload + short sleep).  The injection
-- counter is spent by the first failing read; the server must stay up
-- and the next read must succeed.
-- ----------------------------------------------------------------------
SET client_min_messages = warning;
CREATE EXTENSION IF NOT EXISTS pg_buffercache;
RESET client_min_messages;
 
CREATE TABLE te (id int, v text) WITH (algorithm='zstd');
INSERT INTO te SELECT g, md5(g::text) FROM generate_series(1, 1000) g;
CHECKPOINT;
SELECT pg_buffercache_evict_relation('te');
 
ALTER SYSTEM SET cfs_debug_fail_read = 1;
SELECT pg_reload_conf();
SELECT pg_sleep(1);
 
DO $$
DECLARE
  code text;
BEGIN
  BEGIN
    PERFORM count(*) FROM te;
    RAISE NOTICE 'read unexpectedly succeeded';
  EXCEPTION WHEN OTHERS THEN
    GET STACKED DIAGNOSTICS code = RETURNED_SQLSTATE;
    RAISE NOTICE 'sqlstate=%', code;
  END;
END
$$;
 
ALTER SYSTEM RESET cfs_debug_fail_read;
SELECT pg_reload_conf();
SELECT pg_sleep(1);
 
-- The server survived the IO error; the next read succeeds.
SELECT count(*) FROM te;
 
DROP TABLE te;