/*-------------------------------------------------------------------------
|
* cfs_guc.c
|
* Compressed File Store (CFS) — GUC fallback parameter storage.
|
*
|
* The actual GUC table entries are registered in guc_tables.c; this module
|
* only owns the backing storage for the variables so that low-level CFS code
|
* can reference them without pulling in the full GUC machinery.
|
*
|
* Copyright (c) 2026, Kirillov Vyacheslav by AI, QDB Development Group
|
*
|
* IDENTIFICATION
|
* src/backend/storage/cfs/cfs_guc.c
|
*
|
*-------------------------------------------------------------------------
|
*/
|
#include "postgres.h"
|
|
#include "utils/guc.h"
|
|
#include "storage/cfs/cfs.h"
|
#include "storage/cfs/cfs_guc.h"
|
#include "storage/cfs/cfs_shmem.h"
|
|
/*
|
* Per-algorithm default compression levels used when a CFS relation does
|
* not specify "level" explicitly. Defaults follow the backing libraries:
|
* LZ4_compress_default (= 1) and ZSTD_CLEVEL_DEFAULT (= 3); see
|
* CFS_LZ4_LEVEL_DEFAULT / CFS_ZSTD_LEVEL_DEFAULT in cfs.h.
|
*/
|
int cfs_default_lz4_level = CFS_LZ4_LEVEL_DEFAULT;
|
int cfs_default_zstd_level = CFS_ZSTD_LEVEL_DEFAULT;
|
|
/*
|
* Default minimum gain (bytes) used when a CFS relation does not specify
|
* "min_gain_bytes" explicitly. Matches the on-disk constant
|
* CFS_MIN_GAIN_BYTES_DEFAULT and the boot value of the GUC table entry, so
|
* that the effective default is the canonical 512 regardless of which layer
|
* resolves it.
|
*/
|
int cfs_default_min_gain_bytes = CFS_MIN_GAIN_BYTES_DEFAULT;
|
|
/*
|
* Per-algorithm default compression level for the given algorithm. Read
|
* from the session's GUC at the moment of the write (the vanilla
|
* default_toast_compression pattern): nothing is cached in relation state,
|
* so a GUC change affects the very next record.
|
*
|
* RAW never compresses and has no level; callers must not ask for it.
|
*/
|
int
|
cfs_default_level_for(CfsAlgorithm algorithm)
|
{
|
switch (algorithm)
|
{
|
case CFS_ALGORITHM_LZ4:
|
return cfs_default_lz4_level;
|
case CFS_ALGORITHM_ZSTD:
|
return cfs_default_zstd_level;
|
case CFS_ALGORITHM_PGLZ:
|
return 1;
|
case CFS_ALGORITHM_ZLIB:
|
return 3;
|
default: /* RAW has no level */
|
Assert(false);
|
return CFS_COMPRESS_LEVEL_DEFAULT;
|
}
|
}
|
|
/* ================================================================
|
* Shared-memory map cache sizing
|
* ================================================================ */
|
|
/*
|
* Relation-metadata slots per map-cache partition. The default matches
|
* CFS_MAP_CACHE_RELS_PER_PART; the upper bound is
|
* CFS_MAP_CACHE_MAX_RELS_PER_PART. PGC_POSTMASTER: the value sizes the
|
* shared-memory arrays in CfsShmemSize()/CfsShmemInit(). Each slot now
|
* also carries a per-relation append lock, so exhausting the capacity is
|
* a hard ERROR — the default is intentionally generous.
|
*/
|
int cfs_map_cache_rels_per_partition = CFS_MAP_CACHE_RELS_PER_PART;
|
|
/*
|
* Per-relation statistics slots per statistics partition. The default
|
* matches CFS_STATS_SLOTS_PER_PART_DEFAULT; the bounds are
|
* CFS_STATS_SLOTS_PER_PART_MIN / CFS_STATS_SLOTS_PER_PART_MAX
|
* (cfs_stats.h). PGC_POSTMASTER: the value sizes the statistics slot and
|
* bucket-head arrays in CfsShmemSize() / cfs_stats_shmem_init() and is
|
* frozen in cfs_control->stats_slots_per_part at postmaster start for the
|
* attach-time mismatch check (EXEC_BACKEND children re-parse their own
|
* configuration). Registered in the GUC table exactly like
|
* cfs_map_cache_rels_per_partition above.
|
*/
|
int cfs_stats_slots_per_partition = CFS_STATS_SLOTS_PER_PART_DEFAULT;
|
|
/*
|
* Size (megabytes) of the shared block-map segment pool: the pool backs
|
* the per-relation "logical block -> .cfp offset" map with fixed-size
|
* segments held in shared memory and shared by all backends, replacing
|
* the former per-process full-map copies. PGC_POSTMASTER: the pool is
|
* allocated once at server start (the shared_buffers model). Zero
|
* disables the pool entirely.
|
*
|
* ponytail: with the pool off (0) the map resolves through the
|
* authoritative miss path on every uncached entry -- correct but slow;
|
* the ceiling is accepted, the upgrade path is a non-zero GUC.
|
*/
|
int cfs_map_memory = 128;
|
|
/*
|
* Size (megabytes) of the CFS read scratch arena (QDB-1513 P4-2): the
|
* shared-memory slots that carry the offloaded read path's span plans and
|
* raw compressed spans. PGC_POSTMASTER: the arena is allocated once at
|
* server start. Zero disables the arena entirely; every read then stays
|
* on the synchronous inline path (the pre-offload behaviour).
|
*
|
* The slot count is min(2 * io_max_concurrency, this budget divided by
|
* the per-slot size), so the value only caps the arena: a budget below
|
* one slot behaves like zero.
|
*/
|
int cfs_read_scratch_mb = 64;
|
|
/* ================================================================
|
* Background compaction worker parameters
|
* ================================================================ */
|
int cfs_bg_threshold_percent = 10;
|
int cfs_bg_respond_time_s = 5;
|
int cfs_bg_delay_ms = 100;
|
int cfs_bg_period_ms = 3600000;
|
int cfs_bg_min_interval_s = 86400;
|
int cfs_bg_max_relations = 2;
|
|
/*
|
* Online compaction switch (QDB-1514), declared in cfs_guc.h: true copies
|
* live records without blocking reads and writes, false restores the
|
* historical exclusive compaction. Read once at the start of each
|
* cfs_compact_relation() call.
|
*/
|
bool cfs_compact_online = true;
|
|
/* ================================================================
|
* Corruption / recovery behaviour parameters
|
* ================================================================ */
|
|
/* GUC enum lookup table for cfs_checksum_failure. */
|
const struct config_enum_entry cfs_checksum_failure_options[] = {
|
{"error", CFS_CHECKSUM_ERROR, false},
|
{"panic", CFS_CHECKSUM_PANIC, false},
|
{NULL, 0, false}
|
};
|
|
int cfs_checksum_failure = CFS_CHECKSUM_ERROR;
|
bool cfs_recovery_strict = false;
|
|
/*
|
* cfs_skip_page_checksum (QDB-1569) — when true (the default), pages
|
* whose read completed through the CFS CRC chain (header, payload and
|
* original-image CRCs) skip the redundant cluster page-checksum hash in
|
* PageIsVerified(); the header sanity checks stay. False restores the
|
* second hash (the double-check behaviour). Read in the owning backend
|
* at IO submit time (PGC_SUSET); see cfs_guc.h for the rationale.
|
*/
|
bool cfs_skip_page_checksum = true;
|
|
/*
|
* Debug fault-injection counter: when > 0, cfs_fsync_kind() pretends the
|
* fsync failed. Backed by the GUC of the same name; defaults to 0 (off).
|
*/
|
int cfs_debug_fail_fsync = 0;
|
|
/*
|
* Debug fault-injection counter: when > 0, the next that many journal
|
* truncations (the journal reset) pretend pg_truncate() failed
|
* (errno = EIO) instead of truncating the file. This lets the
|
* regression suite exercise the checkpoint's error handling for a
|
* failed journal truncation. Zero (the default) is a complete no-op.
|
*/
|
int cfs_debug_fail_truncate = 0;
|
|
/*
|
* Debug fault-injection delay (milliseconds): when > 0, every UPDATE journal
|
* record is appended in two halves separated by this delay, exposing a
|
* genuinely torn record to concurrent readers. See cfs_guc.h for the full
|
* rationale. Defaults to 0 (no-op in production).
|
*/
|
int cfs_debug_torn_journal_ms = 0;
|
|
/*
|
* Debug fault-injection bitmask: when bit (1 << CfsAlgorithm) is set, the
|
* corresponding codec reports itself as not compiled in, simulating a server
|
* built without the backing library. See cfs_guc.h for the full rationale.
|
* Defaults to 0 (no-op in production).
|
*/
|
int cfs_debug_disable_codecs = 0;
|
|
/*
|
* Debug fault-injection delay (milliseconds): when > 0, the compaction copy
|
* loop sleeps this many milliseconds per live record, stretching a
|
* compaction so a concurrent writer to an unrelated relation can be tested
|
* for lock isolation. See cfs_guc.h for the full rationale. Defaults to 0
|
* (no-op in production).
|
*/
|
int cfs_debug_compact_delay_ms = 0;
|
|
/*
|
* Debug fault-injection counter: when > 0, the next that many
|
* cfs_pwrite_all() calls simulate a pwrite() failure (errno = EIO).
|
* See cfs_guc.h for the full rationale. Defaults to 0 (no-op).
|
*/
|
int cfs_debug_fail_pwrite = 0;
|
|
/*
|
* Debug fault-injection counter: when > 0, the next that many
|
* cfs_read_raw_record() calls simulate a pread() failure of the .cfp
|
* record (errno = EIO). See cfs_guc.h for the full rationale. Defaults
|
* to 0 (no-op).
|
*/
|
int cfs_debug_fail_read = 0;
|