~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * proc.h
 
4
 *        per-process shared memory data structures
 
5
 *
 
6
 *
 
7
 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
 
8
 * Portions Copyright (c) 1994, Regents of the University of California
 
9
 *
 
10
 * src/include/storage/proc.h
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
#ifndef _PROC_H_
 
15
#define _PROC_H_
 
16
 
 
17
#include "access/xlog.h"
 
18
#include "replication/syncrep.h"
 
19
#include "storage/latch.h"
 
20
#include "storage/lock.h"
 
21
#include "storage/pg_sema.h"
 
22
#include "utils/timestamp.h"
 
23
 
 
24
/*
 
25
 * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
 
26
 * for non-aborted subtransactions of its current top transaction.      These
 
27
 * have to be treated as running XIDs by other backends.
 
28
 *
 
29
 * We also keep track of whether the cache overflowed (ie, the transaction has
 
30
 * generated at least one subtransaction that didn't fit in the cache).
 
31
 * If none of the caches have overflowed, we can assume that an XID that's not
 
32
 * listed anywhere in the PGPROC array is not a running transaction.  Else we
 
33
 * have to look at pg_subtrans.
 
34
 */
 
35
#define PGPROC_MAX_CACHED_SUBXIDS 64    /* XXX guessed-at value */
 
36
 
 
37
struct XidCache
 
38
{
 
39
        bool            overflowed;
 
40
        int                     nxids;
 
41
        TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS];
 
42
};
 
43
 
 
44
/* Flags for PGPROC->vacuumFlags */
 
45
#define         PROC_IS_AUTOVACUUM      0x01    /* is it an autovac worker? */
 
46
#define         PROC_IN_VACUUM          0x02    /* currently running lazy vacuum */
 
47
#define         PROC_IN_ANALYZE         0x04    /* currently running analyze */
 
48
#define         PROC_VACUUM_FOR_WRAPAROUND 0x08         /* set by autovac only */
 
49
 
 
50
/* flags reset at EOXact */
 
51
#define         PROC_VACUUM_STATE_MASK (0x0E)
 
52
 
 
53
/*
 
54
 * Each backend has a PGPROC struct in shared memory.  There is also a list of
 
55
 * currently-unused PGPROC structs that will be reallocated to new backends.
 
56
 *
 
57
 * links: list link for any list the PGPROC is in.      When waiting for a lock,
 
58
 * the PGPROC is linked into that lock's waitProcs queue.  A recycled PGPROC
 
59
 * is linked into ProcGlobal's freeProcs list.
 
60
 *
 
61
 * Note: twophase.c also sets up a dummy PGPROC struct for each currently
 
62
 * prepared transaction.  These PGPROCs appear in the ProcArray data structure
 
63
 * so that the prepared transactions appear to be still running and are
 
64
 * correctly shown as holding locks.  A prepared transaction PGPROC can be
 
65
 * distinguished from a real one at need by the fact that it has pid == 0.
 
66
 * The semaphore and lock-activity fields in a prepared-xact PGPROC are unused,
 
67
 * but its myProcLocks[] lists are valid.
 
68
 */
 
69
struct PGPROC
 
70
{
 
71
        /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
 
72
        SHM_QUEUE       links;                  /* list link if process is in a list */
 
73
 
 
74
        PGSemaphoreData sem;            /* ONE semaphore to sleep on */
 
75
        int                     waitStatus;             /* STATUS_WAITING, STATUS_OK or STATUS_ERROR */
 
76
 
 
77
        LocalTransactionId lxid;        /* local id of top-level transaction currently
 
78
                                                                 * being executed by this proc, if running;
 
79
                                                                 * else InvalidLocalTransactionId */
 
80
 
 
81
        TransactionId xid;                      /* id of top-level transaction currently being
 
82
                                                                 * executed by this proc, if running and XID
 
83
                                                                 * is assigned; else InvalidTransactionId */
 
84
 
 
85
        TransactionId xmin;                     /* minimal running XID as it was when we were
 
86
                                                                 * starting our xact, excluding LAZY VACUUM:
 
87
                                                                 * vacuum must not remove tuples deleted by
 
88
                                                                 * xid >= xmin ! */
 
89
 
 
90
        int                     pid;                    /* Backend's process ID; 0 if prepared xact */
 
91
 
 
92
        /* These fields are zero while a backend is still starting up: */
 
93
        BackendId       backendId;              /* This backend's backend ID (if assigned) */
 
94
        Oid                     databaseId;             /* OID of database this backend is using */
 
95
        Oid                     roleId;                 /* OID of role using this backend */
 
96
 
 
97
        bool            inCommit;               /* true if within commit critical section */
 
98
 
 
99
        uint8           vacuumFlags;    /* vacuum-related flags, see above */
 
100
 
 
101
        /*
 
102
         * While in hot standby mode, shows that a conflict signal has been sent
 
103
         * for the current transaction. Set/cleared while holding ProcArrayLock,
 
104
         * though not required. Accessed without lock, if needed.
 
105
         */
 
106
        bool            recoveryConflictPending;
 
107
 
 
108
        /* Info about LWLock the process is currently waiting for, if any. */
 
109
        bool            lwWaiting;              /* true if waiting for an LW lock */
 
110
        bool            lwExclusive;    /* true if waiting for exclusive access */
 
111
        struct PGPROC *lwWaitLink;      /* next waiter for same LW lock */
 
112
 
 
113
        /* Info about lock the process is currently waiting for, if any. */
 
114
        /* waitLock and waitProcLock are NULL if not currently waiting. */
 
115
        LOCK       *waitLock;           /* Lock object we're sleeping on ... */
 
116
        PROCLOCK   *waitProcLock;       /* Per-holder info for awaited lock */
 
117
        LOCKMODE        waitLockMode;   /* type of lock we're waiting for */
 
118
        LOCKMASK        heldLocks;              /* bitmask for lock types already held on this
 
119
                                                                 * lock object by this backend */
 
120
 
 
121
        /*
 
122
         * Info to allow us to wait for synchronous replication, if needed.
 
123
         * waitLSN is InvalidXLogRecPtr if not waiting; set only by user backend.
 
124
         * syncRepState must not be touched except by owning process or WALSender.
 
125
         * syncRepLinks used only while holding SyncRepLock.
 
126
         */
 
127
        Latch           waitLatch;              /* allow us to wait for sync rep */
 
128
        XLogRecPtr      waitLSN;                /* waiting for this LSN or higher */
 
129
        int                     syncRepState;   /* wait state for sync rep */
 
130
        SHM_QUEUE       syncRepLinks;   /* list link if process is in syncrep queue */
 
131
 
 
132
        /*
 
133
         * All PROCLOCK objects for locks held or awaited by this backend are
 
134
         * linked into one of these lists, according to the partition number of
 
135
         * their lock.
 
136
         */
 
137
        SHM_QUEUE       myProcLocks[NUM_LOCK_PARTITIONS];
 
138
 
 
139
        struct XidCache subxids;        /* cache for subtransaction XIDs */
 
140
};
 
