/*-------------------------------------------------------------------------
|
* cfs_cfp.h
|
* Compressed File Store (CFS) — the segmented .cfp data chain, one
|
* module.
|
*
|
* Everything that names, opens, switches, walks, sizes or fsyncs the
|
* .cfp segment chain of a relation fork lives here: segment path
|
* building, the append-segment switch, the global append EOF, the
|
* read-cache descriptor and the stat walk. Direct reads of .cfp bytes
|
* outside this module (and cfs_format.c / cfs_codec.c) are a review
|
* blocker - the merge-gate rule in AGENTS.md.
|
*
|
* Copyright (c) 2026, Kirillov Vyacheslav by AI, QDB Development Group
|
*
|
* IDENTIFICATION
|
* src/include/storage/cfs/cfs_cfp.h
|
*
|
*-------------------------------------------------------------------------
|
*/
|
#ifndef CFS_CFP_H
|
#define CFS_CFP_H
|
|
#include "postgres.h"
|
|
#include "storage/block.h"
|
#include "storage/cfs/cfs_io.h"
|
|
/* The handle type: a forward declaration keeps this header free of
|
* cfs_storage.h (breaking the include cycle through the storage layer).
|
* Pass CfsRelation * or struct CfsRelation * interchangeably. */
|
struct CfsRelation;
|
|
/*
|
* Open (and optionally create) one sidecar file. Returns fd or -1; a
|
* failure is reported as WARNING by this helper. Shared by the .cfp
|
* segment openers below and by the sidecar open paths in cfs_storage.c.
|
*/
|
extern int cfs_open_sidecar(const char *path, int flags, bool create);
|
|
/*
|
* fsync the parent directory of 'path' (so renames / unlinks of files in
|
* it are durable). fsync_parent_path() is private to fd.c, so derive the
|
* directory here and use the exported fsync_fname().
|
*/
|
extern void cfs_fsync_parent_dir(const char *path, int elevel);
|
|
/*
|
* Build the path of segment 'segno' of a segmented file chain: segment 0
|
* is the base path itself, segment N > 0 is "<base>.N". Returns a
|
* palloc'd string. Every consumer of the segmented sidecars (.cfp
|
* reader, writer, fsck, compaction) names segments through this one
|
* helper.
|
*/
|
extern char *cfs_segment_path(const char *base_path, uint32 segno);
|
|
/*
|
* The same segment path with a swap-protocol suffix (".tmp", ".new"):
|
* the staged and the activated candidate of segment 'segno'.
|
*/
|
extern char *cfs_segment_suffixed(const char *base_path, uint32 segno,
|
const char *suffix);
|
|
/*
|
* Switch the append descriptor of 'cfs' to segment 'segno', creating the
|
* segment when the handle is writable.
|
*/
|
extern int cfs_cfp_switch_append_segment(struct CfsRelation *cfs,
|
uint32 segno);
|
|
/*
|
* Discover the append EOF of the segmented .cfp chain (the global offset
|
* past the last existing segment's end).
|
*/
|
extern off_t cfs_cfp_discover_eof(struct CfsRelation *cfs);
|
|
/*
|
* Return a descriptor positioned for reading .cfp segment 'segno': the
|
* append descriptor when it matches, otherwise a lazily opened one-entry
|
* read cache. Returns -1 when the segment cannot be opened.
|
*/
|
extern int cfs_cfp_read_segment_fd(struct CfsRelation *cfs, uint32 segno);
|
|
/*
|
* Close a .cfp descriptor cached in a CfsRelation: submit (and, per the
|
* io method, wait for) any staged or in-flight AIO that still names the
|
* descriptor before close(2) recycles the number — the FileClose()
|
* discipline, needed since the P4-2 read offload stores these raw
|
* descriptors in AIO handles.
|
*/
|
extern void cfs_cfp_close_fd(int fd);
|
|
/*
|
* Stat-walk the segmented .cfp chain rooted at 'cfp_path'. Sets
|
* *total_size to the global EOF and *closed_padding to the bytes the
|
* CLOSED segments never received (structural padding, neither live data
|
* nor dead). Either out pointer may be NULL. Returns false when the
|
* chain holds no readable segment.
|
*/
|
extern bool cfs_cfp_chain_stat(const char *cfp_path, uint64 *total_size,
|
uint64 *closed_padding);
|
|
/*
|
* fsync every existing .cfp segment of the handle, walking the chain by
|
* path (other backends may have written earlier segments through their
|
* own handles).
|
*/
|
extern int cfs_fsync_cfp_segments(struct CfsRelation *cfs);
|
|
#endif /* CFS_CFP_H */
|