/*------------------------------------------------------------------------- * cfs_guc.h * Compressed File Store (CFS) — GUC fallback parameters. * * These GUC variables supply default values for the *optional* CFS reloptions * "level" and "min_gain_bytes" when a relation enables CFS (via the * "algorithm" reloption) but does not set them explicitly. They never enable * CFS by themselves: CFS is enabled only by the "algorithm" reloption. * * cfs_default_lz4_level default 1, range 1..CFS_LZ4_LEVEL_MAX * cfs_default_zstd_level default 3, range 1..CFS_ZSTD_LEVEL_MAX * cfs_default_min_gain_bytes default 512, range 0..BLCKSZ * * Copyright (c) 2026, Kirillov Vyacheslav, QDB Development Group * * IDENTIFICATION * src/include/storage/cfs/cfs_guc.h * *------------------------------------------------------------------------- */ #ifndef CFS_GUC_H #define CFS_GUC_H #include "storage/cfs/cfs.h" /* * Per-algorithm fallback compression levels, resolved at write time when * the "level" reloption is not set. Defaults follow the backing * libraries: LZ4_compress_default (= 1) and ZSTD_CLEVEL_DEFAULT (= 3). */ extern PGDLLIMPORT int cfs_default_lz4_level; extern PGDLLIMPORT int cfs_default_zstd_level; /* Per-algorithm default level lookup used by the CFS write path. */ extern int cfs_default_level_for(CfsAlgorithm algorithm); /* Fallback minimum gain (bytes) when "min_gain_bytes" reloption is not set. */ extern PGDLLIMPORT int cfs_default_min_gain_bytes; /* ================================================================ * Background compaction worker GUC parameters * ================================================================ */ /* Minimum dead-space percentage to trigger compaction. */ extern PGDLLIMPORT int cfs_bg_threshold_percent; /* Timeout (seconds) for acquiring AccessExclusiveLock. */ extern PGDLLIMPORT int cfs_bg_respond_time_s; /* Pause (ms) between relations in one pass. */ extern PGDLLIMPORT int cfs_bg_delay_ms; /* Interval (ms) between compaction passes. */ extern PGDLLIMPORT int cfs_bg_period_ms; /* Minimum interval (seconds) between compactions of the same relation. */ extern PGDLLIMPORT int cfs_bg_min_interval_s; /* Maximum relations to compact per pass. */ extern PGDLLIMPORT int cfs_bg_max_relations; /* * Online compaction switch (QDB-1514): when true, compaction copies live * records under a ShareUpdateExclusiveLock and only the short catch-up and * swap phase holds the append lock exclusively; when false, the historical * behaviour — AccessExclusiveLock on the relation plus the append lock for * the whole copy-and-swap window. SIGHUP: picked up by the next * compaction start. */ extern PGDLLIMPORT bool cfs_compact_online; /* ================================================================ * Shared-memory map cache sizing * ================================================================ */ /* * cfs_map_cache_rels_per_partition — number of relation-metadata slots per * map-cache partition. The total number of CFS relations whose metadata * (and per-relation append lock) can be held in shared memory is * CFS_MAP_CACHE_NUM_PARTITIONS times this value. Sized at server start. * When the capacity is exhausted the offending operation raises ERROR * (the relation cannot be written to without a slot); increase this value * and restart the server. */ extern PGDLLIMPORT int cfs_map_cache_rels_per_partition; /* * cfs_stats_slots_per_partition — number of per-relation statistics slots * per statistics partition (default 16, range 4..128, PGC_POSTMASTER). * The total number of tracked CFS relations is * CFS_MAP_CACHE_NUM_PARTITIONS times this value; relations beyond the * capacity are evicted by the statistics LRU and restart their counters * from zero. The value sizes the statistics slot and bucket-head arrays * at server start and is frozen in the shared control block, so changing * it requires a restart. Registered in the GUC table exactly like * cfs_map_cache_rels_per_partition above. */ extern PGDLLIMPORT int cfs_stats_slots_per_partition; /* * cfs_map_memory — size (megabytes) of the shared block-map segment pool * that replaces per-process full-map copies. 0 disables the pool (the * map then resolves through the authoritative miss path). Sized at * server start, like shared_buffers. */ extern PGDLLIMPORT int cfs_map_memory; /* * cfs_read_scratch_mb — size (megabytes) of the CFS read scratch arena * (QDB-1513 P4-2), the shared slots that let an IO worker preadv a * compressed span into shared memory and validate+decompress it outside * the backend. 0 disables the arena and keeps every read on the * synchronous inline path. Sized at server start; the GUC caps the slot * count of min(2 * io_max_concurrency, budget / slot size). */ extern PGDLLIMPORT int cfs_read_scratch_mb; /* ================================================================ * Corruption / recovery behaviour parameters * ================================================================ */ /* * cfs_checksum_failure — determines the severity when a CFS CRC or * format check fails during a normal backend read: * * error - raise ERROR (default) * panic - raise PANIC (for permanent relation) * * Note: a "warning" level that silently substitutes data is intentionally * NOT provided, because returning a fabricated page would cause silent * data divergence between primary and standby. */ typedef enum CfsChecksumFailureAction { CFS_CHECKSUM_ERROR = 0, /* raise ERROR on checksum failure */ CFS_CHECKSUM_PANIC = 1, /* raise PANIC on checksum failure */ } CfsChecksumFailureAction; extern PGDLLIMPORT int cfs_checksum_failure; /* * cfs_skip_page_checksum (QDB-1569) — when true (the default), the * buffer manager skips the redundant cluster page-checksum for pages * delivered and verified by the CFS CRC chain (header, payload and * original-image CRCs); the header sanity checks of PageIsVerified() * always remain. When false, the second full-page hash is restored. * The decision is read at IO submit time in the owning backend * (PGC_SUSET), because the buffer completion callback may run in an * IO worker with its own GUC copy. */ extern PGDLLIMPORT bool cfs_skip_page_checksum; /* * cfs_recovery_strict — when true, torn/corrupt journal or map records * encountered during recovery are treated as hard errors (ERROR/PANIC) * rather than being skipped. This provides early detection of storage * corruption at the cost of refusing to start when corruption exists. */ extern PGDLLIMPORT bool cfs_recovery_strict; /* ================================================================ * Debug / test fault injection * ================================================================ */ /* * cfs_debug_fail_fsync — when greater than zero, the next that many * cfs_fsync_kind() calls simulate an fsync() failure (errno = EIO) * instead of performing a real fsync. This lets the regression suite * exercise the checkpoint durability path (data_sync_elevel()) the same * way md.c's fsync failures are tested. Zero (the default) is a complete * no-op: production behaviour is unchanged. */ extern PGDLLIMPORT int cfs_debug_fail_fsync; /* * cfs_debug_fail_truncate — when greater than zero, the next that many * journal-reset truncations simulate a pg_truncate() failure * (errno = EIO) instead of truncating the journal, so the checkpoint * error handling of a failed journal truncation can be tested. Zero * (the default) is a complete no-op: production behaviour is unchanged. */ extern PGDLLIMPORT int cfs_debug_fail_truncate; /* * cfs_debug_torn_journal_ms — when greater than zero, every UPDATE journal * record is written in two halves separated by a sleep of this many * milliseconds. While the write is split, a concurrent reader refreshing its * local map sees a torn (half-written) 56-byte entry whose CRC has not landed * yet, so its delta replay stops early and the read can return a stale page. * This widens the torn-read race window so the coordination regression test * can exercise it deterministically. Zero (the default) is a complete no-op: * production behaviour is unchanged. */ extern PGDLLIMPORT int cfs_debug_torn_journal_ms; /* * cfs_debug_disable_codecs — bitmask of (1 << CfsAlgorithm) bits. When the * bit for an algorithm is set, that codec's available() hook reports false, * exactly as if the server had been built without the backing library * (no USE_LZ4 / USE_ZSTD). This lets a single test build simulate a standby * whose compiled-in codec set differs from the primary's — the scenario in * which WAL redo replays a CFS policy naming a codec this binary lacks. * The RAW codec (bit 0) cannot be disabled: it is the fallback the rest of * the subsystem relies on. Zero (the default) is a complete no-op: * production behaviour is unchanged. */ extern PGDLLIMPORT int cfs_debug_disable_codecs; /* * cfs_debug_compact_delay_ms — when greater than zero, the compaction copy * loop sleeps this many milliseconds after copying each live record. This * stretches a compaction that would otherwise finish in milliseconds into a * multi-second operation, so a regression test can hold the per-relation * append lock of one relation long enough to prove that a concurrent write * to an *unrelated* relation (whose hash happens to collide on the same * cache partition) is NOT blocked — the property guaranteed by embedding * the append lock in the per-relation slot instead of sharing a 64-lock * pool. Zero (the default) is a complete no-op: production behaviour is * unchanged. */ extern PGDLLIMPORT int cfs_debug_compact_delay_ms; /* * cfs_debug_fail_pwrite — when greater than zero, the next that many * cfs_pwrite_all() calls simulate a pwrite() failure (errno = EIO) instead * of writing, covering every CFS write: .cfp record appends, journal * appends and the compaction copy. This lets the regression suite * exercise the write-path error handling (the writer must fail loudly and * leave the relation usable) without needing a full disk. Zero (the * default) is a complete no-op: production behaviour is unchanged. */ extern PGDLLIMPORT int cfs_debug_fail_pwrite; /* * cfs_debug_fail_read — when greater than zero, the next that many * cfs_read_raw_record() calls simulate a pread() failure of the .cfp * record (errno = EIO) instead of reading. Both the synchronous and the * AIO read path funnel through this point, so the injection exercises the * read-path error handling (an ERROR for the querying backend, the server * stays up) on either path. Zero (the default) is a complete no-op: * production behaviour is unchanged. */ extern PGDLLIMPORT int cfs_debug_fail_read; #endif /* CFS_GUC_H */