bufmgr.h 3.2 KB
Newer Older
1 2 3
/*-------------------------------------------------------------------------
 *
 * bufmgr.h--
4
 *	  POSTGRES buffer manager definitions.
5 6 7 8
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
9
 * $Id: bufmgr.h,v 1.12 1997/09/07 05:01:06 momjian Exp $
10 11 12
 *
 *-------------------------------------------------------------------------
 */
13
#ifndef BUFMGR_H
14 15
#define BUFMGR_H

16
#include <stdio.h>
17 18 19 20 21

#include <storage/ipc.h>
#include <storage/block.h>
#include <storage/buf.h>
#include <utils/rel.h>
22 23 24 25 26 27 28 29

/*
 * the maximum size of a disk block for any possible installation.
 *
 * in theory this could be anything, but in practice this is actually
 * limited to 2^13 bytes because we have limited ItemIdData.lp_off and
 * ItemIdData.lp_len to 13 bits (see itemid.h).
 */
30
#define MAXBLCKSZ		8192
31

32
typedef void   *Block;
33 34 35


/* special pageno for bget */
36
#define P_NEW	InvalidBlockNumber		/* grow the file to get a new page */
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

typedef bits16	BufferLock;

/**********************************************************************

  the rest is function defns in the bufmgr that are externally callable

 **********************************************************************/

/*
 * These routines are beaten on quite heavily, hence the macroization.
 * See buf_internals.h for a related comment.
 */
#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)

/*
 * BufferIsPinned --
54
 *		True iff the buffer is pinned (and therefore valid)
55 56
 *
 * Note:
57 58
 *		Smenatics are identical to BufferIsValid
 *		XXX - need to remove either one eventually.
59 60 61 62
 */
#define BufferIsPinned BufferIsValid


63
extern int		ShowPinTrace;
64

65 66 67
/*
 * BufferWriteModes (settable via SetBufferWriteMode)
 */
68 69
#define BUFFER_FLUSH_WRITE		0		/* immediate write */
#define BUFFER_LATE_WRITE		1		/* delayed write: mark as DIRTY */
70

71
/*
72
 * prototypes for functions in bufmgr.c
73
 */
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
extern Buffer
RelationGetBufferWithBuffer(Relation relation,
							BlockNumber blockNumber, Buffer buffer);
extern Buffer	ReadBuffer(Relation reln, BlockNumber blockNum);
extern int		WriteBuffer(Buffer buffer);
extern int		WriteNoReleaseBuffer(Buffer buffer);
extern Buffer
ReleaseAndReadBuffer(Buffer buffer, Relation relation,
					 BlockNumber blockNum);

extern void		InitBufferPool(IPCKey key);
extern void		PrintBufferUsage(FILE * statfp);
extern void		ResetBufferUsage(void);
extern void		ResetBufferPool(void);
extern int		BufferPoolCheckLeak(void);
extern void		FlushBufferPool(int StableMainMemoryFlag);
extern bool		BufferIsValid(Buffer bufnum);
91 92 93
extern BlockNumber BufferGetBlockNumber(Buffer buffer);
extern Relation BufferGetRelation(Buffer buffer);
extern BlockNumber RelationGetNumberOfBlocks(Relation relation);
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
extern Block	BufferGetBlock(Buffer buffer);
extern void		ReleaseRelationBuffers(Relation rdesc);
extern void		DropBuffers(Oid dbid);
extern void		PrintBufferDescs(void);
extern void		PrintPinnedBufs(void);
extern int		BufferShmemSize(void);
extern void		IncrBufferRefCount(Buffer buffer);
extern int		ReleaseBuffer(Buffer buffer);

extern void		BufferRefCountReset(int *refcountsave);
extern void		BufferRefCountRestore(int *refcountsave);
extern int		SetBufferWriteMode(int mode);
extern void		SetBufferCommitInfoNeedsSave(Buffer buffer);

#endif							/* !defined(BufMgrIncluded) */