Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef BUFMGR_INTERNALS_H
00016 #define BUFMGR_INTERNALS_H
00017
00018 #include "storage/buf.h"
00019 #include "storage/latch.h"
00020 #include "storage/lwlock.h"
00021 #include "storage/shmem.h"
00022 #include "storage/smgr.h"
00023 #include "storage/spin.h"
00024 #include "utils/relcache.h"
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define BM_DIRTY (1 << 0)
00034 #define BM_VALID (1 << 1)
00035 #define BM_TAG_VALID (1 << 2)
00036 #define BM_IO_IN_PROGRESS (1 << 3)
00037 #define BM_IO_ERROR (1 << 4)
00038 #define BM_JUST_DIRTIED (1 << 5)
00039 #define BM_PIN_COUNT_WAITER (1 << 6)
00040 #define BM_CHECKPOINT_NEEDED (1 << 7)
00041 #define BM_PERMANENT (1 << 8)
00042
00043
00044 typedef bits16 BufFlags;
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #define BM_MAX_USAGE_COUNT 5
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 typedef struct buftag
00069 {
00070 RelFileNode rnode;
00071 ForkNumber forkNum;
00072 BlockNumber blockNum;
00073 } BufferTag;
00074
00075 #define CLEAR_BUFFERTAG(a) \
00076 ( \
00077 (a).rnode.spcNode = InvalidOid, \
00078 (a).rnode.dbNode = InvalidOid, \
00079 (a).rnode.relNode = InvalidOid, \
00080 (a).forkNum = InvalidForkNumber, \
00081 (a).blockNum = InvalidBlockNumber \
00082 )
00083
00084 #define INIT_BUFFERTAG(a,xx_rnode,xx_forkNum,xx_blockNum) \
00085 ( \
00086 (a).rnode = (xx_rnode), \
00087 (a).forkNum = (xx_forkNum), \
00088 (a).blockNum = (xx_blockNum) \
00089 )
00090
00091 #define BUFFERTAGS_EQUAL(a,b) \
00092 ( \
00093 RelFileNodeEquals((a).rnode, (b).rnode) && \
00094 (a).blockNum == (b).blockNum && \
00095 (a).forkNum == (b).forkNum \
00096 )
00097
00098
00099
00100
00101
00102
00103
00104 #define BufTableHashPartition(hashcode) \
00105 ((hashcode) % NUM_BUFFER_PARTITIONS)
00106 #define BufMappingPartitionLock(hashcode) \
00107 ((LWLockId) (FirstBufMappingLock + BufTableHashPartition(hashcode)))
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 typedef struct sbufdesc
00135 {
00136 BufferTag tag;
00137 BufFlags flags;
00138 uint16 usage_count;
00139 unsigned refcount;
00140 int wait_backend_pid;
00141
00142 slock_t buf_hdr_lock;
00143
00144 int buf_id;
00145 int freeNext;
00146
00147 LWLockId io_in_progress_lock;
00148 LWLockId content_lock;
00149 } BufferDesc;
00150
00151 #define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
00152
00153
00154
00155
00156
00157 #define FREENEXT_END_OF_LIST (-1)
00158 #define FREENEXT_NOT_IN_LIST (-2)
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 #define LockBufHdr(bufHdr) SpinLockAcquire(&(bufHdr)->buf_hdr_lock)
00170 #define UnlockBufHdr(bufHdr) SpinLockRelease(&(bufHdr)->buf_hdr_lock)
00171
00172
00173
00174 extern PGDLLIMPORT BufferDesc *BufferDescriptors;
00175
00176
00177 extern BufferDesc *LocalBufferDescriptors;
00178
00179
00180
00181
00182
00183
00184
00185 extern volatile BufferDesc *StrategyGetBuffer(BufferAccessStrategy strategy,
00186 bool *lock_held);
00187 extern void StrategyFreeBuffer(volatile BufferDesc *buf);
00188 extern bool StrategyRejectBuffer(BufferAccessStrategy strategy,
00189 volatile BufferDesc *buf);
00190
00191 extern int StrategySyncStart(uint32 *complete_passes, uint32 *num_buf_alloc);
00192 extern void StrategyNotifyBgWriter(Latch *bgwriterLatch);
00193
00194 extern Size StrategyShmemSize(void);
00195 extern void StrategyInitialize(bool init);
00196
00197
00198 extern Size BufTableShmemSize(int size);
00199 extern void InitBufTable(int size);
00200 extern uint32 BufTableHashCode(BufferTag *tagPtr);
00201 extern int BufTableLookup(BufferTag *tagPtr, uint32 hashcode);
00202 extern int BufTableInsert(BufferTag *tagPtr, uint32 hashcode, int buf_id);
00203 extern void BufTableDelete(BufferTag *tagPtr, uint32 hashcode);
00204
00205
00206 extern void LocalPrefetchBuffer(SMgrRelation smgr, ForkNumber forkNum,
00207 BlockNumber blockNum);
00208 extern BufferDesc *LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum,
00209 BlockNumber blockNum, bool *foundPtr);
00210 extern void MarkLocalBufferDirty(Buffer buffer);
00211 extern void DropRelFileNodeLocalBuffers(RelFileNode rnode, ForkNumber forkNum,
00212 BlockNumber firstDelBlock);
00213 extern void DropRelFileNodeAllLocalBuffers(RelFileNode rnode);
00214 extern void AtEOXact_LocalBuffers(bool isCommit);
00215
00216 #endif