141
 
 
142
/* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */
 
143
 
 
144
 
 
145
extern PGDLLIMPORT PGPROC *MyProc;
 
146
 
 
147
 
 
148
/*
 
149
 * There is one ProcGlobal struct for the whole database cluster.
 
150
 */
 
151
typedef struct PROC_HDR
 
152
{
 
153
        /* Head of list of free PGPROC structures */
 
154
        PGPROC     *freeProcs;
 
155
        /* Head of list of autovacuum's free PGPROC structures */
 
156
        PGPROC     *autovacFreeProcs;
 
157
        /* Current shared estimate of appropriate spins_per_delay value */
 
158
        int                     spins_per_delay;
 
159
        /* The proc of the Startup process, since not in ProcArray */
 
160
        PGPROC     *startupProc;
 
161
        int                     startupProcPid;
 
162
        /* Buffer id of the buffer that Startup process waits for pin on */
 
163
        int                     startupBufferPinWaitBufId;
 
164
} PROC_HDR;
 
165
 
 
166
/*
 
167
 * We set aside some extra PGPROC structures for auxiliary processes,
 
168
 * ie things that aren't full-fledged backends but need shmem access.
 
169
 *
 
170
 * Background writer and WAL writer run during normal operation. Startup
 
171
 * process and WAL receiver also consume 2 slots, but WAL writer is
 
172
 * launched only after startup has exited, so we only need 3 slots.
 
173
 */
 
174
#define NUM_AUXILIARY_PROCS             3
 
175
 
 
176
 
 
177
/* configurable options */
 
178
extern int      DeadlockTimeout;
 
179
extern int      StatementTimeout;
 
180
extern bool log_lock_waits;
 
181
 
 
182
extern volatile bool cancel_from_timeout;
 
183
 
 
184
 
 
185
/*
 
186
 * Function Prototypes
 
187
 */
 
188
extern int      ProcGlobalSemas(void);
 
189
extern Size ProcGlobalShmemSize(void);
 
190
extern void InitProcGlobal(void);
 
191
extern void InitProcess(void);
 
192
extern void InitProcessPhase2(void);
 
193
extern void InitAuxiliaryProcess(void);
 
194
 
 
195
extern void PublishStartupProcessInformation(void);
 
196
extern void SetStartupBufferPinWaitBufId(int bufid);
 
197
extern int      GetStartupBufferPinWaitBufId(void);
 
198
 
 
199
extern bool HaveNFreeProcs(int n);
 
200
extern void ProcReleaseLocks(bool isCommit);
 
201
 
 
202
extern void ProcQueueInit(PROC_QUEUE *queue);
 
203
extern int      ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable);
 
204
extern PGPROC *ProcWakeup(PGPROC *proc, int waitStatus);
 
205
extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock);
 
206
extern bool IsWaitingForLock(void);
 
207
extern void LockWaitCancel(void);
 
208
 
 
209
extern void ProcWaitForSignal(void);
 
210
extern void ProcSendSignal(int pid);
 
211
 
 
212
extern bool enable_sig_alarm(int delayms, bool is_statement_timeout);
 
213
extern bool disable_sig_alarm(bool is_statement_timeout);
 
214
extern void handle_sig_alarm(SIGNAL_ARGS);
 
215
 
 
216
extern bool enable_standby_sig_alarm(TimestampTz now,
 
217
                                                 TimestampTz fin_time, bool deadlock_only);
 
218
extern bool disable_standby_sig_alarm(void);
 
219
extern void handle_standby_sig_alarm(SIGNAL_ARGS);
 
220
 
 
221
#endif   /* PROC_H */