Исходный код СУБД 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
/*-------------------------------------------------------------------------
 *
 * cfs_sync.h
 *    The CFS side of the checkpointer sync queue (see cfs_sync.c): the
 *    file-tag layout shared with storage/sync, the fsync/unlink request
 *    registration API and the four callbacks sync.c dispatches to.
 *
 *    Kept free of the smgr bridge: the storage layer and the bgworker
 *    register sidecar writes through this header alone.
 *
 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
 * Portions Copyright (c) 2026, Diasoft
 *
 * src/include/storage/cfs/cfs_sync.h
 *
 *-------------------------------------------------------------------------
 */
 
#ifndef CFS_SYNC_H
#define CFS_SYNC_H
 
#include "postgres.h"
 
#include "storage/cfs/cfs_path.h"
#include "storage/relfilelocator.h"
#include "storage/sync.h"
 
/*
 * The CFS sync handler reuses the standard FileTag structure.  The 'segno'
 * field stores the CfsFileKind value (CFS_FILE_DATA / CFS_FILE_MAP /
 * CFS_FILE_JOURNAL), and 'forknum' is always MAIN_FORKNUM.
 * ---------------------------------------------------------------- */
 
/* Populate a file tag describing one CFS sidecar file. */
#define INIT_CFS_FILETAG(a,xx_rlocator,xx_kind) \
( \
    memset(&(a), 0, sizeof(FileTag)), \
    (a).handler = SYNC_HANDLER_CFS, \
    (a).rlocator = (xx_rlocator), \
    (a).forknum = MAIN_FORKNUM, \
    (a).segno = (uint64) (xx_kind) \
)
 
/*
 * CFS sidecar files (.cfp/.cfsmap/.cfsjrn) register fsync and unlink
 * requests through the standard sync queue so that the checkpointer
 * fsyncs them at checkpoint time, exactly like md.c does for base
 * relation segments.
 * ---------------------------------------------------------------- */
 
/* fsync a CFS sidecar file identified by ftag; write path into *path. */
extern int  cfs_syncfiletag(const FileTag *ftag, char *path);
 
/* Unlink a CFS sidecar file identified by ftag; write path into *path. */
extern int  cfs_unlinkfiletag(const FileTag *ftag, char *path);
 
/* Check whether two CFS file tags refer to the same relation. */
extern bool cfs_filetagmatches(const FileTag *ftag, const FileTag *candidate);
 
/*
 * cfs_register_dirty_file — register an fsync request for one sidecar
 * kind of a relation fork.  Called by the storage layer after a write
 * to .cfp / .cfsjrn (TEMP relations are never registered).
 */
extern void cfs_register_dirty_file(RelFileLocatorBackend rlocator,
                                    ForkNumber forknum, CfsFileKind kind);
 
/*
 * cfs_register_unlink_file — schedule the removal of a sidecar file after
 * the next checkpoint (used by cfs_smgr_unlink for permanent relations).
 */
extern void cfs_register_unlink_file(RelFileLocatorBackend rlocator,
                                     ForkNumber forknum, CfsFileKind kind);
 
/*
 * cfs_forget_sync_requests — drop all pending fsync/unlink requests for
 * a relation fork (used when the relation is dropped immediately).
 */
extern void cfs_forget_sync_requests(RelFileLocatorBackend rlocator,
                                     ForkNumber forknum);
 
/*
 * cfs_forget_database_sync_requests — drop all pending fsync/unlink
 * requests for every sidecar file of a whole database (used when the
 * database is dropped; the mirror of ForgetDatabaseSyncRequests()).
 */
extern void cfs_forget_database_sync_requests(Oid dbid);
 
#endif                          /* CFS_SYNC_H */