Commit 2584029e authored by Bruce Momjian's avatar Bruce Momjian

Rename locking structure names to be clearer. Add narrative to

backend flowchart.
parent f21fa6a7
This diff is collapsed.
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/multi.c,v 1.18 1998/06/28 21:17:35 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/multi.c,v 1.19 1998/06/30 02:33:31 momjian Exp $
* *
* NOTES: * NOTES:
* (1) The lock.c module assumes that the caller here is doing * (1) The lock.c module assumes that the caller here is doing
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
#include "miscadmin.h" /* MyDatabaseId */ #include "miscadmin.h" /* MyDatabaseId */
static bool static bool
MultiAcquire(LockTableId tableId, LOCKTAG *tag, LOCKTYPE locktype, MultiAcquire(LOCKMETHOD lockmethod, LOCKTAG *tag, LOCKMODE lockmode,
PG_LOCK_LEVEL level); PG_LOCK_LEVEL level);
static bool static bool
MultiRelease(LockTableId tableId, LOCKTAG *tag, LOCKTYPE locktype, MultiRelease(LOCKMETHOD lockmethod, LOCKTAG *tag, LOCKMODE lockmode,
PG_LOCK_LEVEL level); PG_LOCK_LEVEL level);
/* /*
...@@ -78,25 +78,27 @@ static int MultiPrios[] = { ...@@ -78,25 +78,27 @@ static int MultiPrios[] = {
* Lock table identifier for this lock table. The multi-level * Lock table identifier for this lock table. The multi-level
* lock table is ONE lock table, not three. * lock table is ONE lock table, not three.
*/ */
LockTableId MultiTableId = (LockTableId) NULL; LOCKMETHOD MultiTableId = (LOCKMETHOD) NULL;
LockTableId ShortTermTableId = (LockTableId) NULL; #ifdef NOT_USED
LOCKMETHOD ShortTermTableId = (LOCKMETHOD) NULL;
#endif
/* /*
* Create the lock table described by MultiConflicts and Multiprio. * Create the lock table described by MultiConflicts and Multiprio.
*/ */
LockTableId LOCKMETHOD
InitMultiLevelLocks() InitMultiLevelLocks()
{ {
int tableId; int lockmethod;
tableId = LockTableInit("LockTable", MultiConflicts, MultiPrios, 5); lockmethod = LockMethodTableInit("MultiLevelLockTable", MultiConflicts, MultiPrios, 5);
MultiTableId = tableId; MultiTableId = lockmethod;
if (!(MultiTableId)) if (!(MultiTableId))
elog(ERROR, "InitMultiLocks: couldnt initialize lock table"); elog(ERROR, "InitMultiLocks: couldnt initialize lock table");
/* ----------------------- /* -----------------------
* No short term lock table for now. -Jeff 15 July 1991 * No short term lock table for now. -Jeff 15 July 1991
* *
* ShortTermTableId = LockTableRename(tableId); * ShortTermTableId = LockTableRename(lockmethod);
* if (! (ShortTermTableId)) { * if (! (ShortTermTableId)) {
* elog(ERROR,"InitMultiLocks: couldnt rename lock table"); * elog(ERROR,"InitMultiLocks: couldnt rename lock table");
* } * }
...@@ -111,7 +113,7 @@ InitMultiLevelLocks() ...@@ -111,7 +113,7 @@ InitMultiLevelLocks()
* Returns: TRUE if the lock can be set, FALSE otherwise. * Returns: TRUE if the lock can be set, FALSE otherwise.
*/ */
bool bool
MultiLockReln(LockInfo linfo, LOCKTYPE locktype) MultiLockReln(LockInfo linfo, LOCKMODE lockmode)
{ {
LOCKTAG tag; LOCKTAG tag;
...@@ -122,7 +124,7 @@ MultiLockReln(LockInfo linfo, LOCKTYPE locktype) ...@@ -122,7 +124,7 @@ MultiLockReln(LockInfo linfo, LOCKTYPE locktype)
MemSet(&tag, 0, sizeof(tag)); MemSet(&tag, 0, sizeof(tag));
tag.relId = linfo->lRelId.relId; tag.relId = linfo->lRelId.relId;
tag.dbId = linfo->lRelId.dbId; tag.dbId = linfo->lRelId.dbId;
return (MultiAcquire(MultiTableId, &tag, locktype, RELN_LEVEL)); return (MultiAcquire(MultiTableId, &tag, lockmode, RELN_LEVEL));
} }
/* /*
...@@ -134,7 +136,7 @@ MultiLockReln(LockInfo linfo, LOCKTYPE locktype) ...@@ -134,7 +136,7 @@ MultiLockReln(LockInfo linfo, LOCKTYPE locktype)
* at the page and relation level. * at the page and relation level.
*/ */
bool bool
MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode)
{ {
LOCKTAG tag; LOCKTAG tag;
...@@ -149,14 +151,14 @@ MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) ...@@ -149,14 +151,14 @@ MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
/* not locking any valid Tuple, just the page */ /* not locking any valid Tuple, just the page */
tag.tupleId = *tidPtr; tag.tupleId = *tidPtr;
return (MultiAcquire(MultiTableId, &tag, locktype, TUPLE_LEVEL)); return (MultiAcquire(MultiTableId, &tag, lockmode, TUPLE_LEVEL));
} }
/* /*
* same as above at page level * same as above at page level
*/ */
bool bool
MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode)
{ {
LOCKTAG tag; LOCKTAG tag;
...@@ -179,7 +181,7 @@ MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) ...@@ -179,7 +181,7 @@ MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
tag.relId = linfo->lRelId.relId; tag.relId = linfo->lRelId.relId;
tag.dbId = linfo->lRelId.dbId; tag.dbId = linfo->lRelId.dbId;
BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid)); BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid));
return (MultiAcquire(MultiTableId, &tag, locktype, PAGE_LEVEL)); return (MultiAcquire(MultiTableId, &tag, lockmode, PAGE_LEVEL));
} }
/* /*
...@@ -189,12 +191,12 @@ MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) ...@@ -189,12 +191,12 @@ MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
* Side Effects: * Side Effects:
*/ */
static bool static bool
MultiAcquire(LockTableId tableId, MultiAcquire(LOCKMETHOD lockmethod,
LOCKTAG *tag, LOCKTAG *tag,
LOCKTYPE locktype, LOCKMODE lockmode,
PG_LOCK_LEVEL level) PG_LOCK_LEVEL level)
{ {
LOCKTYPE locks[N_LEVELS]; LOCKMODE locks[N_LEVELS];
int i, int i,
status; status;
LOCKTAG xxTag, LOCKTAG xxTag,
...@@ -213,19 +215,19 @@ MultiAcquire(LockTableId tableId, ...@@ -213,19 +215,19 @@ MultiAcquire(LockTableId tableId,
switch (level) switch (level)
{ {
case RELN_LEVEL: case RELN_LEVEL:
locks[0] = locktype; locks[0] = lockmode;
locks[1] = NO_LOCK; locks[1] = NO_LOCK;
locks[2] = NO_LOCK; locks[2] = NO_LOCK;
break; break;
case PAGE_LEVEL: case PAGE_LEVEL:
locks[0] = locktype + INTENT; locks[0] = lockmode + INTENT;
locks[1] = locktype; locks[1] = lockmode;
locks[2] = NO_LOCK; locks[2] = NO_LOCK;
break; break;
case TUPLE_LEVEL: case TUPLE_LEVEL:
locks[0] = locktype + INTENT; locks[0] = lockmode + INTENT;
locks[1] = locktype + INTENT; locks[1] = lockmode + INTENT;
locks[2] = locktype; locks[2] = lockmode;
break; break;
default: default:
elog(ERROR, "MultiAcquire: bad lock level"); elog(ERROR, "MultiAcquire: bad lock level");
...@@ -274,7 +276,7 @@ MultiAcquire(LockTableId tableId, ...@@ -274,7 +276,7 @@ MultiAcquire(LockTableId tableId,
break; break;
} }
status = LockAcquire(tableId, tmpTag, locks[i]); status = LockAcquire(lockmethod, tmpTag, locks[i]);
if (!status) if (!status)
{ {
...@@ -285,7 +287,7 @@ MultiAcquire(LockTableId tableId, ...@@ -285,7 +287,7 @@ MultiAcquire(LockTableId tableId,
* the last level lock we successfully acquired * the last level lock we successfully acquired
*/ */
retStatus = FALSE; retStatus = FALSE;
MultiRelease(tableId, tag, locktype, i); MultiRelease(lockmethod, tag, lockmode, i);
/* now leave the loop. Don't try for any more locks */ /* now leave the loop. Don't try for any more locks */
break; break;
} }
...@@ -300,7 +302,7 @@ MultiAcquire(LockTableId tableId, ...@@ -300,7 +302,7 @@ MultiAcquire(LockTableId tableId,
*/ */
#ifdef NOT_USED #ifdef NOT_USED
bool bool
MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode)
{ {
LOCKTAG tag; LOCKTAG tag;
...@@ -316,7 +318,7 @@ MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) ...@@ -316,7 +318,7 @@ MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
tag.dbId = linfo->lRelId.dbId; tag.dbId = linfo->lRelId.dbId;
BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid)); BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid));
return (MultiRelease(MultiTableId, &tag, locktype, PAGE_LEVEL)); return (MultiRelease(MultiTableId, &tag, lockmode, PAGE_LEVEL));
} }
#endif #endif
...@@ -326,7 +328,7 @@ MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) ...@@ -326,7 +328,7 @@ MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
* ------------------ * ------------------
*/ */
bool bool
MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype) MultiReleaseReln(LockInfo linfo, LOCKMODE lockmode)
{ {
LOCKTAG tag; LOCKTAG tag;
...@@ -340,7 +342,7 @@ MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype) ...@@ -340,7 +342,7 @@ MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype)
tag.relId = linfo->lRelId.relId; tag.relId = linfo->lRelId.relId;
tag.dbId = linfo->lRelId.dbId; tag.dbId = linfo->lRelId.dbId;
return (MultiRelease(MultiTableId, &tag, locktype, RELN_LEVEL)); return (MultiRelease(MultiTableId, &tag, lockmode, RELN_LEVEL));
} }
/* /*
...@@ -349,12 +351,12 @@ MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype) ...@@ -349,12 +351,12 @@ MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype)
* Returns: TRUE if successful, FALSE otherwise. * Returns: TRUE if successful, FALSE otherwise.
*/ */
static bool static bool
MultiRelease(LockTableId tableId, MultiRelease(LOCKMETHOD lockmethod,
LOCKTAG *tag, LOCKTAG *tag,
LOCKTYPE locktype, LOCKMODE lockmode,
PG_LOCK_LEVEL level) PG_LOCK_LEVEL level)
{ {
LOCKTYPE locks[N_LEVELS]; LOCKMODE locks[N_LEVELS];
int i, int i,
status; status;
LOCKTAG xxTag, LOCKTAG xxTag,
...@@ -366,22 +368,22 @@ MultiRelease(LockTableId tableId, ...@@ -366,22 +368,22 @@ MultiRelease(LockTableId tableId,
switch (level) switch (level)
{ {
case RELN_LEVEL: case RELN_LEVEL:
locks[0] = locktype; locks[0] = lockmode;
locks[1] = NO_LOCK; locks[1] = NO_LOCK;
locks[2] = NO_LOCK; locks[2] = NO_LOCK;
break; break;
case PAGE_LEVEL: case PAGE_LEVEL:
locks[0] = locktype + INTENT; locks[0] = lockmode + INTENT;
locks[1] = locktype; locks[1] = lockmode;
locks[2] = NO_LOCK; locks[2] = NO_LOCK;
break; break;
case TUPLE_LEVEL: case TUPLE_LEVEL:
locks[0] = locktype + INTENT; locks[0] = lockmode + INTENT;
locks[1] = locktype + INTENT; locks[1] = lockmode + INTENT;
locks[2] = locktype; locks[2] = lockmode;
break; break;
default: default:
elog(ERROR, "MultiRelease: bad locktype"); elog(ERROR, "MultiRelease: bad lockmode");
} }
/* /*
...@@ -423,7 +425,7 @@ MultiRelease(LockTableId tableId, ...@@ -423,7 +425,7 @@ MultiRelease(LockTableId tableId,
ItemPointerCopy(&tmpTag->tupleId, &tag->tupleId); ItemPointerCopy(&tmpTag->tupleId, &tag->tupleId);
break; break;
} }
status = LockRelease(tableId, tmpTag, locks[i]); status = LockRelease(lockmethod, tmpTag, locks[i]);
if (!status) if (!status)
elog(ERROR, "MultiRelease: couldn't release after error"); elog(ERROR, "MultiRelease: couldn't release after error");
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.38 1998/06/27 15:47:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.39 1998/06/30 02:33:32 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
* This is so that we can support more backends. (system-wide semaphore * This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95 * sets run out pretty fast.) -ay 4/95
* *
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.38 1998/06/27 15:47:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.39 1998/06/30 02:33:32 momjian Exp $
*/ */
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
...@@ -580,7 +580,7 @@ ProcWakeup(PROC *proc, int errType) ...@@ -580,7 +580,7 @@ ProcWakeup(PROC *proc, int errType)
* released. * released.
*/ */
int int
ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock) ProcLockWakeup(PROC_QUEUE *queue, LOCKMETHOD lockmethod, LOCK *lock)
{ {
PROC *proc; PROC *proc;
int count; int count;
...@@ -590,8 +590,8 @@ ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock) ...@@ -590,8 +590,8 @@ ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock)
proc = (PROC *) MAKE_PTR(queue->links.prev); proc = (PROC *) MAKE_PTR(queue->links.prev);
count = 0; count = 0;
while ((LockResolveConflicts((LOCKTAB *) ltable, while ((LockResolveConflicts(lockmethod,
(LOCK *) lock, lock,
proc->token, proc->token,
proc->xid) == STATUS_OK)) proc->xid) == STATUS_OK))
{ {
...@@ -602,7 +602,7 @@ ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock) ...@@ -602,7 +602,7 @@ ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock)
* between the time we release the lock master (spinlock) and the * between the time we release the lock master (spinlock) and the
* time that the awoken process begins executing again. * time that the awoken process begins executing again.
*/ */
GrantLock((LOCK *) lock, proc->token); GrantLock(lock, proc->token);
queue->size--; queue->size--;
/* /*
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/single.c,v 1.6 1998/06/28 21:17:35 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/single.c,v 1.7 1998/06/30 02:33:32 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
* Returns: TRUE if the lock can be set, FALSE otherwise. * Returns: TRUE if the lock can be set, FALSE otherwise.
*/ */
bool bool
SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action) SingleLockReln(LockInfo linfo, LOCKMODE lockmode, int action)
{ {
LOCKTAG tag; LOCKTAG tag;
...@@ -47,9 +47,9 @@ SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action) ...@@ -47,9 +47,9 @@ SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action)
tag.tupleId.ip_posid = InvalidOffsetNumber; tag.tupleId.ip_posid = InvalidOffsetNumber;
if (action == UNLOCK) if (action == UNLOCK)
return (LockRelease(MultiTableId, &tag, locktype)); return (LockRelease(MultiTableId, &tag, lockmode));
else else
return (LockAcquire(MultiTableId, &tag, locktype)); return (LockAcquire(MultiTableId, &tag, lockmode));
} }
/* /*
...@@ -63,7 +63,7 @@ SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action) ...@@ -63,7 +63,7 @@ SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action)
bool bool
SingleLockPage(LockInfo linfo, SingleLockPage(LockInfo linfo,
ItemPointer tidPtr, ItemPointer tidPtr,
LOCKTYPE locktype, LOCKMODE lockmode,
int action) int action)
{ {
LOCKTAG tag; LOCKTAG tag;
...@@ -80,7 +80,7 @@ SingleLockPage(LockInfo linfo, ...@@ -80,7 +80,7 @@ SingleLockPage(LockInfo linfo,
if (action == UNLOCK) if (action == UNLOCK)
return (LockRelease(MultiTableId, &tag, locktype)); return (LockRelease(MultiTableId, &tag, lockmode));
else else
return (LockAcquire(MultiTableId, &tag, locktype)); return (LockAcquire(MultiTableId, &tag, lockmode));
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: lmgr.h,v 1.11 1998/06/28 21:17:35 momjian Exp $ * $Id: lmgr.h,v 1.12 1998/06/30 02:33:32 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -72,10 +72,10 @@ extern void RelationSetWIntentLock(Relation relation); ...@@ -72,10 +72,10 @@ extern void RelationSetWIntentLock(Relation relation);
extern void RelationUnsetWIntentLock(Relation relation); extern void RelationUnsetWIntentLock(Relation relation);
/* single.c */ /* single.c */
extern bool SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action); extern bool SingleLockReln(LockInfo linfo, LOCKMODE lockmode, int action);
extern bool extern bool
SingleLockPage(LockInfo linfo, ItemPointer tidPtr, SingleLockPage(LockInfo linfo, ItemPointer tidPtr,
LOCKTYPE locktype, int action); LOCKMODE lockmode, int action);
/* proc.c */ /* proc.c */
extern void InitProcGlobal(IPCKey key); extern void InitProcGlobal(IPCKey key);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: lock.h,v 1.14 1998/06/28 21:17:35 momjian Exp $ * $Id: lock.h,v 1.15 1998/06/30 02:33:33 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -36,26 +36,25 @@ typedef int MASK; ...@@ -36,26 +36,25 @@ typedef int MASK;
#define NLOCKS_PER_XACT 40 #define NLOCKS_PER_XACT 40
#define NLOCKENTS NLOCKS_PER_XACT*NBACKENDS #define NLOCKENTS NLOCKS_PER_XACT*NBACKENDS
typedef int LOCK_TYPE; typedef int LOCKMODE;
typedef int LOCKTYPE; typedef int LOCKMETHOD;
typedef int LockTableId;
/* MAX_LOCKTYPES cannot be larger than the bits in MASK */ /* MAX_LOCKMODES cannot be larger than the bits in MASK */
#define MAX_LOCKTYPES 6 #define MAX_LOCKMODES 6
/* /*
* MAX_TABLES corresponds to the number of spin locks allocated in * MAX_LOCK_METHODS corresponds to the number of spin locks allocated in
* CreateSpinLocks() or the number of shared memory locations allocated * CreateSpinLocks() or the number of shared memory locations allocated
* for lock table spin locks in the case of machines with TAS instructions. * for lock table spin locks in the case of machines with TAS instructions.
*/ */
#define MAX_TABLES 2 #define MAX_LOCK_METHODS 2
#define INVALID_TABLEID 0 #define INVALID_TABLEID 0
/*typedef struct LOCK LOCK; */ /*typedef struct LOCK LOCK; */
typedef struct ltag typedef struct LTAG
{ {
Oid relId; Oid relId;
Oid dbId; Oid dbId;
...@@ -67,31 +66,31 @@ typedef struct ltag ...@@ -67,31 +66,31 @@ typedef struct ltag
/* This is the control structure for a lock table. It /* This is the control structure for a lock table. It
* lives in shared memory: * lives in shared memory:
* *
* tableID -- the handle used by the lock table's clients to * lockmethod -- the handle used by the lock table's clients to
* refer to the table. * refer to the type of lock table being used.
* *
* nLockTypes -- number of lock types (READ,WRITE,etc) that * numLockModes -- number of lock types (READ,WRITE,etc) that
* are defined on this lock table * are defined on this lock table
* *
* conflictTab -- this is an array of bitmasks showing lock * conflictTab -- this is an array of bitmasks showing lock
* type conflicts. conflictTab[i] is a mask with the j-th bit * type conflicts. conflictTab[i] is a mask with the j-th bit
* turned on if lock types i and j conflict. * turned on if lock types i and j conflict.
* *
* prio -- each locktype has a priority, so, for example, waiting * prio -- each lockmode has a priority, so, for example, waiting
* writers can be given priority over readers (to avoid * writers can be given priority over readers (to avoid
* starvation). * starvation).
* *
* masterlock -- synchronizes access to the table * masterlock -- synchronizes access to the table
* *
*/ */
typedef struct lockctl typedef struct LOCKMETHODCTL
{ {
LockTableId tableId; LOCKMETHOD lockmethod;
int nLockTypes; int numLockModes;
int conflictTab[MAX_LOCKTYPES]; int conflictTab[MAX_LOCKMODES];
int prio[MAX_LOCKTYPES]; int prio[MAX_LOCKMODES];
SPINLOCK masterLock; SPINLOCK masterLock;
} LOCKCTL; } LOCKMETHODCTL;
/* /*
* lockHash -- hash table on lock Ids, * lockHash -- hash table on lock Ids,
...@@ -99,12 +98,12 @@ typedef struct lockctl ...@@ -99,12 +98,12 @@ typedef struct lockctl
* multiple processes are holding the lock * multiple processes are holding the lock
* ctl - control structure described above. * ctl - control structure described above.
*/ */
typedef struct ltable typedef struct LOCKMETHODTABLE
{ {
HTAB *lockHash; HTAB *lockHash;
HTAB *xidHash; HTAB *xidHash;
LOCKCTL *ctl; LOCKMETHODCTL *ctl;
} LOCKTAB; } LOCKMETHODTABLE;
/* ----------------------- /* -----------------------
* A transaction never conflicts with its own locks. Hence, if * A transaction never conflicts with its own locks. Hence, if
...@@ -148,7 +147,7 @@ typedef struct XIDLookupEnt ...@@ -148,7 +147,7 @@ typedef struct XIDLookupEnt
XIDTAG tag; XIDTAG tag;
/* data */ /* data */
int holders[MAX_LOCKTYPES]; int holders[MAX_LOCKMODES];
int nHolding; int nHolding;
SHM_QUEUE queue; SHM_QUEUE queue;
} XIDLookupEnt; } XIDLookupEnt;
...@@ -156,7 +155,7 @@ typedef struct XIDLookupEnt ...@@ -156,7 +155,7 @@ typedef struct XIDLookupEnt
#define XID_TAGSIZE (sizeof(XIDTAG)) #define XID_TAGSIZE (sizeof(XIDTAG))
/* originally in procq.h */ /* originally in procq.h */
typedef struct procQueue typedef struct PROC_QUEUE
{ {
SHM_QUEUE links; SHM_QUEUE links;
int size; int size;
...@@ -174,7 +173,7 @@ typedef struct procQueue ...@@ -174,7 +173,7 @@ typedef struct procQueue
* lock. * lock.
* nHolding -- total locks of all types. * nHolding -- total locks of all types.
*/ */
typedef struct Lock typedef struct LOCK
{ {
/* hash key */ /* hash key */
LOCKTAG tag; LOCKTAG tag;
...@@ -182,18 +181,18 @@ typedef struct Lock ...@@ -182,18 +181,18 @@ typedef struct Lock
/* data */ /* data */
int mask; int mask;
PROC_QUEUE waitProcs; PROC_QUEUE waitProcs;
int holders[MAX_LOCKTYPES]; int holders[MAX_LOCKMODES];
int nHolding; int nHolding;
int activeHolders[MAX_LOCKTYPES]; int activeHolders[MAX_LOCKMODES];
int nActive; int nActive;
} LOCK; } LOCK;
#define LockGetLock_nHolders(l) l->nHolders #define LockGetLock_nHolders(l) l->nHolders
#define LockDecrWaitHolders(lock, locktype) \ #define LockDecrWaitHolders(lock, lockmode) \
( \ ( \
lock->nHolding--, \ lock->nHolding--, \
lock->holders[locktype]-- \ lock->holders[lockmode]-- \
) )
#define LockLockTable() SpinAcquire(LockMgrLock); #define LockLockTable() SpinAcquire(LockMgrLock);
...@@ -206,16 +205,16 @@ extern SPINLOCK LockMgrLock; ...@@ -206,16 +205,16 @@ extern SPINLOCK LockMgrLock;
*/ */
extern void InitLocks(void); extern void InitLocks(void);
extern void LockDisable(int status); extern void LockDisable(int status);
extern LockTableId extern LOCKMETHOD
LockTableInit(char *tabName, MASK *conflictsP, int *prioP, LockMethodTableInit(char *tabName, MASK *conflictsP, int *prioP,
int ntypes); int numModes);
extern bool LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype); extern bool LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, LOCKMODE lockmode);
extern int extern int
LockResolveConflicts(LOCKTAB *ltable, LOCK *lock, LOCKTYPE locktype, LockResolveConflicts(LOCKMETHOD lockmethod, LOCK *lock, LOCKMODE lockmode,
TransactionId xid); TransactionId xid);
extern bool LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype); extern bool LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, LOCKMODE lockmode);
extern void GrantLock(LOCK *lock, LOCKTYPE locktype); extern void GrantLock(LOCK *lock, LOCKMODE lockmode);
extern bool LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue); extern bool LockReleaseAll(LOCKMETHOD lockmethod, SHM_QUEUE *lockQueue);
extern int LockShmemSize(void); extern int LockShmemSize(void);
extern bool LockingDisabled(void); extern bool LockingDisabled(void);
extern bool DeadLockCheck(SHM_QUEUE *lockQueue, LOCK *findlock, bool skip_check); extern bool DeadLockCheck(SHM_QUEUE *lockQueue, LOCK *findlock, bool skip_check);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: multilev.h,v 1.9 1998/06/28 21:17:36 momjian Exp $ * $Id: multilev.h,v 1.10 1998/06/30 02:33:33 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -43,16 +43,18 @@ typedef int PG_LOCK_LEVEL; ...@@ -43,16 +43,18 @@ typedef int PG_LOCK_LEVEL;
/* multi.c */ /* multi.c */
extern LockTableId MultiTableId; extern LOCKMETHOD MultiTableId;
extern LockTableId ShortTermTableId; #ifdef NOT_USED
extern LOCKMETHOD ShortTermTableId;
#endif
/* /*
* function prototypes * function prototypes
*/ */
extern LockTableId InitMultiLevelLocks(void); extern LOCKMETHOD InitMultiLevelLocks(void);
extern bool MultiLockReln(LockInfo linfo, LOCKTYPE locktype); extern bool MultiLockReln(LockInfo linfo, LOCKMODE lockmode);
extern bool MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype); extern bool MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode);
extern bool MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype); extern bool MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode);
extern bool MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype); extern bool MultiReleaseReln(LockInfo linfo, LOCKMODE lockmode);
#endif /* MULTILEV_H */ #endif /* MULTILEV_H */
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: proc.h,v 1.11 1998/02/26 04:43:31 momjian Exp $ * $Id: proc.h,v 1.12 1998/06/30 02:33:33 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -100,7 +100,7 @@ extern void ProcQueueInit(PROC_QUEUE *queue); ...@@ -100,7 +100,7 @@ extern void ProcQueueInit(PROC_QUEUE *queue);
extern int extern int
ProcSleep(PROC_QUEUE *queue, SPINLOCK spinlock, int token, ProcSleep(PROC_QUEUE *queue, SPINLOCK spinlock, int token,
int prio, LOCK *lock); int prio, LOCK *lock);
extern int ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock); extern int ProcLockWakeup(PROC_QUEUE *queue, LOCKMETHOD lockmethod, LOCK *lock);
extern void ProcAddLock(SHM_QUEUE *elem); extern void ProcAddLock(SHM_QUEUE *elem);
extern void ProcReleaseSpins(PROC *proc); extern void ProcReleaseSpins(PROC *proc);
extern void ProcFreeAllSemaphores(void); extern void ProcFreeAllSemaphores(void);
......
...@@ -25,13 +25,13 @@ structure, like ...@@ -25,13 +25,13 @@ structure, like
The query is then identified as a <I>Utility</I> function or a more The query is then identified as a <I>Utility</I> function or a more
complex query. A <I>Utility</I> query is processed by a complex query. A <I>Utility</I> query is processed by a
query-specific function in <A HREF="../../backend/commands"> query-specific function in <A HREF="../../backend/commands">
commands.</A> A complex query, like <B>SELECT, UPDATE,</B> and commands.</A> A complex query, like <CODE>SELECT, UPDATE,</CODE> and
<B>DELETE</B> requires much more handling. <CODE>DELETE</CODE> requires much more handling.
<P> <P>
The parser takes a complex query, and creates a The parser takes a complex query, and creates a
<A HREF="../../include/nodes/parsenodes.h">Query</A> structure that <A HREF="../../include/nodes/parsenodes.h">Query</A> structure that
contains all the elements used by complex queries. Query.qual holds the contains all the elements used by complex queries. Query.qual holds the
<B>WHERE</B> clause qualification, which is filled in by <CODE>WHERE</CODE> clause qualification, which is filled in by
<A HREF="../../backend/parser/parse_clause.c">transformWhereClause().</A> <A HREF="../../backend/parser/parse_clause.c">transformWhereClause().</A>
Each table referenced in the query is represented by a <A Each table referenced in the query is represented by a <A
HREF="../../include/nodes/parsenodes.h"> RangeTableEntry,</A> and they HREF="../../include/nodes/parsenodes.h"> RangeTableEntry,</A> and they
...@@ -39,19 +39,19 @@ are linked together to form the <I>range table</I> of the query, which is ...@@ -39,19 +39,19 @@ are linked together to form the <I>range table</I> of the query, which is
generated by <A HREF="../../backend/parser/parse_clause.c"> generated by <A HREF="../../backend/parser/parse_clause.c">
makeRangeTable().</A> Query.rtable holds the queries range table. makeRangeTable().</A> Query.rtable holds the queries range table.
<P> <P>
Certain queries, like <B>SELECT,</B> return columns of data. Other Certain queries, like <CODE>SELECT,</CODE> return columns of data. Other
queries, like <B>INSERT</B> and <B>UPDATE,</B> specify the columns queries, like <CODE>INSERT</CODE> and <CODE>UPDATE,</CODE> specify the columns
modified by the query. These column references are converted to <A modified by the query. These column references are converted to <A
HREF="../../include/nodes/primnodes.h">Resdom</A> entries, which are HREF="../../include/nodes/primnodes.h">Resdom</A> entries, which are
linked together to make up the <I>target list</I> of the query. The linked together to make up the <I>target list</I> of the query. The
target list is stored in Query.targetList, which is generated by target list is stored in Query.targetList, which is generated by
<A HREF="../../backend/parser/parse_target.c">transformTargetList().</A> <A HREF="../../backend/parser/parse_target.c">transformTargetList().</A>
<P> <P>
Other query elements, like aggregates(<B>SUM()</B>), <B>GROUP BY,</B> Other query elements, like aggregates(<CODE>SUM()</CODE>), <CODE>GROUP BY,</CODE>
<B>ORDER BY</B> are also stored in their own Query fields. <CODE>ORDER BY</CODE> are also stored in their own Query fields.
<P> <P>
The next step is for the Query to be modified by any <B>VIEWS</B> or The next step is for the Query to be modified by any <CODE>VIEWS</CODE> or
<B>RULES</B> that may apply to the query. This is performed by the <A <CODE>RULES</CODE> that may apply to the query. This is performed by the <A
HREF="../../backend/rewrite">rewrite</A> system. HREF="../../backend/rewrite">rewrite</A> system.
<P> <P>
The <A HREF="../../backend/optimizer">optimizer</A> takes the Query The <A HREF="../../backend/optimizer">optimizer</A> takes the Query
...@@ -60,7 +60,7 @@ HREF="../..//include/nodes/plannodes.h">Plan,</A> which contains the ...@@ -60,7 +60,7 @@ HREF="../..//include/nodes/plannodes.h">Plan,</A> which contains the
operations to be performed to execute the query. The <A operations to be performed to execute the query. The <A
HREF="../../backend/optimizer/path">path</A> module determines the best HREF="../../backend/optimizer/path">path</A> module determines the best
table join order and join type of each table in the RangeTable, using table join order and join type of each table in the RangeTable, using
Query.qual(<B>WHERE</B> clause) to consider optimal index usage. Query.qual(<CODE>WHERE</CODE> clause) to consider optimal index usage.
<P> <P>
The Plan is then passed to the <A The Plan is then passed to the <A
HREF="../../backend/executor">executor</A> for execution, and the result HREF="../../backend/executor">executor</A> for execution, and the result
...@@ -81,15 +81,25 @@ data/index buffer cache block ...@@ -81,15 +81,25 @@ data/index buffer cache block
<LI>Shared Buf Lookup Table - lookup of buffer cache block address using <LI>Shared Buf Lookup Table - lookup of buffer cache block address using
table name and block number(<A HREF="../../include/storage/buf_internals.h"> table name and block number(<A HREF="../../include/storage/buf_internals.h">
BufferTag</A>) BufferTag</A>)
<LI><A HREF="../../include/storage/lock.h">LockTable (ctl)</A> - lock table <LI>MultiLevelLockTable (ctl) - <A
structure, specifiying table, lock types, and backends holding or HREF="../../include/storage/lock.h">LOCKCTL</A> control structure for
waiting on lock each locking method. Currently, only multi-level locking is used.
<LI>LockTable (lock hash) - lookup of LockTable structures using relation, <LI>MultiLevelLockTable (lock hash) - the <A
database object ids HREF="../../include/storage/lock.h">LOCK</A> structure, looked up using
<LI>LockTable (xid hash) - lookup of LockTable structures using relation, database object ids(<A
transaction id, LockTable address HREF="../../include/storage/lock.h">LOCKTAG)</A>. The lock table structure contains the
lock modes(read, write) and circular linked list of backends (<A
HREF="../../include/storage/proc.h">PROC</A> structure pointers) waiting
on the lock.
<LI>MultiLevelLockTable (xid hash) - lookup of LOCK structure address
using transaction id, LOCK address. It is used to quickly check if the
current transaction already has any locks on a table, rather than having
to search through all the held locks. It also stores the modes
(read/write) of the locks held by the current transaction. The returned
<A HREF="../../include/storage/lock.h">XIDLookupEnt</A> structure also
contains a pointer to the backend's PROC.lockQueue.
<LI><A HREF="../../include/storage/proc.h">Proc Header</A> - information <LI><A HREF="../../include/storage/proc.h">Proc Header</A> - information
about each backend, including locks held/waiting, indexed by process id about each backend, including locks held/waiting, indexed by process id
</UL> </UL>
Each data structure is created by calling <A Each data structure is created by calling <A
HREF="../../backend/storage/ipc/shmem.c">ShmemInitStruct(),</A> and HREF="../../backend/storage/ipc/shmem.c">ShmemInitStruct(),</A> and
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment