]> granicus.if.org Git - postgresql/blob - src/include/storage/proc.h
Introduce local hash table for lock state, as per recent proposal.
[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-2003, 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.73 2004/08/27 17:07:42 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef _PROC_H_
15 #define _PROC_H_
16
17 #include "access/xlog.h"
18 #include "storage/backendid.h"
19 #include "storage/lock.h"
20 #include "storage/pg_sema.h"
21
22
23 /*
24  * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
25  * for non-aborted subtransactions of its current top transaction.  These
26  * have to be treated as running XIDs by other backends.
27  *
28  * We also keep track of whether the cache overflowed (ie, the transaction has
29  * generated at least one subtransaction that didn't fit in the cache).
30  * If none of the caches have overflowed, we can assume that an XID that's not
31  * listed anywhere in the PGPROC array is not a running transaction.  Else we
32  * have to look at pg_subtrans.
33  */
34 #define PGPROC_MAX_CACHED_SUBXIDS 64            /* XXX guessed-at value */
35
36 struct XidCache {
37         bool                    overflowed;
38         int                             nxids;
39         TransactionId   xids[PGPROC_MAX_CACHED_SUBXIDS];
40 };
41
42 /*
43  * Each backend has a PGPROC struct in shared memory.  There is also a list of
44  * currently-unused PGPROC structs that will be reallocated to new backends.
45  *
46  * links: list link for any list the PGPROC is in.      When waiting for a lock,
47  * the PGPROC is linked into that lock's waitProcs queue.  A recycled PGPROC
48  * is linked into ProcGlobal's freeProcs list.
49  */
50 struct PGPROC
51 {
52         /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
53         SHM_QUEUE       links;                  /* list link if process is in a list */
54
55         PGSemaphoreData sem;            /* ONE semaphore to sleep on */
56         int                     waitStatus;             /* STATUS_OK or STATUS_ERROR after wakeup */
57
58         TransactionId xid;                      /* transaction currently being executed by
59                                                                  * this proc */
60
61         TransactionId xmin;                     /* minimal running XID as it was when we
62                                                                  * were starting our xact: vacuum must not
63                                                                  * remove tuples deleted by xid >= xmin ! */
64
65         int                     pid;                    /* This backend's process id */
66         Oid                     databaseId;             /* OID of database this backend is using */
67
68         /*
69          * XLOG location of first XLOG record written by this backend's
70          * current transaction.  If backend is not in a transaction or hasn't
71          * yet modified anything, logRec.xrecoff is zero.
72          */
73         XLogRecPtr      logRec;
74
75         /* Info about LWLock the process is currently waiting for, if any. */
76         bool            lwWaiting;              /* true if waiting for an LW lock */
77         bool            lwExclusive;    /* true if waiting for exclusive access */
78         struct PGPROC *lwWaitLink;      /* next waiter for same LW lock */
79
80         /* Info about lock the process is currently waiting for, if any. */
81         /* waitLock and waitProcLock are NULL if not currently waiting. */
82         LOCK       *waitLock;           /* Lock object we're sleeping on ... */
83         PROCLOCK   *waitProcLock;       /* Per-holder info for awaited lock */
84         LOCKMODE        waitLockMode;   /* type of lock we're waiting for */
85         LOCKMASK        heldLocks;              /* bitmask for lock types already held on
86                                                                  * this lock object by this backend */
87
88         SHM_QUEUE       procLocks;              /* list of PROCLOCK objects for locks held
89                                                                  * or awaited by this backend */
90
91         struct XidCache subxids;        /* cache for subtransaction XIDs */
92 };
93
94 /* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */
95
96
97 extern DLLIMPORT PGPROC *MyProc;
98
99
100 /*
101  * There is one ProcGlobal struct for the whole installation.
102  */
103 typedef struct PROC_HDR
104 {
105         /* Head of list of free PGPROC structures */
106         SHMEM_OFFSET freeProcs;
107 } PROC_HDR;
108
109
110 #define DUMMY_PROC_DEFAULT      0
111 #define DUMMY_PROC_BGWRITER     1
112 #define NUM_DUMMY_PROCS         2
113
114
115 /* configurable options */
116 extern int      DeadlockTimeout;
117 extern int      StatementTimeout;
118
119
120 /*
121  * Function Prototypes
122  */
123 extern int      ProcGlobalSemas(int maxBackends);
124 extern void InitProcGlobal(int maxBackends);
125 extern void InitProcess(void);
126 extern void InitDummyProcess(int proctype);
127 extern void ProcReleaseLocks(bool isCommit);
128
129 extern void ProcQueueInit(PROC_QUEUE *queue);
130 extern int ProcSleep(LockMethod lockMethodTable, LOCKMODE lockmode,
131                   LOCK *lock, PROCLOCK *proclock);
132 extern PGPROC *ProcWakeup(PGPROC *proc, int waitStatus);
133 extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock);
134 extern bool LockWaitCancel(void);
135
136 extern void ProcWaitForSignal(void);
137 extern void ProcCancelWaitForSignal(void);
138 extern void ProcSendSignal(BackendId procId);
139
140 extern bool enable_sig_alarm(int delayms, bool is_statement_timeout);
141 extern bool disable_sig_alarm(bool is_statement_timeout);
142 extern void handle_sig_alarm(SIGNAL_ARGS);
143
144 #endif   /* PROC_H */