PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
smgr.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * smgr.h
4  * storage manager switch public interface declarations.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/smgr.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef SMGR_H
15 #define SMGR_H
16 
17 #include "fmgr.h"
18 #include "storage/block.h"
19 #include "storage/relfilenode.h"
20 
21 
22 /*
23  * smgr.c maintains a table of SMgrRelation objects, which are essentially
24  * cached file handles. An SMgrRelation is created (if not already present)
25  * by smgropen(), and destroyed by smgrclose(). Note that neither of these
26  * operations imply I/O, they just create or destroy a hashtable entry.
27  * (But smgrclose() may release associated resources, such as OS-level file
28  * descriptors.)
29  *
30  * An SMgrRelation may have an "owner", which is just a pointer to it from
31  * somewhere else; smgr.c will clear this pointer if the SMgrRelation is
32  * closed. We use this to avoid dangling pointers from relcache to smgr
33  * without having to make the smgr explicitly aware of relcache. There
34  * can't be more than one "owner" pointer per SMgrRelation, but that's
35  * all we need.
36  *
37  * SMgrRelations that do not have an "owner" are considered to be transient,
38  * and are deleted at end of transaction.
39  */
40 typedef struct SMgrRelationData
41 {
42  /* rnode is the hashtable lookup key, so it must be first! */
43  RelFileNodeBackend smgr_rnode; /* relation physical identifier */
44 
45  /* pointer to owning pointer, or NULL if none */
47 
48  /*
49  * These next three fields are not actually used or manipulated by smgr,
50  * except that they are reset to InvalidBlockNumber upon a cache flush
51  * event (in particular, upon truncation of the relation). Higher levels
52  * store cached state here so that it will be reset when truncation
53  * happens. In all three cases, InvalidBlockNumber means "unknown".
54  */
55  BlockNumber smgr_targblock; /* current insertion target block */
56  BlockNumber smgr_fsm_nblocks; /* last known size of fsm fork */
57  BlockNumber smgr_vm_nblocks; /* last known size of vm fork */
58 
59  /* additional public fields may someday exist here */
60 
61  /*
62  * Fields below here are intended to be private to smgr.c and its
63  * submodules. Do not touch them from elsewhere.
64  */
65  int smgr_which; /* storage manager selector */
66 
67  /*
68  * for md.c; per-fork arrays of the number of open segments
69  * (md_num_open_segs) and the segments themselves (md_seg_fds).
70  */
73 
74  /* if unowned, list link in list of all unowned SMgrRelations */
77 
79 
80 #define SmgrIsTemp(smgr) \
81  RelFileNodeBackendIsTemp((smgr)->smgr_rnode)
82 
83 extern void smgrinit(void);
84 extern SMgrRelation smgropen(RelFileNode rnode, BackendId backend);
85 extern bool smgrexists(SMgrRelation reln, ForkNumber forknum);
86 extern void smgrsetowner(SMgrRelation *owner, SMgrRelation reln);
87 extern void smgrclearowner(SMgrRelation *owner, SMgrRelation reln);
88 extern void smgrclose(SMgrRelation reln);
89 extern void smgrcloseall(void);
90 extern void smgrclosenode(RelFileNodeBackend rnode);
91 extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
92 extern void smgrdounlink(SMgrRelation reln, bool isRedo);
93 extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);
94 extern void smgrdounlinkfork(SMgrRelation reln, ForkNumber forknum, bool isRedo);
95 extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
96  BlockNumber blocknum, char *buffer, bool skipFsync);
97 extern void smgrprefetch(SMgrRelation reln, ForkNumber forknum,
98  BlockNumber blocknum);
99 extern void smgrread(SMgrRelation reln, ForkNumber forknum,
100  BlockNumber blocknum, char *buffer);
101 extern void smgrwrite(SMgrRelation reln, ForkNumber forknum,
102  BlockNumber blocknum, char *buffer, bool skipFsync);
103 extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
104  BlockNumber blocknum, BlockNumber nblocks);
105 extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
106 extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum,
107  BlockNumber nblocks);
108 extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
109 extern void smgrpreckpt(void);
110 extern void smgrsync(void);
111 extern void smgrpostckpt(void);
112 extern void AtEOXact_SMgr(void);
113 
114 
115 /* internals: move me elsewhere -- ay 7/94 */
116 
117 /* in md.c */
118 extern void mdinit(void);
119 extern void mdclose(SMgrRelation reln, ForkNumber forknum);
120 extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
121 extern bool mdexists(SMgrRelation reln, ForkNumber forknum);
122 extern void mdunlink(RelFileNodeBackend rnode, ForkNumber forknum, bool isRedo);
123 extern void mdextend(SMgrRelation reln, ForkNumber forknum,
124  BlockNumber blocknum, char *buffer, bool skipFsync);
125 extern void mdprefetch(SMgrRelation reln, ForkNumber forknum,
126  BlockNumber blocknum);
127 extern void mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
128  char *buffer);
129 extern void mdwrite(SMgrRelation reln, ForkNumber forknum,
130  BlockNumber blocknum, char *buffer, bool skipFsync);
131 extern void mdwriteback(SMgrRelation reln, ForkNumber forknum,
132  BlockNumber blocknum, BlockNumber nblocks);
133 extern BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum);
134 extern void mdtruncate(SMgrRelation reln, ForkNumber forknum,
135  BlockNumber nblocks);
136 extern void mdimmedsync(SMgrRelation reln, ForkNumber forknum);
137 extern void mdpreckpt(void);
138 extern void mdsync(void);
139 extern void mdpostckpt(void);
140 
141 extern void SetForwardFsyncRequests(void);
142 extern void RememberFsyncRequest(RelFileNode rnode, ForkNumber forknum,
143  BlockNumber segno);
144 extern void ForgetRelationFsyncRequests(RelFileNode rnode, ForkNumber forknum);
145 extern void ForgetDatabaseFsyncRequests(Oid dbid);
146 
147 #endif /* SMGR_H */
void smgrpreckpt(void)
Definition: smgr.c:744
void ForgetDatabaseFsyncRequests(Oid dbid)
Definition: md.c:1684
void smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:660
struct SMgrRelationData SMgrRelationData
BlockNumber smgr_vm_nblocks
Definition: smgr.h:57
void smgrclosenode(RelFileNodeBackend rnode)
Definition: smgr.c:350
void smgrclearowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:222
void mdpreckpt(void)
Definition: md.c:1345
SMgrRelation smgropen(RelFileNode rnode, BackendId backend)
Definition: smgr.c:137
SMgrRelationData * SMgrRelation
Definition: smgr.h:78
void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:647
void smgrtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
Definition: smgr.c:684
void smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: smgr.c:611
void smgrclose(SMgrRelation reln)
Definition: smgr.c:296
void smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer)
Definition: smgr.c:625
void mdclose(SMgrRelation reln, ForkNumber forknum)
Definition: md.c:627
void mdinit(void)
Definition: md.c:205
uint32 BlockNumber
Definition: block.h:31
BlockNumber smgr_fsm_nblocks
Definition: smgr.h:56
void mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: md.c:658
unsigned int Oid
Definition: postgres_ext.h:31
void mdpostckpt(void)
Definition: md.c:1360
void smgrsync(void)
Definition: smgr.c:759
void smgrcloseall(void)
Definition: smgr.c:326
void mdsync(void)
Definition: md.c:1053
bool mdexists(SMgrRelation reln, ForkNumber forknum)
Definition: md.c:276
BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: md.c:872
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:287
void smgrsetowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:193
void RememberFsyncRequest(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
Definition: md.c:1513
void ForgetRelationFsyncRequests(RelFileNode rnode, ForkNumber forknum)
Definition: md.c:1651
RelFileNodeBackend smgr_rnode
Definition: smgr.h:43
void smgrinit(void)
Definition: smgr.c:102
void mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: md.c:494
void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:600
void mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: md.c:681
void SetForwardFsyncRequests(void)
Definition: md.c:253
ForkNumber
Definition: relpath.h:24
struct SMgrRelationData * next_unowned_reln
Definition: smgr.h:75
struct SMgrRelationData ** smgr_owner
Definition: smgr.h:46
int smgr_which
Definition: smgr.h:65
int BackendId
Definition: backendid.h:21
Definition: md.c:108
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:672
void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: md.c:293
void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo)
Definition: smgr.c:471
BlockNumber smgr_targblock
Definition: smgr.h:55
void mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer)
Definition: md.c:730
void smgrdounlinkfork(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:549
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:376
#define MAX_FORKNUM
Definition: relpath.h:39
void mdimmedsync(SMgrRelation reln, ForkNumber forknum)
Definition: md.c:1024
void mdtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
Definition: md.c:927
void mdunlink(RelFileNodeBackend rnode, ForkNumber forknum, bool isRedo)
Definition: md.c:386
int md_num_open_segs[MAX_FORKNUM+1]
Definition: smgr.h:71
void mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: md.c:801
void smgrdounlink(SMgrRelation reln, bool isRedo)
Definition: smgr.c:414
void AtEOXact_SMgr(void)
Definition: smgr.c:798
struct _MdfdVec * md_seg_fds[MAX_FORKNUM+1]
Definition: smgr.h:72
void smgrimmedsync(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:734
void smgrpostckpt(void)
Definition: smgr.c:774