Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef BUFMGR_H
00015 #define BUFMGR_H
00016
00017 #include "storage/block.h"
00018 #include "storage/buf.h"
00019 #include "storage/bufpage.h"
00020 #include "storage/relfilenode.h"
00021 #include "utils/relcache.h"
00022
00023 typedef void *Block;
00024
00025
00026 typedef enum BufferAccessStrategyType
00027 {
00028 BAS_NORMAL,
00029 BAS_BULKREAD,
00030
00031 BAS_BULKWRITE,
00032 BAS_VACUUM
00033 } BufferAccessStrategyType;
00034
00035
00036 typedef enum
00037 {
00038 RBM_NORMAL,
00039 RBM_ZERO,
00040
00041 RBM_ZERO_ON_ERROR
00042 } ReadBufferMode;
00043
00044
00045 extern PGDLLIMPORT int NBuffers;
00046
00047
00048 extern bool zero_damaged_pages;
00049 extern int bgwriter_lru_maxpages;
00050 extern double bgwriter_lru_multiplier;
00051 extern bool track_io_timing;
00052 extern int target_prefetch_pages;
00053
00054
00055 extern PGDLLIMPORT char *BufferBlocks;
00056 extern PGDLLIMPORT int32 *PrivateRefCount;
00057
00058
00059 extern PGDLLIMPORT int NLocBuffer;
00060 extern PGDLLIMPORT Block *LocalBufferBlockPointers;
00061 extern PGDLLIMPORT int32 *LocalRefCount;
00062
00063
00064 #define P_NEW InvalidBlockNumber
00065
00066
00067
00068
00069 #define BUFFER_LOCK_UNLOCK 0
00070 #define BUFFER_LOCK_SHARE 1
00071 #define BUFFER_LOCK_EXCLUSIVE 2
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 #define BufferIsValid(bufnum) \
00097 ( \
00098 AssertMacro((bufnum) <= NBuffers && (bufnum) >= -NLocBuffer), \
00099 (bufnum) != InvalidBuffer \
00100 )
00101
00102
00103
00104
00105
00106
00107
00108
00109 #define BufferIsPinned(bufnum) \
00110 ( \
00111 !BufferIsValid(bufnum) ? \
00112 false \
00113 : \
00114 BufferIsLocal(bufnum) ? \
00115 (LocalRefCount[-(bufnum) - 1] > 0) \
00116 : \
00117 (PrivateRefCount[(bufnum) - 1] > 0) \
00118 )
00119
00120
00121
00122
00123
00124
00125
00126
00127 #define BufferGetBlock(buffer) \
00128 ( \
00129 AssertMacro(BufferIsValid(buffer)), \
00130 BufferIsLocal(buffer) ? \
00131 LocalBufferBlockPointers[-(buffer) - 1] \
00132 : \
00133 (Block) (BufferBlocks + ((Size) ((buffer) - 1)) * BLCKSZ) \
00134 )
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 #define BufferGetPageSize(buffer) \
00148 ( \
00149 AssertMacro(BufferIsValid(buffer)), \
00150 (Size)BLCKSZ \
00151 )
00152
00153
00154
00155
00156
00157 #define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer))
00158
00159
00160
00161
00162 extern void PrefetchBuffer(Relation reln, ForkNumber forkNum,
00163 BlockNumber blockNum);
00164 extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum);
00165 extern Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum,
00166 BlockNumber blockNum, ReadBufferMode mode,
00167 BufferAccessStrategy strategy);
00168 extern Buffer ReadBufferWithoutRelcache(RelFileNode rnode,
00169 ForkNumber forkNum, BlockNumber blockNum,
00170 ReadBufferMode mode, BufferAccessStrategy strategy);
00171 extern void ReleaseBuffer(Buffer buffer);
00172 extern void UnlockReleaseBuffer(Buffer buffer);
00173 extern void MarkBufferDirty(Buffer buffer);
00174 extern void IncrBufferRefCount(Buffer buffer);
00175 extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation,
00176 BlockNumber blockNum);
00177
00178 extern void InitBufferPool(void);
00179 extern void InitBufferPoolAccess(void);
00180 extern void InitBufferPoolBackend(void);
00181 extern void AtEOXact_Buffers(bool isCommit);
00182 extern void PrintBufferLeakWarning(Buffer buffer);
00183 extern void CheckPointBuffers(int flags);
00184 extern BlockNumber BufferGetBlockNumber(Buffer buffer);
00185 extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation,
00186 ForkNumber forkNum);
00187 extern void FlushRelationBuffers(Relation rel);
00188 extern void FlushDatabaseBuffers(Oid dbid);
00189 extern void DropRelFileNodeBuffers(RelFileNodeBackend rnode,
00190 ForkNumber forkNum, BlockNumber firstDelBlock);
00191 extern void DropRelFileNodesAllBuffers(RelFileNodeBackend *rnodes, int nnodes);
00192 extern void DropDatabaseBuffers(Oid dbid);
00193
00194 #define RelationGetNumberOfBlocks(reln) \
00195 RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM)
00196
00197 extern bool BufferIsPermanent(Buffer buffer);
00198 extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer);
00199
00200 #ifdef NOT_USED
00201 extern void PrintPinnedBufs(void);
00202 #endif
00203 extern Size BufferShmemSize(void);
00204 extern void BufferGetTag(Buffer buffer, RelFileNode *rnode,
00205 ForkNumber *forknum, BlockNumber *blknum);
00206
00207 extern void MarkBufferDirtyHint(Buffer buffer);
00208
00209 extern void UnlockBuffers(void);
00210 extern void LockBuffer(Buffer buffer, int mode);
00211 extern bool ConditionalLockBuffer(Buffer buffer);
00212 extern void LockBufferForCleanup(Buffer buffer);
00213 extern bool ConditionalLockBufferForCleanup(Buffer buffer);
00214 extern bool HoldingBufferPinThatDelaysRecovery(void);
00215
00216 extern void AbortBufferIO(void);
00217
00218 extern void BufmgrCommit(void);
00219 extern bool BgBufferSync(void);
00220
00221 extern void AtProcExit_LocalBuffers(void);
00222
00223
00224 extern BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype);
00225 extern void FreeAccessStrategy(BufferAccessStrategy strategy);
00226
00227 #endif