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 */ |
45 | struct SMgrRelationData **smgr_owner; |
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 | */ |
70 | int md_num_open_segs[MAX_FORKNUM + 1]; |
71 | struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1]; |
72 | |
73 | /* if unowned, list link in list of all unowned SMgrRelations */ |
74 | dlist_node node; |
75 | } SMgrRelationData; |
76 | |
77 | typedef SMgrRelationData *SMgrRelation; |
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 smgrdounlinkfork(SMgrRelation reln, ForkNumber forknum, bool isRedo); |
94 | extern void smgrextend(SMgrRelation reln, ForkNumber forknum, |
95 | BlockNumber blocknum, char *buffer, bool skipFsync); |
96 | extern void smgrprefetch(SMgrRelation reln, ForkNumber forknum, |
97 | BlockNumber blocknum); |
98 | extern void smgrread(SMgrRelation reln, ForkNumber forknum, |
99 | BlockNumber blocknum, char *buffer); |
100 | extern void smgrwrite(SMgrRelation reln, ForkNumber forknum, |
101 | BlockNumber blocknum, char *buffer, bool skipFsync); |
102 | extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum, |
103 | BlockNumber blocknum, BlockNumber nblocks); |
104 | extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum); |
105 | extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum, |
106 | BlockNumber nblocks); |
107 | extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum); |
108 | extern void AtEOXact_SMgr(void); |
109 | |
110 | #endif /* SMGR_H */ |
111 | |