1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* proc.h
|
2000-11-29 00:27:57 +01:00
|
|
|
* per-process shared memory data structures
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2004-12-31 23:04:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2005-10-15 04:49:52 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.84 2005/10/15 02:49:46 momjian Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef _PROC_H_
|
|
|
|
#define _PROC_H_
|
|
|
|
|
1999-09-27 17:48:12 +02:00
|
|
|
#include "access/xlog.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "storage/lock.h"
|
2002-05-05 02:03:29 +02:00
|
|
|
#include "storage/pg_sema.h"
|
1996-11-05 07:11:08 +01:00
|
|
|
|
2000-05-31 02:28:42 +02:00
|
|
|
|
2004-08-01 19:32:22 +02:00
|
|
|
/*
|
|
|
|
* Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
|
2004-08-29 07:07:03 +02:00
|
|
|
* for non-aborted subtransactions of its current top transaction. These
|
2004-08-01 19:32:22 +02:00
|
|
|
* have to be treated as running XIDs by other backends.
|
|
|
|
*
|
|
|
|
* We also keep track of whether the cache overflowed (ie, the transaction has
|
|
|
|
* generated at least one subtransaction that didn't fit in the cache).
|
|
|
|
* If none of the caches have overflowed, we can assume that an XID that's not
|
|
|
|
* listed anywhere in the PGPROC array is not a running transaction. Else we
|
|
|
|
* have to look at pg_subtrans.
|
|
|
|
*/
|
2004-08-29 07:07:03 +02:00
|
|
|
#define PGPROC_MAX_CACHED_SUBXIDS 64 /* XXX guessed-at value */
|
2004-08-01 19:32:22 +02:00
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
struct XidCache
|
|
|
|
{
|
|
|
|
bool overflowed;
|
|
|
|
int nxids;
|
|
|
|
TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS];
|
2004-08-01 19:32:22 +02:00
|
|
|
};
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
2002-06-11 15:40:53 +02:00
|
|
|
* Each backend has a PGPROC struct in shared memory. There is also a list of
|
|
|
|
* currently-unused PGPROC structs that will be reallocated to new backends.
|
2001-01-16 07:11:34 +01:00
|
|
|
*
|
2002-09-04 22:31:48 +02:00
|
|
|
* links: list link for any list the PGPROC is in. When waiting for a lock,
|
2002-06-11 15:40:53 +02:00
|
|
|
* the PGPROC is linked into that lock's waitProcs queue. A recycled PGPROC
|
2001-01-16 07:11:34 +01:00
|
|
|
* is linked into ProcGlobal's freeProcs list.
|
2005-06-18 00:32:51 +02:00
|
|
|
*
|
|
|
|
* Note: twophase.c also sets up a dummy PGPROC struct for each currently
|
|
|
|
* prepared transaction. These PGPROCs appear in the ProcArray data structure
|
|
|
|
* so that the prepared transactions appear to be still running and are
|
|
|
|
* correctly shown as holding locks. A prepared transaction PGPROC can be
|
|
|
|
* distinguished from a real one at need by the fact that it has pid == 0.
|
|
|
|
* The semaphore and lock-related fields in a prepared-xact PGPROC are unused.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
2002-06-11 15:40:53 +02:00
|
|
|
struct PGPROC
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2001-01-22 23:30:06 +01:00
|
|
|
/* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */
|
2001-01-16 07:11:34 +01:00
|
|
|
SHM_QUEUE links; /* list link if process is in a list */
|
|
|
|
|
2002-05-05 02:03:29 +02:00
|
|
|
PGSemaphoreData sem; /* ONE semaphore to sleep on */
|
2004-07-17 05:32:14 +02:00
|
|
|
int waitStatus; /* STATUS_OK or STATUS_ERROR after wakeup */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
TransactionId xid; /* transaction currently being executed by
|
1997-09-07 07:04:48 +02:00
|
|
|
* this proc */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2005-10-15 04:49:52 +02:00
|
|
|
TransactionId xmin; /* minimal running XID as it was when we were
|
|
|
|
* starting our xact: vacuum must not remove
|
|
|
|
* tuples deleted by xid >= xmin ! */
|
2000-12-22 01:51:54 +01:00
|
|
|
|
2005-06-18 00:32:51 +02:00
|
|
|
int pid; /* This backend's process id, or 0 */
|
2001-09-29 06:02:27 +02:00
|
|
|
Oid databaseId; /* OID of database this backend is using */
|
2005-07-31 19:19:22 +02:00
|
|
|
Oid roleId; /* OID of role using this backend */
|
2001-09-29 06:02:27 +02:00
|
|
|
|
|
|
|
/* Info about LWLock the process is currently waiting for, if any. */
|
|
|
|
bool lwWaiting; /* true if waiting for an LW lock */
|
|
|
|
bool lwExclusive; /* true if waiting for exclusive access */
|
2002-06-11 15:40:53 +02:00
|
|
|
struct PGPROC *lwWaitLink; /* next waiter for same LW lock */
|
2001-09-29 06:02:27 +02:00
|
|
|
|
2001-01-22 23:30:06 +01:00
|
|
|
/* Info about lock the process is currently waiting for, if any. */
|
2004-08-27 19:07:42 +02:00
|
|
|
/* waitLock and waitProcLock are NULL if not currently waiting. */
|
2000-12-22 01:51:54 +01:00
|
|
|
LOCK *waitLock; /* Lock object we're sleeping on ... */
|
2004-08-27 19:07:42 +02:00
|
|
|
PROCLOCK *waitProcLock; /* Per-holder info for awaited lock */
|
2000-12-22 01:51:54 +01:00
|
|
|
LOCKMODE waitLockMode; /* type of lock we're waiting for */
|
2005-10-15 04:49:52 +02:00
|
|
|
LOCKMASK heldLocks; /* bitmask for lock types already held on this
|
|
|
|
* lock object by this backend */
|
2000-12-22 01:51:54 +01:00
|
|
|
|
2005-10-15 04:49:52 +02:00
|
|
|
SHM_QUEUE procLocks; /* list of PROCLOCK objects for locks held or
|
|
|
|
* awaited by this backend */
|
2004-08-01 19:32:22 +02:00
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
struct XidCache subxids; /* cache for subtransaction XIDs */
|
2000-12-22 01:51:54 +01:00
|
|
|
};
|
|
|
|
|
2002-06-11 15:40:53 +02:00
|
|
|
/* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */
|
2000-12-22 01:51:54 +01:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2002-10-21 20:57:35 +02:00
|
|
|
extern DLLIMPORT PGPROC *MyProc;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-11-29 00:27:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There is one ProcGlobal struct for the whole installation.
|
|
|
|
*/
|
2001-09-29 06:02:27 +02:00
|
|
|
typedef struct PROC_HDR
|
2000-11-29 00:27:57 +01:00
|
|
|
{
|
2002-06-11 15:40:53 +02:00
|
|
|
/* Head of list of free PGPROC structures */
|
2000-11-29 00:27:57 +01:00
|
|
|
SHMEM_OFFSET freeProcs;
|
2005-10-11 22:41:32 +02:00
|
|
|
/* Current shared estimate of appropriate spins_per_delay value */
|
|
|
|
int spins_per_delay;
|
2000-11-29 00:27:57 +01:00
|
|
|
} PROC_HDR;
|
|
|
|
|
2001-09-29 06:02:27 +02:00
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
#define DUMMY_PROC_DEFAULT 0
|
|
|
|
#define DUMMY_PROC_BGWRITER 1
|
|
|
|
#define NUM_DUMMY_PROCS 2
|
2003-11-19 16:55:08 +01:00
|
|
|
|
|
|
|
|
2002-10-31 22:34:17 +01:00
|
|
|
/* configurable options */
|
2001-09-29 06:02:27 +02:00
|
|
|
extern int DeadlockTimeout;
|
2002-10-31 22:34:17 +01:00
|
|
|
extern int StatementTimeout;
|
2001-09-29 06:02:27 +02:00
|
|
|
|
2005-09-19 19:21:49 +02:00
|
|
|
extern volatile bool cancel_from_timeout;
|
|
|
|
|
2001-09-29 06:02:27 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
|
|
|
* Function Prototypes
|
|
|
|
*/
|
2005-06-18 00:32:51 +02:00
|
|
|
extern int ProcGlobalSemas(void);
|
2005-08-21 01:26:37 +02:00
|
|
|
extern Size ProcGlobalShmemSize(void);
|
2005-06-18 00:32:51 +02:00
|
|
|
extern void InitProcGlobal(void);
|
2000-11-29 00:27:57 +01:00
|
|
|
extern void InitProcess(void);
|
2003-11-19 16:55:08 +01:00
|
|
|
extern void InitDummyProcess(int proctype);
|
2005-06-18 00:32:51 +02:00
|
|
|
extern bool HaveNFreeProcs(int n);
|
2004-07-17 05:32:14 +02:00
|
|
|
extern void ProcReleaseLocks(bool isCommit);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 23:56:23 +02:00
|
|
|
extern void ProcQueueInit(PROC_QUEUE *queue);
|
Try to reduce confusion about what is a lock method identifier, a lock
method control structure, or a table of control structures.
. Use type LOCKMASK where an int is not a counter.
. Get rid of INVALID_TABLEID, use INVALID_LOCKMETHOD instead.
. Use INVALID_LOCKMETHOD instead of (LOCKMETHOD) NULL, because
LOCKMETHOD is not a pointer.
. Define and use macro LockMethodIsValid.
. Rename LOCKMETHOD to LOCKMETHODID.
. Remove global variable LongTermTableId in lmgr.c, because it is
never used.
. Make LockTableId static in lmgr.c, because it is used nowhere else.
Why not remove it and use DEFAULT_LOCKMETHOD?
. Rename the lock method control structure from LOCKMETHODTABLE to
LockMethodData. Introduce a pointer type named LockMethod.
. Remove elog(FATAL) after InitLockTable() call in
CreateSharedMemoryAndSemaphores(), because if something goes wrong,
there is elog(FATAL) in LockMethodTableInit(), and if this doesn't
help, an elog(ERROR) in InitLockTable() is promoted to FATAL.
. Make InitLockTable() void, because its only caller does not use its
return value any more.
. Rename variables in lock.c to avoid statements like
LockMethodTable[NumLockMethods] = lockMethodTable;
lockMethodTable = LockMethodTable[lockmethod];
. Change LOCKMETHODID type to uint16 to fit into struct LOCKTAG.
. Remove static variables BITS_OFF and BITS_ON from lock.c, because
I agree to this doubt:
* XXX is a fetch from a static array really faster than a shift?
. Define and use macros LOCKBIT_ON/OFF.
Manfred Koizar
2003-12-01 22:59:25 +01:00
|
|
|
extern int ProcSleep(LockMethod lockMethodTable, LOCKMODE lockmode,
|
2003-02-18 03:13:24 +01:00
|
|
|
LOCK *lock, PROCLOCK *proclock);
|
2004-07-17 05:32:14 +02:00
|
|
|
extern PGPROC *ProcWakeup(PGPROC *proc, int waitStatus);
|
Try to reduce confusion about what is a lock method identifier, a lock
method control structure, or a table of control structures.
. Use type LOCKMASK where an int is not a counter.
. Get rid of INVALID_TABLEID, use INVALID_LOCKMETHOD instead.
. Use INVALID_LOCKMETHOD instead of (LOCKMETHOD) NULL, because
LOCKMETHOD is not a pointer.
. Define and use macro LockMethodIsValid.
. Rename LOCKMETHOD to LOCKMETHODID.
. Remove global variable LongTermTableId in lmgr.c, because it is
never used.
. Make LockTableId static in lmgr.c, because it is used nowhere else.
Why not remove it and use DEFAULT_LOCKMETHOD?
. Rename the lock method control structure from LOCKMETHODTABLE to
LockMethodData. Introduce a pointer type named LockMethod.
. Remove elog(FATAL) after InitLockTable() call in
CreateSharedMemoryAndSemaphores(), because if something goes wrong,
there is elog(FATAL) in LockMethodTableInit(), and if this doesn't
help, an elog(ERROR) in InitLockTable() is promoted to FATAL.
. Make InitLockTable() void, because its only caller does not use its
return value any more.
. Rename variables in lock.c to avoid statements like
LockMethodTable[NumLockMethods] = lockMethodTable;
lockMethodTable = LockMethodTable[lockmethod];
. Change LOCKMETHODID type to uint16 to fit into struct LOCKTAG.
. Remove static variables BITS_OFF and BITS_ON from lock.c, because
I agree to this doubt:
* XXX is a fetch from a static array really faster than a shift?
. Define and use macros LOCKBIT_ON/OFF.
Manfred Koizar
2003-12-01 22:59:25 +01:00
|
|
|
extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock);
|
2001-01-16 21:59:34 +01:00
|
|
|
extern bool LockWaitCancel(void);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2001-07-06 23:04:26 +02:00
|
|
|
extern void ProcWaitForSignal(void);
|
|
|
|
extern void ProcCancelWaitForSignal(void);
|
2005-05-19 23:35:48 +02:00
|
|
|
extern void ProcSendSignal(int pid);
|
2001-07-06 23:04:26 +02:00
|
|
|
|
2002-07-13 03:02:14 +02:00
|
|
|
extern bool enable_sig_alarm(int delayms, bool is_statement_timeout);
|
|
|
|
extern bool disable_sig_alarm(bool is_statement_timeout);
|
|
|
|
extern void handle_sig_alarm(SIGNAL_ARGS);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PROC_H */
|