PostgreSQL Source Code  git master
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-2020, 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 "lib/ilist.h"
18 #include "storage/block.h"
19 #include "storage/relfilenode.h"
20 
21 /*
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
27  * descriptors.)
28  *
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
34  * all we need.
35  *
36  * SMgrRelations that do not have an "owner" are considered to be transient,
37  * and are deleted at end of transaction.
38  */
39 typedef struct SMgrRelationData
40 {
41  /* rnode is the hashtable lookup key, so it must be first! */
42  RelFileNodeBackend smgr_rnode; /* relation physical identifier */
43 
44  /* pointer to owning pointer, or NULL if none */
46 
47  /*
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.
52  */
53  BlockNumber smgr_targblock; /* current insertion target block */
54  BlockNumber smgr_cached_nblocks[MAX_FORKNUM + 1]; /* last known size */
55 
56  /* additional public fields may someday exist here */
57 
58  /*
59  * Fields below here are intended to be private to smgr.c and its
60  * submodules. Do not touch them from elsewhere.
61  */
62  int smgr_which; /* storage manager selector */
63 
64  /*
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).
67  */
70 
71  /* if unowned, list link in list of all unowned SMgrRelations */
74 
76 
77 #define SmgrIsTemp(smgr) \
78  RelFileNodeBackendIsTemp((smgr)->smgr_rnode)
79 
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 void smgrtruncate(SMgrRelation reln, ForkNumber *forknum,
103  int nforks, BlockNumber *nblocks);
104 extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
105 extern void AtEOXact_SMgr(void);
106 
107 #endif /* SMGR_H */
void smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:537
struct SMgrRelationData SMgrRelationData
void smgrclosenode(RelFileNodeBackend rnode)
Definition: smgr.c:311
void smgrclearowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:228
SMgrRelation smgropen(RelFileNode rnode, BackendId backend)
Definition: smgr.c:146
SMgrRelationData * SMgrRelation
Definition: smgr.h:75
void smgrdosyncall(SMgrRelation *rels, int nrels)
Definition: smgr.c:349
void smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber *nblocks)
Definition: smgr.c:578
void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:524
void smgrclose(SMgrRelation reln)
Definition: smgr.c:257
void smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer)
Definition: smgr.c:502
uint32 BlockNumber
Definition: block.h:31
bool smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: smgr.c:488
void smgrcloseall(void)
Definition: smgr.c:287
BlockNumber smgr_cached_nblocks[MAX_FORKNUM+1]
Definition: smgr.h:54
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:248
void smgrsetowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:199
RelFileNodeBackend smgr_rnode
Definition: smgr.h:42
void smgrinit(void)
Definition: smgr.c:111
void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:463
ForkNumber
Definition: relpath.h:40
struct SMgrRelationData ** smgr_owner
Definition: smgr.h:45
int smgr_which
Definition: smgr.h:62
int BackendId
Definition: backendid.h:21
Definition: md.c:82
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:549
void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo)
Definition: smgr.c:385
BlockNumber smgr_targblock
Definition: smgr.h:53
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:334
#define MAX_FORKNUM
Definition: relpath.h:55
int md_num_open_segs[MAX_FORKNUM+1]
Definition: smgr.h:68
void AtEOXact_SMgr(void)
Definition: smgr.c:661
struct _MdfdVec * md_seg_fds[MAX_FORKNUM+1]
Definition: smgr.h:69
void smgrimmedsync(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:643
dlist_node node
Definition: smgr.h:72