~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/include/storage/buf_internals.h

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * buf_internals.h
 
4
 *        Internal definitions for buffer manager and the buffer replacement
 
5
 *        strategy.
 
6
 *
 
7
 *
 
8
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
9
 * Portions Copyright (c) 1994, Regents of the University of California
 
10
 *
 
11
 * $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.75.4.1 2005-02-03 23:30:12 tgl Exp $
 
12
 *
 
13
 *-------------------------------------------------------------------------
 
14
 */
 
15
#ifndef BUFMGR_INTERNALS_H
 
16
#define BUFMGR_INTERNALS_H
 
17
 
 
18
#include "storage/backendid.h"
 
19
#include "storage/buf.h"
 
20
#include "storage/lwlock.h"
 
21
#include "storage/shmem.h"
 
22
#include "utils/rel.h"
 
23
 
 
24
 
 
25
/*
 
26
 * Flags for buffer descriptors
 
27
 */
 
28
#define BM_DIRTY                                (1 << 0)                /* data needs writing */
 
29
#define BM_VALID                                (1 << 1)                /* data is valid */
 
30
#define BM_IO_IN_PROGRESS               (1 << 2)                /* read or write in
 
31
                                                                                                 * progress */
 
32
#define BM_IO_ERROR                             (1 << 3)                /* previous I/O failed */
 
33
#define BM_JUST_DIRTIED                 (1 << 4)                /* dirtied since write
 
34
                                                                                                 * started */
 
35
#define BM_PIN_COUNT_WAITER             (1 << 5)                /* have waiter for sole
 
36
                                                                                                 * pin */
 
37
 
 
38
typedef bits16 BufFlags;
 
39
 
 
40
/*
 
41
 * Buffer tag identifies which disk block the buffer contains.
 
42
 *
 
43
 * Note: the BufferTag data must be sufficient to determine where to write the
 
44
 * block, without reference to pg_class or pg_tablespace entries.  It's
 
45
 * possible that the backend flushing the buffer doesn't even believe the
 
46
 * relation is visible yet (its xact may have started before the xact that
 
47
 * created the rel).  The storage manager must be able to cope anyway.
 
48
 *
 
49
 * Note: if there's any pad bytes in the struct, INIT_BUFFERTAG will have
 
50
 * to be fixed to zero them, since this struct is used as a hash key.
 
51
 */
 
52
typedef struct buftag
 
53
{
 
54
        RelFileNode rnode;                      /* physical relation identifier */
 
55
        BlockNumber blockNum;           /* blknum relative to begin of reln */
 
56
} BufferTag;
 
57
 
 
58
#define CLEAR_BUFFERTAG(a) \
 
59
( \
 
60
        (a).rnode.spcNode = InvalidOid, \
 
61
        (a).rnode.dbNode = InvalidOid, \
 
62
        (a).rnode.relNode = InvalidOid, \
 
63
        (a).blockNum = InvalidBlockNumber \
 
64
)
 
65
 
 
66
#define INIT_BUFFERTAG(a,xx_reln,xx_blockNum) \
 
67
( \
 
68
        (a).rnode = (xx_reln)->rd_node, \
 
69
        (a).blockNum = (xx_blockNum) \
 
70
)
 
71
 
 
72
#define BUFFERTAGS_EQUAL(a,b) \
 
73
( \
 
74
        RelFileNodeEquals((a).rnode, (b).rnode) && \
 
75
        (a).blockNum == (b).blockNum \
 
76
)
 
77
 
 
78
/*
 
79
 *      BufferDesc -- shared descriptor/state data for a single shared buffer.
 
80
 */
 
81
typedef struct sbufdesc
 
82
{
 
83
        Buffer          bufNext;                /* link in freelist chain */
 
84
        SHMEM_OFFSET data;                      /* pointer to data in buf pool */
 
85
 
 
86
        /* tag and id must be together for table lookup (still true?) */
 
87
        BufferTag       tag;                    /* file/block identifier */
 
88
        int                     buf_id;                 /* buffer's index number (from 0) */
 
89
 
 
90
        BufFlags        flags;                  /* see bit definitions above */
 
91
        unsigned        refcount;               /* # of backends holding pins on buffer */
 
92
 
 
93
        LWLockId        io_in_progress_lock;    /* to wait for I/O to complete */
 
94
        LWLockId        cntx_lock;              /* to lock access to page context */
 
95
 
 
96
        bool            cntxDirty;              /* new way to mark block as dirty */
 
97
 
 
98
        /*
 
99
         * We can't physically remove items from a disk page if another
 
100
         * backend has the buffer pinned.  Hence, a backend may need to wait
 
101
         * for all other pins to go away.  This is signaled by storing its own
 
102
         * backend ID into wait_backend_id and setting flag bit
 
103
         * BM_PIN_COUNT_WAITER. At present, there can be only one such waiter
 
104
         * per buffer.
 
105
         */
 
106
        BackendId       wait_backend_id;        /* backend ID of pin-count waiter */
 
107
} BufferDesc;
 
108
 
 
109
#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
 
110
 
 
111
 
 
112
/* in bufmgr.c */
 
113
extern BufferDesc *BufferDescriptors;
 
114
 
 
115
/* in localbuf.c */
 
116
extern BufferDesc *LocalBufferDescriptors;
 
117
 
 
118
/* counters in buf_init.c */
 
119
extern long int ReadBufferCount;
 
120
extern long int ReadLocalBufferCount;
 
121
extern long int BufferHitCount;
 
122
extern long int LocalBufferHitCount;
 
123
extern long int BufferFlushCount;
 
124
extern long int LocalBufferFlushCount;
 
125
 
 
126
 
 
127
/*
 
128
 * Internal routines: only called by bufmgr
 
129
 */
 
130
 
 
131
/* freelist.c */
 
132
extern BufferDesc *StrategyBufferLookup(BufferTag *tagPtr, bool recheck,
 
133
                                         int *cdb_found_index);
 
134
extern BufferDesc *StrategyGetBuffer(int *cdb_replace_index);
 
135
extern void StrategyReplaceBuffer(BufferDesc *buf, BufferTag *newTag,
 
136
                                          int cdb_found_index, int cdb_replace_index);
 
137
extern void StrategyInvalidateBuffer(BufferDesc *buf);
 
138
extern void StrategyHintVacuum(bool vacuum_active);
 
139
extern int StrategyDirtyBufferList(BufferDesc **buffers, BufferTag *buftags,
 
140
                                                int max_buffers);
 
141
extern int      StrategyShmemSize(void);
 
142
extern void StrategyInitialize(bool init);
 
143
 
 
144
/* buf_table.c */
 
145
extern int      BufTableShmemSize(int size);
 
146
extern void InitBufTable(int size);
 
147
extern int      BufTableLookup(BufferTag *tagPtr);
 
148
extern void BufTableInsert(BufferTag *tagPtr, int buf_id);
 
149
extern void BufTableDelete(BufferTag *tagPtr);
 
150
 
 
151
/* localbuf.c */
 
152
extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum,
 
153
                                 bool *foundPtr);
 
154
extern void WriteLocalBuffer(Buffer buffer, bool release);
 
155
extern void AtEOXact_LocalBuffers(bool isCommit);
 
156
 
 
157
#endif   /* BUFMGR_INTERNALS_H */