-- test_cfs--1.0.sql - test module for Compressed File Store (CFS) CREATE FUNCTION cfs_run_tests( OUT test_name text, OUT result text, OUT detail text) RETURNS SETOF record AS 'MODULE_PATHNAME', 'cfs_run_tests' LANGUAGE C STRICT; CREATE FUNCTION test_cfs_roundtrip(algorithm text, payload bytea, level int) RETURNS boolean AS 'MODULE_PATHNAME', 'test_cfs_roundtrip' LANGUAGE C STRICT; CREATE FUNCTION test_cfs_corrupt_crc(algorithm text) RETURNS text AS 'MODULE_PATHNAME', 'test_cfs_corrupt_crc' LANGUAGE C STRICT; CREATE FUNCTION test_cfs_codec_available(algorithm text) RETURNS boolean AS 'MODULE_PATHNAME', 'test_cfs_codec_available' LANGUAGE C STRICT; -- On-disk format, path and fsck test runners. CREATE FUNCTION cfs_run_format_tests( OUT test_name text, OUT result text, OUT detail text) RETURNS SETOF record AS 'MODULE_PATHNAME', 'cfs_run_format_tests' LANGUAGE C STRICT; CREATE FUNCTION cfs_run_path_tests( OUT test_name text, OUT result text, OUT detail text) RETURNS SETOF record AS 'MODULE_PATHNAME', 'cfs_run_path_tests' LANGUAGE C STRICT; CREATE FUNCTION cfs_run_fsck_tests( OUT test_name text, OUT result text, OUT detail text) RETURNS SETOF record AS 'MODULE_PATHNAME', 'cfs_run_fsck_tests' LANGUAGE C STRICT; -- Autonomous storage layer tests (create/open, write/read, journal -- replay, checkpoint, crash injection, CfsStorageOps dispatch, compaction). CREATE FUNCTION cfs_run_storage_tests( OUT test_name text, OUT result text, OUT detail text) RETURNS SETOF record AS 'MODULE_PATHNAME', 'cfs_run_storage_tests' LANGUAGE C STRICT; -- Shared-memory map cache, statistics, eviction and cached I/O. CREATE FUNCTION cfs_run_shmem_tests( OUT test_name text, OUT result text, OUT detail text) RETURNS SETOF record AS 'MODULE_PATHNAME', 'cfs_run_shmem_tests' LANGUAGE C STRICT; -- Assert-only shared-map tests (driven by t/002_cfs_shmem_hooks.pl). CREATE FUNCTION cfs_run_shmem_hook_tests( OUT test_name text, OUT result text, OUT detail text) RETURNS SETOF record AS 'MODULE_PATHNAME', 'cfs_run_shmem_hook_tests' LANGUAGE C STRICT; -- .cfp segmentation (1 GiB segment rollover) and streaming fsck on -- files larger than MaxAllocSize, plus journal generation monotonicity. CREATE FUNCTION cfs_run_segment_tests( OUT test_name text, OUT result text, OUT detail text) RETURNS SETOF record AS 'MODULE_PATHNAME', 'cfs_run_segment_tests' LANGUAGE C STRICT; -- Inspect the resolved CFS policy of a relation (reloptions + GUC -- fallback + TOAST / index inheritance). CREATE FUNCTION cfs_relation_policy(regclass, OUT is_cfs boolean, OUT algorithm text, OUT level integer, OUT min_gain_bytes integer) AS 'MODULE_PATHNAME', 'cfs_relation_policy' LANGUAGE C STRICT; -- Report whether the sidecar files (.cfp/.cfsmap/.cfsjrn) exist on -- disk for a relation's main fork. Used to verify that the smgr layer -- creates and removes sidecars together with the relation lifecycle. CREATE FUNCTION cfs_relation_has_sidecars(regclass) RETURNS boolean AS 'MODULE_PATHNAME', 'cfs_relation_has_sidecars' LANGUAGE C STRICT; -- Read the last record of the relation's .cfp file: its algorithm and -- sizes (the record header carries no compression level - decompression -- does not need it). Used to pin the runtime level resolve to the -- actual bytes: identical pages written under different effective -- levels must yield records of different compressed_size. CREATE FUNCTION cfs_relation_last_record(regclass, OUT algorithm text, OUT original_size bigint, OUT compressed_size bigint, OUT records bigint) AS 'MODULE_PATHNAME', 'cfs_relation_last_record' LANGUAGE C STRICT; -- Queue a deferred CFS policy publication for the relation (as if an ALTER -- had changed the level), and inspect the deferred/effective shared state. CREATE FUNCTION cfs_test_defer_publish(regclass, int) RETURNS void AS 'MODULE_PATHNAME', 'cfs_test_defer_publish' LANGUAGE C STRICT; CREATE FUNCTION cfs_test_publish_pending(regclass) RETURNS boolean AS 'MODULE_PATHNAME', 'cfs_test_publish_pending' LANGUAGE C STRICT; CREATE FUNCTION cfs_test_shared_level(regclass) RETURNS integer AS 'MODULE_PATHNAME', 'cfs_test_shared_level' LANGUAGE C STRICT; -- Same two probes addressed by relfilenode (in the current database, -- default tablespace): the relation itself may have been rewritten to a -- new storage node, and the check must target the old one. CREATE FUNCTION cfs_test_publish_pending_at(oid) RETURNS boolean AS 'MODULE_PATHNAME', 'cfs_test_publish_pending_at' LANGUAGE C STRICT; CREATE FUNCTION cfs_test_shared_level_at(oid) RETURNS integer AS 'MODULE_PATHNAME', 'cfs_test_shared_level_at' LANGUAGE C STRICT; -- Dump the .cfsjrn header summary together with the map row generation -- watermark computed from the .cfsmap entries. CREATE FUNCTION cfs_test_journal_header(oid) RETURNS table(incarnation integer, max_generation integer, map_max_generation bigint) AS 'MODULE_PATHNAME', 'cfs_test_journal_header' LANGUAGE C STRICT; CREATE FUNCTION cfs_test_publish_false_at(oid) RETURNS void AS 'MODULE_PATHNAME', 'cfs_test_publish_false_at' LANGUAGE C STRICT; CREATE FUNCTION cfs_test_sidecars_at(oid) RETURNS boolean AS 'MODULE_PATHNAME', 'cfs_test_sidecars_at' LANGUAGE C STRICT; -- True when the shared policy cache holds a slot for the relfilenode, -- whatever the slot says — distinguishes "no slot" from "a slot lying -- is_cfs=false". CREATE FUNCTION cfs_test_slot_present_at(oid) RETURNS boolean AS 'MODULE_PATHNAME', 'cfs_test_slot_present_at' LANGUAGE C STRICT; -- Read block 0 through the smgr bridge after dropping the metadata slot and -- report the published nblocks value (NULL when nothing was published). CREATE FUNCTION cfs_test_smgr_read_meta(regclass) RETURNS bigint AS 'MODULE_PATHNAME', 'cfs_test_smgr_read_meta' LANGUAGE C STRICT; -- Measure the size through the smgr bridge with a cold metadata slot and -- report how many throwaway full-map handles it opened. CREATE FUNCTION cfs_test_smgr_size_full_opens(regclass) RETURNS bigint AS 'MODULE_PATHNAME', 'cfs_test_smgr_size_full_opens' LANGUAGE C STRICT; -- Run a real immediate checkpoint and report how many throwaway full-map -- handles the CFS checkpoint path opened for THIS relation (0 expected: -- the fold works off the sidecar files and never assembles the in-memory -- map; the per-relation count keeps unrelated background opens out of -- the measurement). CREATE FUNCTION cfs_test_checkpoint_full_opens(regclass) RETURNS bigint AS 'MODULE_PATHNAME', 'cfs_test_checkpoint_full_opens' LANGUAGE C STRICT; -- Run smgrimmedsync() on the relation's main fork: the SQL-reachable way -- to open a CFS full map handle lock-free on demand (immedsync path). CREATE FUNCTION cfs_test_immedsync(regclass) RETURNS boolean AS 'MODULE_PATHNAME', 'cfs_test_immedsync' LANGUAGE C STRICT; -- The pin-owner registry must exist for every cfs_map_memory value (0 -- included), or pins of dead processes could never be reaped. CREATE FUNCTION cfs_test_map_pin_registry() RETURNS boolean AS 'MODULE_PATHNAME', 'cfs_test_map_pin_registry' LANGUAGE C STRICT; -- Run smgrtruncate() on the relation's main fork through the backend's -- cached SMgrRelation (and its cached CFS handle): the SQL-reachable way -- to truncate with a handle that predates a sidecar swap. CREATE FUNCTION cfs_test_smgr_truncate(regclass, int) RETURNS boolean AS 'MODULE_PATHNAME', 'cfs_test_smgr_truncate' LANGUAGE C STRICT; -- The D1 two-backend write-path exercise: write one page of a synthetic -- CFS relation through the real locked append path (pinned metadata slot, -- append lock, handle refresh, cfs_write_page_cached) and return the -- record's .cfp offset; verify reads every block back and proves the -- offsets are strictly increasing (no backend overwrote a peer's record); -- cleanup drops the synthetic sidecars and cache entries. CREATE FUNCTION cfs_test_tail_write(bigint, int) RETURNS bigint AS 'MODULE_PATHNAME', 'cfs_test_tail_write' LANGUAGE C STRICT; CREATE FUNCTION cfs_test_tail_verify(bigint, int) RETURNS bigint AS 'MODULE_PATHNAME', 'cfs_test_tail_verify' LANGUAGE C STRICT; CREATE FUNCTION cfs_test_tail_cleanup(bigint) RETURNS boolean AS 'MODULE_PATHNAME', 'cfs_test_tail_cleanup' LANGUAGE C STRICT; -- QDB-1513 batched read path: advisory contiguous-run lengths and a -- byte-for-byte comparison of cfs_read_pages_batch() against the per-block -- cfs_read_page_cached() on a real relation (full private-map handle). CREATE FUNCTION cfs_test_read_batch(regclass) RETURNS TABLE(run0 integer, run_max integer, pages_checked bigint, batch_ok boolean) AS 'MODULE_PATHNAME', 'cfs_test_read_batch' LANGUAGE C STRICT; -- QDB-1513 span failure semantics: corrupt one payload byte of a record -- inside a contiguous run, demand CFS_STORAGE_CORRUPT with the exact -- failing block from a batched range read, restore and demand a clean -- re-read. CREATE FUNCTION cfs_test_read_batch_corrupt(regclass, integer) RETURNS text AS 'MODULE_PATHNAME', 'cfs_test_read_batch_corrupt' LANGUAGE C STRICT; CREATE FUNCTION cfs_test_lz4_record(regclass, integer, OUT records bigint, OUT record_offset bigint, OUT record_end bigint, OUT page bytea, OUT payload bytea, OUT matches_fast boolean, OUT matches_hc boolean) RETURNS record AS 'MODULE_PATHNAME', 'cfs_test_lz4_record' LANGUAGE C STRICT;