]> granicus.if.org Git - postgresql/blob - src/include/storage/proc.h
Remove the CheckpointStartLock in favor of having backends show whether they
[postgresql] / src / include / storage / proc.h
1 /*-------------------------------------------------------------------------
2  *
3  * proc.h
4  *        per-process shared memory data structures
5  *
6  *
7  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.97 2007/04/03 16:34:36 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef _PROC_H_
15 #define _PROC_H_
16
17 #include "storage/lock.h"
18 #include "storage/pg_sema.h"
19
20
21 /*
22  * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
23  * for non-aborted subtransactions of its current top transaction.      These
24  * have to be treated as running XIDs by other backends.
25  *
26  * We also keep track of whether the cache overflowed (ie, the transaction has
27  * generated at least one subtransaction that didn't fit in the cache).
28  * If none of the caches have overflowed, we can assume that an XID that's not
29  * listed anywhere in the PGPROC array is not a running transaction.  Else we
30  * have to look at pg_subtrans.
31  */
32 #define PGPROC_MAX_CACHED_SUBXIDS 64    /* XXX guessed-at value */
33
34 struct XidCache
35 {
36         bool            overflowed;
37         int                     nxids;
38         TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS];
39 };
40
41 /*
42  * Each backend has a PGPROC struct in shared memory.  There is also a list of
43  * currently-unused PGPROC structs that will be reallocated to new backends.
44  *
45  * links: list link for any list the PGPROC is in.      When waiting for a lock,
46  * the PGPROC is linked into that lock's waitProcs queue.  A recycled PGPROC
47  * is linked into ProcGlobal's freeProcs list.
48  *
49  * Note: twophase.c also sets up a dummy PGPROC struct for each currently
50  * prepared transaction.  These PGPROCs appear in the ProcArray data structure
51  * so that the prepared transactions appear to be still running and are
52  * correctly shown as holding locks.  A prepared transaction PGPROC can be
53  * distinguished from a real one at need by the fact that it has pid == 0.
54  * The semaphore and lock-activity fields in a prepared-xact PGPROC are unused,
55  * but its myProcLocks[] lists are valid.
56  */
57 struct PGPROC
58 {
59         /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
60         SHM_QUEUE       links;                  /* list link if process is in a list */
61
62         PGSemaphoreData sem;            /* ONE semaphore to sleep on */
63         int                     waitStatus;             /* STATUS_WAITING, STATUS_OK or STATUS_ERROR */
64
65         TransactionId xid;                      /* transaction currently being executed by
66                                                                  * this proc */
67
68         TransactionId xmin;                     /* minimal running XID as it was when we were
69                                                                  * starting our xact, excluding LAZY VACUUM:
70                                                                  * vacuum must not remove tuples deleted by
71                                                                  * xid >= xmin ! */
72
73         int                     pid;                    /* This backend's process id, or 0 */
74         Oid                     databaseId;             /* OID of database this backend is using */
75         Oid                     roleId;                 /* OID of role using this backend */
76
77         bool            inCommit;               /* true if within commit critical section */
78
79         bool            inVacuum;               /* true if current xact is a LAZY VACUUM */
80         bool            isAutovacuum;   /* true if it's autovacuum */
81
82         /* Info about LWLock the process is currently waiting for, if any. */
83         bool            lwWaiting;              /* true if waiting for an LW lock */
84         bool            lwExclusive;    /* true if waiting for exclusive access */
85         struct PGPROC *lwWaitLink;      /* next waiter for same LW lock */
86
87         /* Info about lock the process is currently waiting for, if any. */
88         /* waitLock and waitProcLock are NULL if not currently waiting. */
89         LOCK       *waitLock;           /* Lock object we're sleeping on ... */
90         PROCLOCK   *waitProcLock;       /* Per-holder info for awaited lock */
91         LOCKMODE        waitLockMode;   /* type of lock we're waiting for */
92         LOCKMASK        heldLocks;              /* bitmask for lock types already held on this
93                                                                  * lock object by this backend */
94
95         /*
96          * All PROCLOCK objects for locks held or awaited by this backend are
97          * linked into one of these lists, according to the partition number of
98          * their lock.
99          */
100         SHM_QUEUE       myProcLocks[NUM_LOCK_PARTITIONS];
101
102         struct XidCache subxids;        /* cache for subtransaction XIDs */
103 };
104
105 /* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */
106
107
108 extern DLLIMPORT PGPROC *MyProc;
109
110
111 /*
112  * There is one ProcGlobal struct for the whole database cluster.
113  */
114 typedef struct PROC_HDR
115 {
116         /* Head of list of free PGPROC structures */
117         SHMEM_OFFSET freeProcs;
118         /* Current shared estimate of appropriate spins_per_delay value */
119         int                     spins_per_delay;
120 } PROC_HDR;
121
122 /*
123  * We set aside some extra PGPROC structures for auxiliary processes,
124  * ie things that aren't full-fledged backends but need shmem access.
125  */
126 #define NUM_AUXILIARY_PROCS             3
127
128
129 /* configurable options */
130 extern int      DeadlockTimeout;
131 extern int      StatementTimeout;
132 extern bool     log_lock_waits;
133
134 extern volatile bool cancel_from_timeout;
135
136
137 /*
138  * Function Prototypes
139  */
140 extern int      ProcGlobalSemas(void);
141 extern Size ProcGlobalShmemSize(void);
142 extern void InitProcGlobal(void);
143 extern void InitProcess(void);
144 extern void InitProcessPhase2(void);
145 extern void InitAuxiliaryProcess(void);
146 extern bool HaveNFreeProcs(int n);
147 extern void ProcReleaseLocks(bool isCommit);
148
149 extern void ProcQueueInit(PROC_QUEUE *queue);
150 extern int      ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable);
151 extern PGPROC *ProcWakeup(PGPROC *proc, int waitStatus);
152 extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock);
153 extern bool LockWaitCancel(void);
154
155 extern void ProcWaitForSignal(void);
156 extern void ProcSendSignal(int pid);
157
158 extern bool enable_sig_alarm(int delayms, bool is_statement_timeout);
159 extern bool disable_sig_alarm(bool is_statement_timeout);
160 extern void handle_sig_alarm(SIGNAL_ARGS);
161
162 #endif   /* PROC_H */