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-2019, 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  * These next three fields are not actually used or manipulated by smgr,
49  * except that they are reset to InvalidBlockNumber upon a cache flush
50  * event (in particular, upon truncation of the relation). Higher levels
51  * store cached state here so that it will be reset when truncation
52  * happens. In all three cases, InvalidBlockNumber means "unknown".
53  */
54  BlockNumber smgr_targblock; /* current insertion target block */
55  BlockNumber smgr_fsm_nblocks; /* last known size of fsm fork */
56  BlockNumber smgr_vm_nblocks; /* last known size of vm fork */
57 
58  /* additional public fields may someday exist here */
59 
60  /*
61  * Fields below here are intended to be private to smgr.c and its
62  * submodules. Do not touch them from elsewhere.
63  */
64  int smgr_which; /* storage manager selector */
65 
66  /*
67  * for md.c; per-fork arrays of the number of open segments
68  * (md_num_open_segs) and the segments themselves (md_seg_fds).
69  */
72 
73  /* if unowned, list link in list of all unowned SMgrRelations */
76 
78 
79 #define SmgrIsTemp(smgr) \
80  RelFileNodeBackendIsTemp((smgr)->smgr_rnode)
81 
82 extern void smgrinit(void);
83 extern SMgrRelation smgropen(RelFileNode rnode, BackendId backend);
84 extern bool smgrexists(SMgrRelation reln, ForkNumber forknum);
85 extern void smgrsetowner(SMgrRelation *owner, SMgrRelation reln);
86 extern void smgrclearowner(SMgrRelation *owner, SMgrRelation reln);
87 extern void smgrclose(SMgrRelation reln);
88 extern void smgrcloseall(void);
89 extern void smgrclosenode(RelFileNodeBackend rnode);
90 extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
91 extern void smgrdounlink(SMgrRelation reln, bool isRedo);
92 extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);
93 extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
94  BlockNumber blocknum, char *buffer, bool skipFsync);
95 extern void smgrprefetch(SMgrRelation reln, ForkNumber forknum,
96  BlockNumber blocknum);
97 extern void smgrread(SMgrRelation reln, ForkNumber forknum,
98  BlockNumber blocknum, char *buffer);
99 extern void smgrwrite(SMgrRelation reln, ForkNumber forknum,
100  BlockNumber blocknum, char *buffer, bool skipFsync);
101 extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
102  BlockNumber blocknum, BlockNumber nblocks);
103 extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
104 extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum,
105  BlockNumber nblocks);
106 extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
107 extern void AtEOXact_SMgr(void);
108 
109 #endif /* SMGR_H */
void smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:542
struct SMgrRelationData SMgrRelationData
BlockNumber smgr_vm_nblocks
Definition: smgr.h:56
void smgrclosenode(RelFileNodeBackend rnode)
Definition: smgr.c:310
void smgrclearowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:227
SMgrRelation smgropen(RelFileNode rnode, BackendId backend)
Definition: smgr.c:145
SMgrRelationData * SMgrRelation
Definition: smgr.h:77
void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:529
void smgrtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
Definition: smgr.c:566
void smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: smgr.c:493
void smgrclose(SMgrRelation reln)
Definition: smgr.c:256
void smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer)
Definition: smgr.c:507
uint32 BlockNumber
Definition: block.h:31
BlockNumber smgr_fsm_nblocks
Definition: smgr.h:55
void smgrcloseall(void)
Definition: smgr.c:286
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:247
void smgrsetowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:198
RelFileNodeBackend smgr_rnode
Definition: smgr.h:42
void smgrinit(void)
Definition: smgr.c:110
void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:482
ForkNumber
Definition: relpath.h:40
struct SMgrRelationData ** smgr_owner
Definition: smgr.h:45
int smgr_which
Definition: smgr.h:64
int BackendId
Definition: backendid.h:21
Definition: md.c:82
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:554
void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo)
Definition: smgr.c:405
BlockNumber smgr_targblock
Definition: smgr.h:54
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:333
#define MAX_FORKNUM
Definition: relpath.h:55
int md_num_open_segs[MAX_FORKNUM+1]
Definition: smgr.h:70
void smgrdounlink(SMgrRelation reln, bool isRedo)
Definition: smgr.c:348
void AtEOXact_SMgr(void)
Definition: smgr.c:634
struct _MdfdVec * md_seg_fds[MAX_FORKNUM+1]
Definition: smgr.h:71
void smgrimmedsync(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:616
dlist_node node
Definition: smgr.h:74