Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*-------------------------------------------------------------------------
 * cfs_filename.h
 *    Compressed File Store (CFS) — frontend-safe on-disk format lexicon.
 *
 * 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
 *
 * This header is deliberately frontend-safe and is compiled into every
 * build, with or without CFS support: frontend tools that were built
 * without CFS (pg_upgrade, pg_checksums) still need the naming lexicon
 * and the .cfsmap prologue constants to recognize sidecar files and
 * refuse or skip them.  It must not include anything backend-only.
 *
 * The suffix macros, CfsFileKind and the map header constants here are
 * the single source of truth for the on-disk format; the server-side
 * cfs.h includes this header instead of redefining them.
 *
 * Copyright (c) 2026, Kirillov Vyacheslav, QDB Development Group
 *
 * IDENTIFICATION
 *    src/include/common/cfs_filename.h
 *
 *-------------------------------------------------------------------------
 */
#ifndef CFS_FILENAME_H
#define CFS_FILENAME_H
 
#include "c.h"
#include "common/relpath.h"
 
/* ----------------------------------------------------------------
 * File extension conventions
 * ---------------------------------------------------------------- */
#define CFS_DATA_SUFFIX     ".cfp"
#define CFS_MAP_SUFFIX      ".cfsmap"
#define CFS_JOURNAL_SUFFIX  ".cfsjrn"
 
/* ----------------------------------------------------------------
 * CfsFileKind — identifies which sidecar file a path refers to.
 *
 * Kept in sync with the suffix macros above through cfs_file_suffix()
 * in the server's cfs_path.c.
 * ---------------------------------------------------------------- */
typedef enum CfsFileKind
{
    CFS_FILE_DATA = 0,          /* .cfp    — append-only compressed page
                                 * data */
    CFS_FILE_MAP = 1,           /* .cfsmap — page map snapshot               */
    CFS_FILE_JOURNAL = 2,       /* .cfsjrn — page map journal                */
 
    /* sentinel — keep last */
    CFS_FILE_KIND_COUNT
} CfsFileKind;
 
/* ----------------------------------------------------------------
 * Page Map file prologue (the first bytes of .cfsmap).
 *
 * CfsMapPrologue covers only the part a frontend tool needs to check
 * (magic + version); the server treats the rest of the file as an array
 * of positional rows (storage/cfs/cfs.h).  The prologue is written once
 * when the file is created and is never rewritten.
 * ---------------------------------------------------------------- */
/*
 * CFS is pre-release and no on-disk format has shipped, so the layout may
 * change without a CFS_MAP_VERSION bump: there are no older builds to
 * stay compatible with.  A released format change must bump the version.
 */
#define CFS_MAP_MAGIC           UINT32_C(0xCF5A4700)
#define CFS_MAP_VERSION         UINT16_C(2)
 
typedef struct CfsMapPrologue
{
    uint32      magic;          /* CFS_MAP_MAGIC                        */
    uint16      version;        /* CFS_MAP_VERSION                      */
    uint16      _reserved;      /* must be zero                         */
} CfsMapPrologue;
 
StaticAssertDecl(sizeof(CfsMapPrologue) == 8,
                 "CfsMapPrologue layout matches the on-disk .cfsmap prologue");
 
/* ----------------------------------------------------------------
 * Strict parsing of a putative CFS sidecar filename.
 * ---------------------------------------------------------------- */
 
/*
 * parse_cfs_sidecar_filename
 *      Strict parsing of a putative CFS sidecar filename, mirroring the
 *      rules of parse_filename_for_nontemp_relation(): the name must be
 *      "<relfilenode>.cfp"[.<segno>], "<relfilenode>.cfsmap" or
 *      "<relfilenode>.cfsjrn", with no leading zeroes in the numbers.
 *
 * Returns true and sets *relnumber, *kind and *segno on success; returns
 * false (zeroing the outputs) for anything else, including transient
 * compaction files (".cfp.tmp", ".cfsswap", ...).
 */
extern bool parse_cfs_sidecar_filename(const char *name,
                                       RelFileNumber *relnumber,
                                       CfsFileKind *kind, unsigned *segno);
 
#endif                          /* CFS_FILENAME_H */