1 /*-------------------------------------------------------------------------
4 * storage manager switch public interface declarations.
7 * Portions Copyright (c) 1996-2021, 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/relfilenode.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 smgrclose(). Note that neither of these
25 * operations imply I/O, they just create or destroy a hashtable entry.
26 * (But smgrclose() may release associated resources, such as OS-level file
29 * An SMgrRelation may have an "owner", which is just a pointer to it from
30 * somewhere else; smgr.c will clear this pointer if the SMgrRelation is
31 * closed. We use this to avoid dangling pointers from relcache to smgr
32 * without having to make the smgr explicitly aware of relcache. There
33 * can't be more than one "owner" pointer per SMgrRelation, but that's
36 * SMgrRelations that do not have an "owner" are considered to be transient,
37 * and are deleted at end of transaction.
39 typedef struct SMgrRelationData
41 /* rnode is the hashtable lookup key, so it must be first! */
42 RelFileNodeBackend smgr_rnode
; /* relation physical identifier */
44 /* pointer to owning pointer, or NULL if none */
45 struct SMgrRelationData
**smgr_owner
;
48 * The following fields are reset to InvalidBlockNumber upon a cache flush
49 * event, and hold the last known size for each fork. This information is
50 * currently only reliable during recovery, since there is no cache
51 * invalidation for fork extension.
53 BlockNumber smgr_targblock
; /* current insertion target block */
54 BlockNumber smgr_cached_nblocks
[MAX_FORKNUM
+ 1]; /* last known size */
56 /* additional public fields may someday exist here */
59 * Fields below here are intended to be private to smgr.c and its
60 * submodules. Do not touch them from elsewhere.
62 int smgr_which
; /* storage manager selector */
65 * for md.c; per-fork arrays of the number of open segments
66 * (md_num_open_segs) and the segments themselves (md_seg_fds).
68 int md_num_open_segs
[MAX_FORKNUM
+ 1];
69 struct _MdfdVec
*md_seg_fds
[MAX_FORKNUM
+ 1];
71 /* if unowned, list link in list of all unowned SMgrRelations */
75 typedef SMgrRelationData
*SMgrRelation
;
77 #define SmgrIsTemp(smgr) \
78 RelFileNodeBackendIsTemp((smgr)->smgr_rnode)
80 extern void smgrinit(void);
81 extern SMgrRelation
smgropen(RelFileNode rnode
, BackendId backend
);
82 extern bool smgrexists(SMgrRelation reln
, ForkNumber forknum
);
83 extern void smgrsetowner(SMgrRelation
*owner
, SMgrRelation reln
);
84 extern void smgrclearowner(SMgrRelation
*owner
, SMgrRelation reln
);
85 extern void smgrclose(SMgrRelation reln
);
86 extern void smgrcloseall(void);
87 extern void smgrclosenode(RelFileNodeBackend rnode
);
88 extern void smgrcreate(SMgrRelation reln
, ForkNumber forknum
, bool isRedo
);
89 extern void smgrdosyncall(SMgrRelation
*rels
, int nrels
);
90 extern void smgrdounlinkall(SMgrRelation
*rels
, int nrels
, bool isRedo
);
91 extern void smgrextend(SMgrRelation reln
, ForkNumber forknum
,
92 BlockNumber blocknum
, char *buffer
, bool skipFsync
);
93 extern bool smgrprefetch(SMgrRelation reln
, ForkNumber forknum
,
94 BlockNumber blocknum
);
95 extern void smgrread(SMgrRelation reln
, ForkNumber forknum
,
96 BlockNumber blocknum
, char *buffer
);
97 extern void smgrwrite(SMgrRelation reln
, ForkNumber forknum
,
98 BlockNumber blocknum
, char *buffer
, bool skipFsync
);
99 extern void smgrwriteback(SMgrRelation reln
, ForkNumber forknum
,
100 BlockNumber blocknum
, BlockNumber nblocks
);
101 extern BlockNumber
smgrnblocks(SMgrRelation reln
, ForkNumber forknum
);
102 extern BlockNumber
smgrnblocks_cached(SMgrRelation reln
, ForkNumber forknum
);
103 extern void smgrtruncate(SMgrRelation reln
, ForkNumber
*forknum
,
104 int nforks
, BlockNumber
*nblocks
);
105 extern void smgrimmedsync(SMgrRelation reln
, ForkNumber forknum
);
106 extern void AtEOXact_SMgr(void);