Header And Logo

PostgreSQL
| The world's most advanced open source database.

smgr.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * smgr.h
00004  *    storage manager switch public interface declarations.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/storage/smgr.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef SMGR_H
00015 #define SMGR_H
00016 
00017 #include "fmgr.h"
00018 #include "storage/block.h"
00019 #include "storage/relfilenode.h"
00020 
00021 
00022 /*
00023  * smgr.c maintains a table of SMgrRelation objects, which are essentially
00024  * cached file handles.  An SMgrRelation is created (if not already present)
00025  * by smgropen(), and destroyed by smgrclose().  Note that neither of these
00026  * operations imply I/O, they just create or destroy a hashtable entry.
00027  * (But smgrclose() may release associated resources, such as OS-level file
00028  * descriptors.)
00029  *
00030  * An SMgrRelation may have an "owner", which is just a pointer to it from
00031  * somewhere else; smgr.c will clear this pointer if the SMgrRelation is
00032  * closed.  We use this to avoid dangling pointers from relcache to smgr
00033  * without having to make the smgr explicitly aware of relcache.  There
00034  * can't be more than one "owner" pointer per SMgrRelation, but that's
00035  * all we need.
00036  *
00037  * SMgrRelations that do not have an "owner" are considered to be transient,
00038  * and are deleted at end of transaction.
00039  */
00040 typedef struct SMgrRelationData
00041 {
00042     /* rnode is the hashtable lookup key, so it must be first! */
00043     RelFileNodeBackend smgr_rnode;      /* relation physical identifier */
00044 
00045     /* pointer to owning pointer, or NULL if none */
00046     struct SMgrRelationData **smgr_owner;
00047 
00048     /*
00049      * These next three fields are not actually used or manipulated by smgr,
00050      * except that they are reset to InvalidBlockNumber upon a cache flush
00051      * event (in particular, upon truncation of the relation).  Higher levels
00052      * store cached state here so that it will be reset when truncation
00053      * happens.  In all three cases, InvalidBlockNumber means "unknown".
00054      */
00055     BlockNumber smgr_targblock; /* current insertion target block */
00056     BlockNumber smgr_fsm_nblocks;       /* last known size of fsm fork */
00057     BlockNumber smgr_vm_nblocks;    /* last known size of vm fork */
00058 
00059     /* additional public fields may someday exist here */
00060 
00061     /*
00062      * Fields below here are intended to be private to smgr.c and its
00063      * submodules.  Do not touch them from elsewhere.
00064      */
00065     int         smgr_which;     /* storage manager selector */
00066 
00067     /* for md.c; NULL for forks that are not open */
00068     struct _MdfdVec *md_fd[MAX_FORKNUM + 1];
00069 
00070     /* if unowned, list link in list of all unowned SMgrRelations */
00071     struct SMgrRelationData *next_unowned_reln;
00072 } SMgrRelationData;
00073 
00074 typedef SMgrRelationData *SMgrRelation;
00075 
00076 #define SmgrIsTemp(smgr) \
00077     RelFileNodeBackendIsTemp((smgr)->smgr_rnode)
00078 
00079 extern void smgrinit(void);
00080 extern SMgrRelation smgropen(RelFileNode rnode, BackendId backend);
00081 extern bool smgrexists(SMgrRelation reln, ForkNumber forknum);
00082 extern void smgrsetowner(SMgrRelation *owner, SMgrRelation reln);
00083 extern void smgrclose(SMgrRelation reln);
00084 extern void smgrcloseall(void);
00085 extern void smgrclosenode(RelFileNodeBackend rnode);
00086 extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
00087 extern void smgrdounlink(SMgrRelation reln, bool isRedo);
00088 extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);
00089 extern void smgrdounlinkfork(SMgrRelation reln, ForkNumber forknum, bool isRedo);
00090 extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
00091            BlockNumber blocknum, char *buffer, bool skipFsync);
00092 extern void smgrprefetch(SMgrRelation reln, ForkNumber forknum,
00093              BlockNumber blocknum);
00094 extern void smgrread(SMgrRelation reln, ForkNumber forknum,
00095          BlockNumber blocknum, char *buffer);
00096 extern void smgrwrite(SMgrRelation reln, ForkNumber forknum,
00097           BlockNumber blocknum, char *buffer, bool skipFsync);
00098 extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
00099 extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum,
00100              BlockNumber nblocks);
00101 extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
00102 extern void smgrpreckpt(void);
00103 extern void smgrsync(void);
00104 extern void smgrpostckpt(void);
00105 extern void AtEOXact_SMgr(void);
00106 
00107 
00108 /* internals: move me elsewhere -- ay 7/94 */
00109 
00110 /* in md.c */
00111 extern void mdinit(void);
00112 extern void mdclose(SMgrRelation reln, ForkNumber forknum);
00113 extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
00114 extern bool mdexists(SMgrRelation reln, ForkNumber forknum);
00115 extern void mdunlink(RelFileNodeBackend rnode, ForkNumber forknum, bool isRedo);
00116 extern void mdextend(SMgrRelation reln, ForkNumber forknum,
00117          BlockNumber blocknum, char *buffer, bool skipFsync);
00118 extern void mdprefetch(SMgrRelation reln, ForkNumber forknum,
00119            BlockNumber blocknum);
00120 extern void mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
00121        char *buffer);
00122 extern void mdwrite(SMgrRelation reln, ForkNumber forknum,
00123         BlockNumber blocknum, char *buffer, bool skipFsync);
00124 extern BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum);
00125 extern void mdtruncate(SMgrRelation reln, ForkNumber forknum,
00126            BlockNumber nblocks);
00127 extern void mdimmedsync(SMgrRelation reln, ForkNumber forknum);
00128 extern void mdpreckpt(void);
00129 extern void mdsync(void);
00130 extern void mdpostckpt(void);
00131 
00132 extern void SetForwardFsyncRequests(void);
00133 extern void RememberFsyncRequest(RelFileNode rnode, ForkNumber forknum,
00134                      BlockNumber segno);
00135 extern void ForgetRelationFsyncRequests(RelFileNode rnode, ForkNumber forknum);
00136 extern void ForgetDatabaseFsyncRequests(Oid dbid);
00137 
00138 /* smgrtype.c */
00139 extern Datum smgrout(PG_FUNCTION_ARGS);
00140 extern Datum smgrin(PG_FUNCTION_ARGS);
00141 extern Datum smgreq(PG_FUNCTION_ARGS);
00142 extern Datum smgrne(PG_FUNCTION_ARGS);
00143 
00144 #endif   /* SMGR_H */