1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* buf_internals.h
|
1999-11-21 20:56:12 +01:00
|
|
|
* Internal definitions for buffer manager.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2000-11-30 09:46:26 +01:00
|
|
|
* $Id: buf_internals.h,v 1.46 2000/11/30 08:46:26 vadim Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef BUFMGR_INTERNALS_H
|
1996-08-28 03:59:28 +02:00
|
|
|
#define BUFMGR_INTERNALS_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "storage/buf.h"
|
1999-07-16 19:07:40 +02:00
|
|
|
#include "storage/lmgr.h"
|
2000-11-29 00:27:57 +01:00
|
|
|
#include "storage/s_lock.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* Buf Mgr constants */
|
|
|
|
/* in bufmgr.c */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int Data_Descriptors;
|
|
|
|
extern int Free_List_Descriptor;
|
|
|
|
extern int Lookup_List_Descriptor;
|
|
|
|
extern int Num_Descriptors;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-11-30 02:39:08 +01:00
|
|
|
extern int ShowPinTrace;
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
|
|
|
* Flags for buffer descriptors
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define BM_DIRTY (1 << 0)
|
|
|
|
#define BM_PRIVATE (1 << 1)
|
|
|
|
#define BM_VALID (1 << 2)
|
|
|
|
#define BM_DELETED (1 << 3)
|
|
|
|
#define BM_FREE (1 << 4)
|
|
|
|
#define BM_IO_IN_PROGRESS (1 << 5)
|
|
|
|
#define BM_IO_ERROR (1 << 6)
|
|
|
|
#define BM_JUST_DIRTIED (1 << 7)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef bits16 BufFlags;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-11-21 20:56:12 +01:00
|
|
|
typedef struct buftag
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-10-18 07:50:16 +02:00
|
|
|
RelFileNode rnode;
|
1997-09-08 04:41:22 +02:00
|
|
|
BlockNumber blockNum; /* blknum relative to begin of reln */
|
1999-11-21 20:56:12 +01:00
|
|
|
} BufferTag;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-06-15 20:40:05 +02:00
|
|
|
#define CLEAR_BUFFERTAG(a) \
|
|
|
|
( \
|
2000-10-18 07:50:16 +02:00
|
|
|
(a)->rnode.tblNode = InvalidOid, \
|
|
|
|
(a)->rnode.relNode = InvalidOid, \
|
1998-06-15 20:40:05 +02:00
|
|
|
(a)->blockNum = InvalidBlockNumber \
|
|
|
|
)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define INIT_BUFFERTAG(a,xx_reln,xx_blockNum) \
|
1998-06-15 20:40:05 +02:00
|
|
|
( \
|
1999-09-18 21:08:25 +02:00
|
|
|
(a)->blockNum = (xx_blockNum), \
|
2000-10-18 07:50:16 +02:00
|
|
|
(a)->rnode = (xx_reln)->rd_node \
|
1998-06-15 20:40:05 +02:00
|
|
|
)
|
|
|
|
|
2000-10-18 07:50:16 +02:00
|
|
|
/*
|
2000-11-30 02:39:08 +01:00
|
|
|
* We don't need this data any more but it allows more user
|
2000-10-18 07:50:16 +02:00
|
|
|
* friendly error messages. Feel free to get rid of it
|
|
|
|
* (and change a lot of places -:))
|
2000-04-09 06:43:20 +02:00
|
|
|
*/
|
|
|
|
typedef struct bufblindid
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
char dbname[NAMEDATALEN]; /* name of db in which buf belongs */
|
|
|
|
char relname[NAMEDATALEN]; /* name of reln */
|
|
|
|
} BufferBlindId;
|
2000-04-09 06:43:20 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
1999-11-21 20:56:12 +01:00
|
|
|
* BufferDesc -- shared buffer cache metadata for a single
|
|
|
|
* shared buffer descriptor.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* We keep the name of the database and relation in which this
|
|
|
|
* buffer appears in order to avoid a catalog lookup on cache
|
|
|
|
* flush if we don't have the reldesc in the cache. It is also
|
|
|
|
* possible that the relation to which this buffer belongs is
|
|
|
|
* not visible to all backends at the time that it gets flushed.
|
|
|
|
* Dbname, relname, dbid, and relid are enough to determine where
|
|
|
|
* to put the buffer, for all storage managers.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1999-11-21 20:56:12 +01:00
|
|
|
typedef struct sbufdesc
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1999-11-21 20:56:12 +01:00
|
|
|
Buffer freeNext; /* links for freelist chain */
|
1997-09-08 04:41:22 +02:00
|
|
|
Buffer freePrev;
|
|
|
|
SHMEM_OFFSET data; /* pointer to data in buf pool */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* tag and id must be together for table lookup to work */
|
1997-09-08 04:41:22 +02:00
|
|
|
BufferTag tag; /* file/block identifier */
|
|
|
|
int buf_id; /* maps global desc to local desc */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-11-21 20:56:12 +01:00
|
|
|
BufFlags flags; /* see bit definitions above */
|
1997-09-08 04:41:22 +02:00
|
|
|
unsigned refcount; /* # of times buffer is pinned */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-11-29 00:27:57 +01:00
|
|
|
slock_t io_in_progress_lock; /* to block for I/O to complete */
|
1998-12-15 13:47:01 +01:00
|
|
|
slock_t cntx_lock; /* to lock access to page context */
|
2000-11-29 00:27:57 +01:00
|
|
|
|
1998-12-15 13:47:01 +01:00
|
|
|
unsigned r_locks; /* # of shared locks */
|
|
|
|
bool ri_lock; /* read-intent lock */
|
|
|
|
bool w_lock; /* context exclusively locked */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
bool cntxDirty; /* new way to mark block as dirty */
|
|
|
|
|
2000-10-18 07:50:16 +02:00
|
|
|
BufferBlindId blind; /* was used to support blind write */
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When we can't delete item from page (someone else has buffer pinned)
|
|
|
|
* we mark buffer for cleanup by specifying appropriate for buffer
|
|
|
|
* content cleanup function. Buffer will be cleaned up from release
|
|
|
|
* buffer functions.
|
|
|
|
*/
|
|
|
|
void (*CleanupFunc)(Buffer);
|
1999-11-21 20:56:12 +01:00
|
|
|
} BufferDesc;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-11-30 02:39:08 +01:00
|
|
|
#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
|
|
|
|
|
1998-12-15 13:47:01 +01:00
|
|
|
/*
|
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.
|
|
|
|
*
|
1998-12-15 13:47:01 +01:00
|
|
|
* We have to free these locks in elog(ERROR)...
|
|
|
|
*/
|
1999-05-25 18:15:34 +02:00
|
|
|
#define BL_IO_IN_PROGRESS (1 << 0) /* unimplemented */
|
|
|
|
#define BL_R_LOCK (1 << 1)
|
|
|
|
#define BL_RI_LOCK (1 << 2)
|
|
|
|
#define BL_W_LOCK (1 << 3)
|
1998-12-15 13:47:01 +01:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* mao tracing buffer allocation
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*#define BMTRACE*/
|
|
|
|
#ifdef BMTRACE
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct _bmtrace
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int bmt_pid;
|
|
|
|
long bmt_buf;
|
|
|
|
long bmt_dbid;
|
|
|
|
long bmt_relid;
|
|
|
|
int bmt_blkno;
|
|
|
|
int bmt_op;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define BMT_NOTUSED 0
|
1996-08-28 03:59:28 +02:00
|
|
|
#define BMT_ALLOCFND 1
|
1997-09-07 07:04:48 +02:00
|
|
|
#define BMT_ALLOCNOTFND 2
|
|
|
|
#define BMT_DEALLOC 3
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
} bmtrace;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* BMTRACE */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1996-08-28 03:59:28 +02:00
|
|
|
* Bufmgr Interface:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Internal routines: only called by buf.c */
|
|
|
|
|
|
|
|
/*freelist.c*/
|
1997-09-08 22:59:27 +02:00
|
|
|
extern void AddBufferToFreelist(BufferDesc *bf);
|
|
|
|
extern void PinBuffer(BufferDesc *buf);
|
|
|
|
extern void PinBuffer_Debug(char *file, int line, BufferDesc *buf);
|
|
|
|
extern void UnpinBuffer(BufferDesc *buf);
|
1996-08-28 03:59:28 +02:00
|
|
|
extern BufferDesc *GetFreeBuffer(void);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void InitFreeList(bool init);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* buf_table.c */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void InitBufTable(void);
|
1997-09-08 23:56:23 +02:00
|
|
|
extern BufferDesc *BufTableLookup(BufferTag *tagPtr);
|
1997-09-08 22:59:27 +02:00
|
|
|
extern bool BufTableDelete(BufferDesc *buf);
|
|
|
|
extern bool BufTableInsert(BufferDesc *buf);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* bufmgr.c */
|
1997-09-07 07:04:48 +02:00
|
|
|
extern BufferDesc *BufferDescriptors;
|
1998-12-15 13:47:01 +01:00
|
|
|
extern bits8 *BufferLocks;
|
2000-04-09 06:43:20 +02:00
|
|
|
extern BufferTag *BufferTagLastDirtied;
|
|
|
|
extern BufferBlindId *BufferBlindLastDirtied;
|
2000-10-18 07:50:16 +02:00
|
|
|
extern LockRelId *BufferRelidLastDirtied;
|
2000-04-09 06:43:20 +02:00
|
|
|
extern bool *BufferDirtiedByMe;
|
1997-09-07 07:04:48 +02:00
|
|
|
extern SPINLOCK BufMgrLock;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* localbuf.c */
|
|
|
|
extern BufferDesc *LocalBufferDescriptors;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum,
|
2000-04-12 19:17:23 +02:00
|
|
|
bool *foundPtr);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int WriteLocalBuffer(Buffer buffer, bool release);
|
2000-11-08 23:10:03 +01:00
|
|
|
extern int FlushLocalBuffer(Buffer buffer, bool sync, bool release);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void LocalBufferSync(void);
|
|
|
|
extern void ResetLocalBufferPool(void);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* BUFMGR_INTERNALS_H */
|