/*-------------------------------------------------------------------------
|
* cfs_path.h
|
* Compressed File Store (CFS) — sidecar filename helpers.
|
*
|
* Sidecar files are named after the MAIN fork path of a relation, with an
|
* extra suffix that identifies the kind of file:
|
*
|
* <relpath>.cfp compressed page data (may be segmented: .cfp.N)
|
* <relpath>.cfsmap page map snapshot
|
* <relpath>.cfsjrn page map journal
|
*
|
* The functions here are the single source of truth for sidecar naming, used
|
* by the storage layer, the integrity checker and backup utilities. Backend-
|
* local (TEMP) locators are not supported in the first implementation and the
|
* helpers report that by returning NULL / false.
|
*
|
* Copyright (c) 2026, Kirillov Vyacheslav, QDB Development Group
|
*
|
* IDENTIFICATION
|
* src/include/storage/cfs/cfs_path.h
|
*
|
*-------------------------------------------------------------------------
|
*/
|
#ifndef CFS_PATH_H
|
#define CFS_PATH_H
|
|
#include "common/relpath.h"
|
#include "common/cfs_filename.h"
|
#include "storage/cfs/cfs.h"
|
#include "storage/relfilelocator.h"
|
|
/* Return the on-disk suffix (".cfp" / ".cfsmap" / ".cfsjrn") for a kind. */
|
extern const char *cfs_file_suffix(CfsFileKind kind);
|
|
/*
|
* cfs_locator_supported
|
* Return true when CFS sidecar files may exist for this locator.
|
* Temporary (backend-local) locators are unsupported.
|
*/
|
extern bool cfs_locator_supported(RelFileLocatorBackend rlocator);
|
|
/*
|
* cfs_make_filename
|
* Build the sidecar path (relative to DataDir) for the given relation
|
* fork and file kind. CFS only applies to MAIN_FORKNUM, so the base
|
* path is always the relation's main-fork path regardless of 'forknum'.
|
*
|
* Returns a palloc'd string, or NULL when the locator is unsupported
|
* (temporary relations).
|
*/
|
extern char *cfs_make_filename(RelFileLocatorBackend rlocator,
|
ForkNumber forknum, CfsFileKind kind);
|
|
/*
|
* cfs_make_segment_filename
|
* Like cfs_make_filename(), but for a numbered .cfp segment. For
|
* segno == 0 the result is identical to cfs_make_filename(). For
|
* segno > 0 the suffix ".N" is appended (e.g. "<relpath>.cfp.1").
|
* Map and journal files are single-segment, so segno > 0 is only
|
* meaningful for CFS_FILE_DATA.
|
*/
|
extern char *cfs_make_segment_filename(RelFileLocatorBackend rlocator,
|
ForkNumber forknum,
|
CfsFileKind kind, uint32 segno);
|
|
/*
|
* cfs_is_sidecar_filename
|
* Return true when 'name' (a path or basename) ends with a CFS sidecar
|
* suffix, optionally followed by a segment number (".cfp.1").
|
*/
|
extern bool cfs_is_sidecar_filename(const char *name);
|
|
/*
|
* cfs_sidecar_kind_from_suffix
|
* If 'name' ends with a recognised CFS sidecar suffix, set *kind and
|
* return true; otherwise return false (and leave *kind untouched).
|
*/
|
extern bool cfs_sidecar_kind_from_suffix(const char *name, CfsFileKind *kind);
|
|
/*
|
* cfs_strip_trailing_segment
|
* Truncate a single trailing ".<digits>" segment component in place
|
* (e.g. "12345.cfp.1" -> "12345.cfp"). Anything that is not a pure
|
* numeric suffix is left untouched.
|
*/
|
extern void cfs_strip_trailing_segment(char *s);
|
|
/* ----------------------------------------------------------------
|
* Sidecar size helpers
|
*
|
* These functions stat() the sidecar files of a relation (or every
|
* relation in a database / tablespace) and return the on-disk byte
|
* count. They are used by the size reporting SQL functions
|
* (pg_relation_size, pg_total_relation_size, ...) so that the numbers
|
* reported to users reflect the *physical* storage consumed by CFS,
|
* not just the (typically empty) base main-fork file.
|
*
|
* Non-CFS relations naturally report 0 because no sidecar files exist.
|
* ---------------------------------------------------------------- */
|
|
/*
|
* cfs_relation_sidecar_size
|
* On-disk size of all three sidecar files for 'rlocator', including
|
* any numbered .cfp.N segments. Returns 0 when the locator is
|
* unsupported (TEMP) or no sidecar files exist.
|
*/
|
extern int64 cfs_relation_sidecar_size(RelFileLocatorBackend rlocator);
|
|
/*
|
* cfs_segmented_sidecar_size
|
* On-disk size of one sidecar kind for 'rlocator', summed over every
|
* existing segment (".cfp", ".cfp.1", ...). Single-segment kinds
|
* (map, journal) naturally stop after segment 0.
|
*/
|
extern int64 cfs_segmented_sidecar_size(RelFileLocatorBackend rlocator,
|
ForkNumber forknum, CfsFileKind kind);
|
|
#endif /* CFS_PATH_H */
|