postgresql/src/include/storage/buf_internals.h

183 lines
5.2 KiB
C
Raw Normal View History

/*-------------------------------------------------------------------------
*
* buf_internals.h
1999-11-21 20:56:12 +01:00
* Internal definitions for buffer manager.
*
*
2003-08-04 04:40:20 +02:00
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.66 2003/12/14 00:34:47 neilc Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef BUFMGR_INTERNALS_H
#define BUFMGR_INTERNALS_H
#include "storage/backendid.h"
#include "storage/buf.h"
1999-07-16 19:07:40 +02:00
#include "storage/lmgr.h"
#include "storage/lwlock.h"
/* Buf Mgr constants */
/* in bufmgr.c */
extern int Data_Descriptors;
extern int Free_List_Descriptor;
extern int Lookup_List_Descriptor;
extern int Num_Descriptors;
extern int ShowPinTrace;
/*
* Flags for buffer descriptors
*/
#define BM_DIRTY (1 << 0)
#define BM_VALID (1 << 1)
#define BM_DELETED (1 << 2)
#define BM_FREE (1 << 3)
#define BM_IO_IN_PROGRESS (1 << 4)
#define BM_IO_ERROR (1 << 5)
#define BM_JUST_DIRTIED (1 << 6)
#define BM_PIN_COUNT_WAITER (1 << 7)
typedef bits16 BufFlags;
/*
* Buffer tag identifies which disk block the buffer contains.
*
* Note: the BufferTag data must be sufficient to determine where to write the
* block, even during a "blind write" with no relcache entry. It's possible
* that the backend flushing the buffer doesn't even believe the relation is
* visible yet (its xact may have started before the xact that created the
* rel). The storage manager must be able to cope anyway.
*/
1999-11-21 20:56:12 +01:00
typedef struct buftag
{
2001-03-22 05:01:46 +01:00
RelFileNode rnode;
BlockNumber blockNum; /* blknum relative to begin of reln */
1999-11-21 20:56:12 +01:00
} BufferTag;
#define CLEAR_BUFFERTAG(a) \
( \
(a)->rnode.tblNode = InvalidOid, \
(a)->rnode.relNode = InvalidOid, \
(a)->blockNum = InvalidBlockNumber \
)
#define INIT_BUFFERTAG(a,xx_reln,xx_blockNum) \
( \
(a)->blockNum = (xx_blockNum), \
(a)->rnode = (xx_reln)->rd_node \
)
#define BUFFERTAG_EQUALS(a,xx_reln,xx_blockNum) \
( \
(a)->rnode.tblNode == (xx_reln)->rd_node.tblNode && \
(a)->rnode.relNode == (xx_reln)->rd_node.relNode && \
(a)->blockNum == (xx_blockNum) \
)
#define BUFFERTAGS_EQUAL(a,b) \
( \
(a)->rnode.tblNode == (b)->rnode.tblNode && \
(a)->rnode.relNode == (b)->rnode.relNode && \
(a)->blockNum == (b)->blockNum \
)
/*
1999-11-21 20:56:12 +01:00
* BufferDesc -- shared buffer cache metadata for a single
* shared buffer descriptor.
*/
1999-11-21 20:56:12 +01:00
typedef struct sbufdesc
{
Buffer bufNext; /* link in freelist chain */
SHMEM_OFFSET data; /* pointer to data in buf pool */
/* tag and id must be together for table lookup */
BufferTag tag; /* file/block identifier */
int buf_id; /* buffer's index number (from 0) */
1999-11-21 20:56:12 +01:00
BufFlags flags; /* see bit definitions above */
unsigned refcount; /* # of backends holding pins on buffer */
LWLockId io_in_progress_lock; /* to wait for I/O to complete */
LWLockId cntx_lock; /* to lock access to page context */
2000-10-28 18:21:00 +02:00
bool cntxDirty; /* new way to mark block as dirty */
/*
* We can't physically remove items from a disk page if another
* backend has the buffer pinned. Hence, a backend may need to wait
* for all other pins to go away. This is signaled by setting its own
* backend ID into wait_backend_id and setting flag bit
* BM_PIN_COUNT_WAITER. At present, there can be only one such waiter
* per buffer.
*/
BackendId wait_backend_id; /* backend ID of pin-count waiter */
1999-11-21 20:56:12 +01:00
} BufferDesc;
#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
/*
1999-11-21 20:56:12 +01:00
* Each backend has its own BufferLocks[] array holding flag bits
* showing what locks it has set on each buffer.
*
2003-07-27 19:10:07 +02:00
* We have to free these locks during ereport(ERROR)...
*/
1999-05-25 18:15:34 +02:00
#define BL_IO_IN_PROGRESS (1 << 0) /* unimplemented */
#define BL_PIN_COUNT_LOCK (1 << 1)
/* entry for buffer hashtable */
typedef struct
{
BufferTag key;
Buffer id;
} BufferLookupEnt;
/* counters in buf_init.c */
2002-09-04 22:31:48 +02:00
extern long int ReadBufferCount;
extern long int ReadLocalBufferCount;
extern long int BufferHitCount;
extern long int LocalBufferHitCount;
extern long int BufferFlushCount;
extern long int LocalBufferFlushCount;
/*
* Bufmgr Interface:
*/
/* Internal routines: only called by buf.c */
/*freelist.c*/
1997-09-08 22:59:27 +02:00
extern void PinBuffer(BufferDesc *buf);
extern void UnpinBuffer(BufferDesc *buf);
extern BufferDesc *StrategyBufferLookup(BufferTag *tagPtr, bool recheck);
extern BufferDesc *StrategyGetBuffer(void);
extern void StrategyReplaceBuffer(BufferDesc *buf, Relation rnode, BlockNumber blockNum);
extern void StrategyInvalidateBuffer(BufferDesc *buf);
extern void StrategyHintVacuum(bool vacuum_active);
extern int StrategyDirtyBufferList(int *buffer_dirty, int max_buffers);
extern void StrategyInitialize(bool init);
/* buf_table.c */
extern void InitBufTable(int size);
extern int BufTableLookup(BufferTag *tagPtr);
extern bool BufTableInsert(BufferTag *tagPtr, Buffer buf_id);
extern bool BufTableDelete(BufferTag *tagPtr);
/* bufmgr.c */
extern BufferDesc *BufferDescriptors;
extern bits8 *BufferLocks;
/* localbuf.c */
extern BufferDesc *LocalBufferDescriptors;
extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum,
bool *foundPtr);
2002-09-04 22:31:48 +02:00
extern void WriteLocalBuffer(Buffer buffer, bool release);
extern void AtEOXact_LocalBuffers(bool isCommit);
#endif /* BUFMGR_INTERNALS_H */