Исходный код СУБД 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*-------------------------------------------------------------------------
 * 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 */