/*------------------------------------------------------------------------- * * cfs_swap.h * The compaction swap protocol shared by the compaction driver and * the open/recovery path (see cfs_swap.c). * * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group * Portions Copyright (c) 2026, Diasoft * * src/include/storage/cfs/cfs_swap.h * *------------------------------------------------------------------------- */ #ifndef CFS_SWAP_H #define CFS_SWAP_H #include "postgres.h" #define CFS_SWAP_MARKER_SUFFIX ".cfsswap" #define CFS_CANDIDATE_SUFFIX ".new" /* * Temp suffix of the compaction candidate .cfsmap. Deliberately distinct * from the snapshot writer's ".tmp" (cfs_map_file_write_snapshot_path): * the two temp namespaces must never share a name, or a snapshot writer * running while the lock-free copy phase builds its candidate could * truncate and rename the candidate away (mixed .cfsmap on disk). The * segment temps ("<...>.cfp[.N].tmp") keep the plain ".tmp": nothing * outside compaction ever creates them. */ #define CFS_MAP_CANDIDATE_TMP_SUFFIX ".cfscand" /* Rename src to dst only when src exists; otherwise a silent no-op. */ extern int cfs_rename_if_exists(const char *src, const char *dst); /* Unlink 'path', tolerating its absence (WARNING on a real failure). */ extern void cfs_unlink_if_exists(const char *path); /* True when 'path' names an existing file. */ extern bool cfs_swap_path_exists(const char *path); /* Drop the .cfsswap commit marker, tolerating its absence. */ extern void cfs_swap_unlink_marker(const char *marker); /* * cfs_unlink_trailing_segments — remove every .cfp segment above * 'last_seg' of the chain rooted at 'cfp_path'. */ extern void cfs_unlink_trailing_segments(const char *cfp_path, uint32 last_seg); /* * cfs_recover_compaction — finish (or abort) an interrupted compaction * swap so that the .cfp / .cfsmap pair on disk is self-consistent before * the caller opens them. Must run before any backend reads the * sidecars. Covers every segment of the .cfp chain. */ extern void cfs_recover_compaction(const char *cfp_path, const char *map_path, const char *jrn_path); #endif /* CFS_SWAP_H */