-- ----------------------------------------------------------------------
|
-- QDB-1569: pages delivered by the CFS CRC chain (header, payload and
|
-- original-image CRCs, all three verified in CfsDecompressPage) are not
|
-- hashed a second time by the cluster page-checksum when
|
-- cfs_skip_page_checksum is on (the default); PageIsVerified() keeps
|
-- its header sanity checks. With the GUC off the double check is
|
-- restored, and corruption detection itself never weakens: it lives in
|
-- the CFS CRC chain, which the GUC does not touch.
|
--
|
-- Part 1: a plain read of a CFS lz4 relation succeeds with the default
|
-- GUC (the redundant page-checksum is skipped after the CFS CRCs).
|
-- Part 2: the same read succeeds with the GUC off (second hash back).
|
-- Part 3: a corrupted payload byte of one record must still fail the
|
-- CFS read with the GUC on and off alike, and a restored record must
|
-- read cleanly again through the smgr read path.
|
-- ----------------------------------------------------------------------
|
-- The corrupt test case intentionally triggers WARNINGs from
|
-- CfsDecompressPage(); suppress client warnings so the regression output
|
-- stays stable (same approach as cfs_read_batch.sql). The CREATE
|
-- EXTENSION notices are hidden the same way: in the full schedule
|
-- cfs_codec.sql and cfs_read_batch.sql have already installed the
|
-- extensions.
|
SET client_min_messages = warning;
|
CREATE EXTENSION IF NOT EXISTS test_cfs;
|
CREATE EXTENSION IF NOT EXISTS pg_buffercache;
|
RESET client_min_messages;
|
|
SHOW cfs_skip_page_checksum;
|
|
-- Part 1: rows on disk, buffers evicted, read through the CFS read path.
|
CREATE TABLE pc_lz4 (id int, payload text) WITH (algorithm = 'lz4');
|
INSERT INTO pc_lz4 SELECT g, repeat('pc ', 60) FROM generate_series(1, 500) g;
|
CHECKPOINT;
|
|
-- Force the scan through the CFS read path: evict the relation's
|
-- buffers so the count below is served by smgr reads.
|
SELECT buffers_evicted > 0 AS pc_evicted
|
FROM pg_buffercache_evict_relation('pc_lz4');
|
SELECT count(*) AS pc_rows FROM pc_lz4;
|
|
-- Part 2: the same read with the redundant page-checksum restored.
|
SET cfs_skip_page_checksum = off;
|
|
SELECT buffers_evicted > 0 AS pc_evicted
|
FROM pg_buffercache_evict_relation('pc_lz4');
|
SELECT count(*) AS pc_rows FROM pc_lz4;
|
|
SET cfs_skip_page_checksum = on;
|
|
-- Part 3: corrupt one payload byte, then restore it; the CFS CRC chain
|
-- must catch the corruption with the GUC on and off alike.
|
-- (Warnings from CfsDecompressPage() are expected and hidden: the CRC
|
-- values printed depend on the compressed bytes of the record.)
|
SET client_min_messages = error;
|
SELECT cfs_test_read_batch_corrupt('pc_lz4', 3) AS corrupt_mid_run;
|
RESET client_min_messages;
|
|
SET cfs_skip_page_checksum = off;
|
SET client_min_messages = error;
|
SELECT cfs_test_read_batch_corrupt('pc_lz4', 3) AS corrupt_mid_run;
|
RESET client_min_messages;
|
SET cfs_skip_page_checksum = on;
|
|
-- The restored record must read cleanly again through the smgr path.
|
SELECT buffers_evicted > 0 AS pc_evicted
|
FROM pg_buffercache_evict_relation('pc_lz4');
|
SELECT count(*) AS pc_rows FROM pc_lz4;
|
|
DROP TABLE pc_lz4;
|