1 /*-------------------------------------------------------------------------
4 * storage manager switch public interface declarations.
7 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/storage/smgr.h
12 *-------------------------------------------------------------------------
17 #include "lib/ilist.h"
18 #include "storage/block.h"
19 #include "storage/relfilelocator.h"
22 * smgr.c maintains a table of SMgrRelation objects, which are essentially
23 * cached file handles. An SMgrRelation is created (if not already present)
24 * by smgropen(), and destroyed by smgrdestroy(). Note that neither of these
25 * operations imply I/O, they just create or destroy a hashtable entry. (But
26 * smgrdestroy() may release associated resources, such as OS-level file
29 * An SMgrRelation may be "pinned", to prevent it from being destroyed while
30 * it's in use. We use this to prevent pointers in relcache to smgr from being
31 * invalidated. SMgrRelations that are not pinned are deleted at end of
34 typedef struct SMgrRelationData
36 /* rlocator is the hashtable lookup key, so it must be first! */
37 RelFileLocatorBackend smgr_rlocator
; /* relation physical identifier */
40 * The following fields are reset to InvalidBlockNumber upon a cache flush
41 * event, and hold the last known size for each fork. This information is
42 * currently only reliable during recovery, since there is no cache
43 * invalidation for fork extension.
45 BlockNumber smgr_targblock
; /* current insertion target block */
46 BlockNumber smgr_cached_nblocks
[MAX_FORKNUM
+ 1]; /* last known size */
48 /* additional public fields may someday exist here */
51 * Fields below here are intended to be private to smgr.c and its
52 * submodules. Do not touch them from elsewhere.
54 int smgr_which
; /* storage manager selector */
57 * for md.c; per-fork arrays of the number of open segments
58 * (md_num_open_segs) and the segments themselves (md_seg_fds).
60 int md_num_open_segs
[MAX_FORKNUM
+ 1];
61 struct _MdfdVec
*md_seg_fds
[MAX_FORKNUM
+ 1];
64 * Pinning support. If unpinned (ie. pincount == 0), 'node' is a list
65 * link in list of all unpinned SMgrRelations.
71 typedef SMgrRelationData
*SMgrRelation
;
73 #define SmgrIsTemp(smgr) \
74 RelFileLocatorBackendIsTemp((smgr)->smgr_rlocator)
76 extern void smgrinit(void);
77 extern SMgrRelation
smgropen(RelFileLocator rlocator
, ProcNumber backend
);
78 extern bool smgrexists(SMgrRelation reln
, ForkNumber forknum
);
79 extern void smgrpin(SMgrRelation reln
);
80 extern void smgrunpin(SMgrRelation reln
);
81 extern void smgrclose(SMgrRelation reln
);
82 extern void smgrdestroyall(void);
83 extern void smgrrelease(SMgrRelation reln
);
84 extern void smgrreleaseall(void);
85 extern void smgrreleaserellocator(RelFileLocatorBackend rlocator
);
86 extern void smgrcreate(SMgrRelation reln
, ForkNumber forknum
, bool isRedo
);
87 extern void smgrdosyncall(SMgrRelation
*rels
, int nrels
);
88 extern void smgrdounlinkall(SMgrRelation
*rels
, int nrels
, bool isRedo
);
89 extern void smgrextend(SMgrRelation reln
, ForkNumber forknum
,
90 BlockNumber blocknum
, const void *buffer
, bool skipFsync
);
91 extern void smgrzeroextend(SMgrRelation reln
, ForkNumber forknum
,
92 BlockNumber blocknum
, int nblocks
, bool skipFsync
);
93 extern bool smgrprefetch(SMgrRelation reln
, ForkNumber forknum
,
94 BlockNumber blocknum
, int nblocks
);
95 extern uint32
smgrmaxcombine(SMgrRelation reln
, ForkNumber forknum
,
96 BlockNumber blocknum
);
97 extern void smgrreadv(SMgrRelation reln
, ForkNumber forknum
,
99 void **buffers
, BlockNumber nblocks
);
100 extern void smgrwritev(SMgrRelation reln
, ForkNumber forknum
,
101 BlockNumber blocknum
,
102 const void **buffers
, BlockNumber nblocks
,
104 extern void smgrwriteback(SMgrRelation reln
, ForkNumber forknum
,
105 BlockNumber blocknum
, BlockNumber nblocks
);
106 extern BlockNumber
smgrnblocks(SMgrRelation reln
, ForkNumber forknum
);
107 extern BlockNumber
smgrnblocks_cached(SMgrRelation reln
, ForkNumber forknum
);
108 extern void smgrtruncate(SMgrRelation reln
, ForkNumber
*forknum
,
109 int nforks
, BlockNumber
*nblocks
);
110 extern void smgrimmedsync(SMgrRelation reln
, ForkNumber forknum
);
111 extern void smgrregistersync(SMgrRelation reln
, ForkNumber forknum
);
112 extern void AtEOXact_SMgr(void);
113 extern bool ProcessBarrierSmgrRelease(void);
116 smgrread(SMgrRelation reln
, ForkNumber forknum
, BlockNumber blocknum
,
119 smgrreadv(reln
, forknum
, blocknum
, &buffer
, 1);
123 smgrwrite(SMgrRelation reln
, ForkNumber forknum
, BlockNumber blocknum
,
124 const void *buffer
, bool skipFsync
)
126 smgrwritev(reln
, forknum
, blocknum
, &buffer
, 1, skipFsync
);