diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index d4162387b6..4b83c9c0d1 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.31 1998/06/28 21:17:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.32 1998/06/30 02:33:31 momjian Exp $ * * NOTES * Outside modules can create a lock table and acquire/release @@ -18,7 +18,7 @@ * * Interface: * - * LockAcquire(), LockRelease(), LockTableInit(). + * LockAcquire(), LockRelease(), LockMethodTableInit(). * * LockReplace() is called only within this module and by the * lkchain module. It releases a lock without looking @@ -51,8 +51,7 @@ #include "access/transam.h" static int -WaitOnLock(LOCKTAB *ltable, LockTableId tableId, LOCK *lock, - LOCKTYPE locktype); +WaitOnLock(LOCKMETHOD lockmethod, LOCK *lock, LOCKMODE lockmode); /*#define LOCK_MGR_DEBUG*/ @@ -134,8 +133,8 @@ SPINLOCK LockMgrLock; /* in Shmem or created in /* This is to simplify/speed up some bit arithmetic */ -static MASK BITS_OFF[MAX_LOCKTYPES]; -static MASK BITS_ON[MAX_LOCKTYPES]; +static MASK BITS_OFF[MAX_LOCKMODES]; +static MASK BITS_ON[MAX_LOCKMODES]; /* ----------------- * XXX Want to move this to this file @@ -144,16 +143,12 @@ static MASK BITS_ON[MAX_LOCKTYPES]; static bool LockingIsDisabled; /* ------------------- - * map from tableId to the lock table structure + * map from lockmethod to the lock table structure * ------------------- */ -static LOCKTAB *AllTables[MAX_TABLES]; +static LOCKMETHODTABLE *LockMethodTable[MAX_LOCK_METHODS]; -/* ------------------- - * no zero-th table - * ------------------- - */ -static int NumTables; +static int NumLockMethods; /* ------------------- * InitLocks -- Init the lock module. Create a private data @@ -168,10 +163,10 @@ InitLocks() bit = 1; /* ------------------- - * remember 0th locktype is invalid + * remember 0th lockmode is invalid * ------------------- */ - for (i = 0; i < MAX_LOCKTYPES; i++, bit <<= 1) + for (i = 0; i < MAX_LOCKMODES; i++, bit <<= 1) { BITS_ON[i] = bit; BITS_OFF[i] = ~bit; @@ -190,30 +185,30 @@ LockDisable(int status) /* - * LockTypeInit -- initialize the lock table's lock type + * LockMethodInit -- initialize the lock table's lock type * structures * * Notes: just copying. Should only be called once. */ static void -LockTypeInit(LOCKTAB *ltable, +LockMethodInit(LOCKMETHODTABLE *lockMethodTable, MASK *conflictsP, int *prioP, - int ntypes) + int numModes) { int i; - ltable->ctl->nLockTypes = ntypes; - ntypes++; - for (i = 0; i < ntypes; i++, prioP++, conflictsP++) + lockMethodTable->ctl->numLockModes = numModes; + numModes++; + for (i = 0; i < numModes; i++, prioP++, conflictsP++) { - ltable->ctl->conflictTab[i] = *conflictsP; - ltable->ctl->prio[i] = *prioP; + lockMethodTable->ctl->conflictTab[i] = *conflictsP; + lockMethodTable->ctl->prio[i] = *prioP; } } /* - * LockTableInit -- initialize a lock table structure + * LockMethodTableInit -- initialize a lock table structure * * Notes: * (a) a lock table has four separate entries in the shmem index @@ -222,23 +217,23 @@ LockTypeInit(LOCKTAB *ltable, * is wasteful, in this case, but not much space is involved. * */ -LockTableId -LockTableInit(char *tabName, +LOCKMETHOD +LockMethodTableInit(char *tabName, MASK *conflictsP, int *prioP, - int ntypes) + int numModes) { - LOCKTAB *ltable; + LOCKMETHODTABLE *lockMethodTable; char *shmemName; HASHCTL info; int hash_flags; bool found; int status = TRUE; - if (ntypes > MAX_LOCKTYPES) + if (numModes > MAX_LOCKMODES) { - elog(NOTICE, "LockTableInit: too many lock types %d greater than %d", - ntypes, MAX_LOCKTYPES); + elog(NOTICE, "LockMethodTableInit: too many lock types %d greater than %d", + numModes, MAX_LOCKMODES); return (INVALID_TABLEID); } @@ -246,15 +241,15 @@ LockTableInit(char *tabName, shmemName = (char *) palloc((unsigned) (strlen(tabName) + 32)); if (!shmemName) { - elog(NOTICE, "LockTableInit: couldn't malloc string %s \n", tabName); + elog(NOTICE, "LockMethodTableInit: couldn't malloc string %s \n", tabName); return (INVALID_TABLEID); } /* each lock table has a non-shared header */ - ltable = (LOCKTAB *) palloc((unsigned) sizeof(LOCKTAB)); - if (!ltable) + lockMethodTable = (LOCKMETHODTABLE *) palloc((unsigned) sizeof(LOCKMETHODTABLE)); + if (!lockMethodTable) { - elog(NOTICE, "LockTableInit: couldn't malloc lock table %s\n", tabName); + elog(NOTICE, "LockMethodTableInit: couldn't malloc lock table %s\n", tabName); pfree(shmemName); return (INVALID_TABLEID); } @@ -272,16 +267,20 @@ LockTableInit(char *tabName, * ----------------------- */ sprintf(shmemName, "%s (ctl)", tabName); - ltable->ctl = (LOCKCTL *) - ShmemInitStruct(shmemName, (unsigned) sizeof(LOCKCTL), &found); + lockMethodTable->ctl = (LOCKMETHODCTL *) + ShmemInitStruct(shmemName, (unsigned) sizeof(LOCKMETHODCTL), &found); - if (!ltable->ctl) + if (!lockMethodTable->ctl) { - elog(FATAL, "LockTableInit: couldn't initialize %s", tabName); + elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName); status = FALSE; } - NumTables = 1; + /* ------------------- + * no zero-th table + * ------------------- + */ + NumLockMethods = 1; /* ---------------- * we're first - initialize @@ -289,18 +288,18 @@ LockTableInit(char *tabName, */ if (!found) { - MemSet(ltable->ctl, 0, sizeof(LOCKCTL)); - ltable->ctl->masterLock = LockMgrLock; - ltable->ctl->tableId = NumTables; + MemSet(lockMethodTable->ctl, 0, sizeof(LOCKMETHODCTL)); + lockMethodTable->ctl->masterLock = LockMgrLock; + lockMethodTable->ctl->lockmethod = NumLockMethods; } /* -------------------- - * other modules refer to the lock table by a tableId + * other modules refer to the lock table by a lockmethod * -------------------- */ - AllTables[NumTables] = ltable; - NumTables++; - Assert(NumTables <= MAX_TABLES); + LockMethodTable[NumLockMethods] = lockMethodTable; + NumLockMethods++; + Assert(NumLockMethods <= MAX_LOCK_METHODS); /* ---------------------- * allocate a hash table for the lock tags. This is used @@ -313,14 +312,14 @@ LockTableInit(char *tabName, hash_flags = (HASH_ELEM | HASH_FUNCTION); sprintf(shmemName, "%s (lock hash)", tabName); - ltable->lockHash = (HTAB *) ShmemInitHash(shmemName, + lockMethodTable->lockHash = (HTAB *) ShmemInitHash(shmemName, INIT_TABLE_SIZE, MAX_TABLE_SIZE, &info, hash_flags); - Assert(ltable->lockHash->hash == tag_hash); - if (!ltable->lockHash) + Assert(lockMethodTable->lockHash->hash == tag_hash); + if (!lockMethodTable->lockHash) { - elog(FATAL, "LockTableInit: couldn't initialize %s", tabName); + elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName); status = FALSE; } @@ -335,31 +334,31 @@ LockTableInit(char *tabName, hash_flags = (HASH_ELEM | HASH_FUNCTION); sprintf(shmemName, "%s (xid hash)", tabName); - ltable->xidHash = (HTAB *) ShmemInitHash(shmemName, + lockMethodTable->xidHash = (HTAB *) ShmemInitHash(shmemName, INIT_TABLE_SIZE, MAX_TABLE_SIZE, &info, hash_flags); - if (!ltable->xidHash) + if (!lockMethodTable->xidHash) { - elog(FATAL, "LockTableInit: couldn't initialize %s", tabName); + elog(FATAL, "LockMethodTableInit: couldn't initialize %s", tabName); status = FALSE; } /* init ctl data structures */ - LockTypeInit(ltable, conflictsP, prioP, ntypes); + LockMethodInit(lockMethodTable, conflictsP, prioP, numModes); SpinRelease(LockMgrLock); pfree(shmemName); if (status) - return (ltable->ctl->tableId); + return (lockMethodTable->ctl->lockmethod); else return (INVALID_TABLEID); } /* - * LockTableRename -- allocate another tableId to the same + * LockMethodTableRename -- allocate another lockmethod to the same * lock table. * * NOTES: Both the lock module and the lock chain (lchain.c) @@ -367,28 +366,27 @@ LockTableInit(char *tabName, * kinds of locks. Short term and long term locks look * the same to the lock table, but are handled differently * by the lock chain manager. This function allows the - * client to use different tableIds when acquiring/releasing + * client to use different lockmethods when acquiring/releasing * short term and long term locks. */ #ifdef NOT_USED -LockTableId -LockTableRename(LockTableId tableId) +LOCKMETHOD +LockMethodTableRename(LOCKMETHOD lockmethod) { - LockTableId newTableId; + LOCKMETHOD newLockMethod; - if (NumTables >= MAX_TABLES) + if (NumLockMethods >= MAX_LOCK_METHODS) return (INVALID_TABLEID); - if (AllTables[tableId] == INVALID_TABLEID) + if (LockMethodTable[lockmethod] == INVALID_TABLEID) return (INVALID_TABLEID); - /* other modules refer to the lock table by a tableId */ - newTableId = NumTables; - NumTables++; + /* other modules refer to the lock table by a lockmethod */ + newLockMethod = NumLockMethods; + NumLockMethods++; - AllTables[newTableId] = AllTables[tableId]; - return (newTableId); + LockMethodTable[newLockMethod] = LockMethodTable[lockmethod]; + return (newLockMethod); } - #endif /* @@ -423,13 +421,13 @@ LockTableRename(LockTableId tableId) * acquired if already held by another process. They must be * released explicitly by the application but they are released * automatically when a backend terminates. - * They are indicated by a dummy tableId 0 which doesn't have + * They are indicated by a dummy lockmethod 0 which doesn't have * any table allocated but uses the normal lock table, and are * distinguished from normal locks for the following differences: * * normal lock user lock * - * tableId 1 0 + * lockmethod 1 0 * tag.relId rel oid 0 * tag.ItemPointerData.ip_blkid block id lock id2 * tag.ItemPointerData.ip_posid tuple offset lock id1 @@ -437,7 +435,7 @@ LockTableRename(LockTableId tableId) * xid.xid current xid 0 * persistence transaction user or backend * - * The locktype parameter can have the same values for normal locks + * The lockmode parameter can have the same values for normal locks * although probably only WRITE_LOCK can have some practical use. * * DZ - 4 Oct 1996 @@ -445,7 +443,7 @@ LockTableRename(LockTableId tableId) */ bool -LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) +LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, LOCKMODE lockmode) { XIDLookupEnt *result, item; @@ -453,50 +451,50 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) bool found; LOCK *lock = NULL; SPINLOCK masterLock; - LOCKTAB *ltable; + LOCKMETHODTABLE *lockMethodTable; int status; TransactionId myXid; #ifdef USER_LOCKS int is_user_lock; - is_user_lock = (tableId == 0); + is_user_lock = (lockmethod == 0); if (is_user_lock) { - tableId = 1; + lockmethod = 1; #ifdef USER_LOCKS_DEBUG elog(NOTICE, "LockAcquire: user lock tag [%u,%u] %d", - lockName->tupleId.ip_posid, - ((lockName->tupleId.ip_blkid.bi_hi << 16) + - lockName->tupleId.ip_blkid.bi_lo), - locktype); + locktag->tupleId.ip_posid, + ((locktag->tupleId.ip_blkid.bi_hi << 16) + + locktag->tupleId.ip_blkid.bi_lo), + lockmode); #endif } #endif - Assert(tableId < NumTables); - ltable = AllTables[tableId]; - if (!ltable) + Assert(lockmethod < NumLockMethods); + lockMethodTable = LockMethodTable[lockmethod]; + if (!lockMethodTable) { - elog(NOTICE, "LockAcquire: bad lock table %d", tableId); + elog(NOTICE, "LockAcquire: bad lock table %d", lockmethod); return (FALSE); } if (LockingIsDisabled) return (TRUE); - LOCK_PRINT("Acquire", lockName, locktype); - masterLock = ltable->ctl->masterLock; + LOCK_PRINT("Acquire", locktag, lockmode); + masterLock = lockMethodTable->ctl->masterLock; SpinAcquire(masterLock); - Assert(ltable->lockHash->hash == tag_hash); - lock = (LOCK *) hash_search(ltable->lockHash, (Pointer) lockName, HASH_ENTER, &found); + Assert(lockMethodTable->lockHash->hash == tag_hash); + lock = (LOCK *) hash_search(lockMethodTable->lockHash, (Pointer) locktag, HASH_ENTER, &found); if (!lock) { SpinRelease(masterLock); - elog(FATAL, "LockAcquire: lock table %d is corrupted", tableId); + elog(FATAL, "LockAcquire: lock table %d is corrupted", lockmethod); return (FALSE); } @@ -508,13 +506,13 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) { lock->mask = 0; ProcQueueInit(&(lock->waitProcs)); - MemSet((char *) lock->holders, 0, sizeof(int) * MAX_LOCKTYPES); - MemSet((char *) lock->activeHolders, 0, sizeof(int) * MAX_LOCKTYPES); + MemSet((char *) lock->holders, 0, sizeof(int) * MAX_LOCKMODES); + MemSet((char *) lock->activeHolders, 0, sizeof(int) * MAX_LOCKMODES); lock->nHolding = 0; lock->nActive = 0; Assert(BlockIdEquals(&(lock->tag.tupleId.ip_blkid), - &(lockName->tupleId.ip_blkid))); + &(locktag->tupleId.ip_blkid))); } @@ -523,7 +521,7 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * locks at end of transaction. * ------------------ */ - xidTable = ltable->xidHash; + xidTable = lockMethodTable->xidHash; myXid = GetCurrentTransactionId(); /* ------------------ @@ -561,7 +559,7 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) XID_PRINT("LockAcquire: queueing XidEnt", result); ProcAddLock(&result->queue); result->nHolding = 0; - MemSet((char *) result->holders, 0, sizeof(int) * MAX_LOCKTYPES); + MemSet((char *) result->holders, 0, sizeof(int) * MAX_LOCKMODES); } /* ---------------- @@ -571,7 +569,7 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * ---------------- */ lock->nHolding++; - lock->holders[locktype]++; + lock->holders[lockmode]++; /* -------------------- * If I'm the only one holding a lock, then there @@ -582,19 +580,19 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) */ if (result->nHolding == lock->nActive) { - result->holders[locktype]++; + result->holders[lockmode]++; result->nHolding++; - GrantLock(lock, locktype); + GrantLock(lock, lockmode); SpinRelease(masterLock); return (TRUE); } Assert(result->nHolding <= lock->nActive); - status = LockResolveConflicts(ltable, lock, locktype, myXid); + status = LockResolveConflicts(lockmethod, lock, lockmode, myXid); if (status == STATUS_OK) - GrantLock(lock, locktype); + GrantLock(lock, lockmode); else if (status == STATUS_FOUND) { #ifdef USER_LOCKS @@ -611,7 +609,7 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) hash_search(xidTable, (Pointer) &item, HASH_REMOVE, &found); } lock->nHolding--; - lock->holders[locktype]--; + lock->holders[lockmode]--; SpinRelease(masterLock); #ifdef USER_LOCKS_DEBUG elog(NOTICE, "LockAcquire: user lock failed"); @@ -619,7 +617,7 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) return (FALSE); } #endif - status = WaitOnLock(ltable, tableId, lock, locktype); + status = WaitOnLock(lockmethod, lock, lockmode); XID_PRINT("Someone granted me the lock", result); } @@ -645,23 +643,23 @@ LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * ---------------------------- */ int -LockResolveConflicts(LOCKTAB *ltable, +LockResolveConflicts(LOCKMETHOD lockmethod, LOCK *lock, - LOCKTYPE locktype, + LOCKMODE lockmode, TransactionId xid) { XIDLookupEnt *result, item; int *myHolders; - int nLockTypes; + int numLockModes; HTAB *xidTable; bool found; int bitmask; int i, tmpMask; - nLockTypes = ltable->ctl->nLockTypes; - xidTable = ltable->xidHash; + numLockModes = LockMethodTable[lockmethod]->ctl->numLockModes; + xidTable = LockMethodTable[lockmethod]->xidHash; /* --------------------- * read my own statistics from the xid table. If there @@ -693,7 +691,7 @@ LockResolveConflicts(LOCKTAB *ltable, * the lock stats. * --------------- */ - MemSet(result->holders, 0, nLockTypes * sizeof(*(lock->holders))); + MemSet(result->holders, 0, numLockModes * sizeof(*(lock->holders))); result->nHolding = 0; } @@ -703,7 +701,7 @@ LockResolveConflicts(LOCKTAB *ltable, * do not continue and share the lock, even if we can. bjm * ------------------------ */ - int myprio = ltable->ctl->prio[locktype]; + int myprio = LockMethodTable[lockmethod]->ctl->prio[lockmode]; PROC_QUEUE *waitQueue = &(lock->waitProcs); PROC *topproc = (PROC *) MAKE_PTR(waitQueue->links.prev); @@ -716,15 +714,15 @@ LockResolveConflicts(LOCKTAB *ltable, * with mine, then I get the lock. * * Checking for conflict: lock->mask represents the types of - * currently held locks. conflictTable[locktype] has a bit + * currently held locks. conflictTable[lockmode] has a bit * set for each type of lock that conflicts with mine. Bitwise * compare tells if there is a conflict. * ---------------------------- */ - if (!(ltable->ctl->conflictTab[locktype] & lock->mask)) + if (!(LockMethodTable[lockmethod]->ctl->conflictTab[lockmode] & lock->mask)) { - result->holders[locktype]++; + result->holders[lockmode]++; result->nHolding++; XID_PRINT("Conflict Resolved: updated xid entry stats", result); @@ -740,7 +738,7 @@ LockResolveConflicts(LOCKTAB *ltable, */ bitmask = 0; tmpMask = 2; - for (i = 1; i <= nLockTypes; i++, tmpMask <<= 1) + for (i = 1; i <= numLockModes; i++, tmpMask <<= 1) { if (lock->activeHolders[i] != myHolders[i]) bitmask |= tmpMask; @@ -753,12 +751,12 @@ LockResolveConflicts(LOCKTAB *ltable, * conflict and I have to sleep. * ------------------------ */ - if (!(ltable->ctl->conflictTab[locktype] & bitmask)) + if (!(LockMethodTable[lockmethod]->ctl->conflictTab[lockmode] & bitmask)) { /* no conflict. Get the lock and go on */ - result->holders[locktype]++; + result->holders[lockmode]++; result->nHolding++; XID_PRINT("Conflict Resolved: updated xid entry stats", result); @@ -771,11 +769,13 @@ LockResolveConflicts(LOCKTAB *ltable, } static int -WaitOnLock(LOCKTAB *ltable, LockTableId tableId, LOCK *lock, LOCKTYPE locktype) +WaitOnLock(LOCKMETHOD lockmethod, LOCK *lock, LOCKMODE lockmode) { PROC_QUEUE *waitQueue = &(lock->waitProcs); + LOCKMETHODTABLE *lockMethodTable = LockMethodTable[lockmethod]; + int prio = lockMethodTable->ctl->prio[lockmode]; - int prio = ltable->ctl->prio[locktype]; + Assert(lockmethod < NumLockMethods); /* * the waitqueue is ordered by priority. I insert myself according to @@ -785,10 +785,10 @@ WaitOnLock(LOCKTAB *ltable, LockTableId tableId, LOCK *lock, LOCKTYPE locktype) * synchronization for this queue. That will not be true if/when * people can be deleted from the queue by a SIGINT or something. */ - LOCK_DUMP_AUX("WaitOnLock: sleeping on lock", lock, locktype); + LOCK_DUMP_AUX("WaitOnLock: sleeping on lock", lock, lockmode); if (ProcSleep(waitQueue, - ltable->ctl->masterLock, - locktype, + lockMethodTable->ctl->masterLock, + lockmode, prio, lock) != NO_ERROR) { @@ -799,18 +799,18 @@ WaitOnLock(LOCKTAB *ltable, LockTableId tableId, LOCK *lock, LOCKTYPE locktype) * ------------------- */ lock->nHolding--; - lock->holders[locktype]--; - LOCK_DUMP_AUX("WaitOnLock: aborting on lock", lock, locktype); - SpinRelease(ltable->ctl->masterLock); + lock->holders[lockmode]--; + LOCK_DUMP_AUX("WaitOnLock: aborting on lock", lock, lockmode); + SpinRelease(lockMethodTable->ctl->masterLock); elog(ERROR, "WaitOnLock: error on wakeup - Aborting this transaction"); } - LOCK_DUMP_AUX("WaitOnLock: wakeup on lock", lock, locktype); + LOCK_DUMP_AUX("WaitOnLock: wakeup on lock", lock, lockmode); return (STATUS_OK); } /* - * LockRelease -- look up 'lockName' in lock table 'tableId' and + * LockRelease -- look up 'locktag' in lock table 'lockmethod' and * release it. * * Side Effects: if the lock no longer conflicts with the highest @@ -820,12 +820,12 @@ WaitOnLock(LOCKTAB *ltable, LockTableId tableId, LOCK *lock, LOCKTYPE locktype) * come along and request the lock). */ bool -LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) +LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, LOCKMODE lockmode) { LOCK *lock = NULL; SPINLOCK masterLock; bool found; - LOCKTAB *ltable; + LOCKMETHODTABLE *lockMethodTable; XIDLookupEnt *result, item; HTAB *xidTable; @@ -834,41 +834,41 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) #ifdef USER_LOCKS int is_user_lock; - is_user_lock = (tableId == 0); + is_user_lock = (lockmethod == 0); if (is_user_lock) { - tableId = 1; + lockmethod = 1; #ifdef USER_LOCKS_DEBUG elog(NOTICE, "LockRelease: user lock tag [%u,%u] %d", - lockName->tupleId.ip_posid, - ((lockName->tupleId.ip_blkid.bi_hi << 16) + - lockName->tupleId.ip_blkid.bi_lo), - locktype); + locktag->tupleId.ip_posid, + ((locktag->tupleId.ip_blkid.bi_hi << 16) + + locktag->tupleId.ip_blkid.bi_lo), + lockmode); #endif } #endif - Assert(tableId < NumTables); - ltable = AllTables[tableId]; - if (!ltable) + Assert(lockmethod < NumLockMethods); + lockMethodTable = LockMethodTable[lockmethod]; + if (!lockMethodTable) { - elog(NOTICE, "ltable is null in LockRelease"); + elog(NOTICE, "lockMethodTable is null in LockRelease"); return (FALSE); } if (LockingIsDisabled) return (TRUE); - LOCK_PRINT("Release", lockName, locktype); + LOCK_PRINT("Release", locktag, lockmode); - masterLock = ltable->ctl->masterLock; - xidTable = ltable->xidHash; + masterLock = lockMethodTable->ctl->masterLock; + xidTable = lockMethodTable->xidHash; SpinAcquire(masterLock); - Assert(ltable->lockHash->hash == tag_hash); + Assert(lockMethodTable->lockHash->hash == tag_hash); lock = (LOCK *) - hash_search(ltable->lockHash, (Pointer) lockName, HASH_FIND_SAVE, &found); + hash_search(lockMethodTable->lockHash, (Pointer) locktag, HASH_FIND_SAVE, &found); #ifdef USER_LOCKS @@ -919,9 +919,9 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * fix the general lock stats */ lock->nHolding--; - lock->holders[locktype]--; + lock->holders[lockmode]--; lock->nActive--; - lock->activeHolders[locktype]--; + lock->activeHolders[lockmode]--; Assert(lock->nActive >= 0); @@ -933,8 +933,8 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * Delete it from the lock table. * ------------------ */ - Assert(ltable->lockHash->hash == tag_hash); - lock = (LOCK *) hash_search(ltable->lockHash, + Assert(lockMethodTable->lockHash->hash == tag_hash); + lock = (LOCK *) hash_search(lockMethodTable->lockHash, (Pointer) &(lock->tag), HASH_REMOVE_SAVED, &found); @@ -992,7 +992,7 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * now check to see if I have any private locks. If I do, decrement * the counts associated with them. */ - result->holders[locktype]--; + result->holders[lockmode]--; result->nHolding--; XID_PRINT("LockRelease updated xid stats", result); @@ -1038,9 +1038,9 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * fix the general lock stats */ lock->nHolding--; - lock->holders[locktype]--; + lock->holders[lockmode]--; lock->nActive--; - lock->activeHolders[locktype]--; + lock->activeHolders[lockmode]--; Assert(lock->nActive >= 0); @@ -1052,8 +1052,8 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * Delete it from the lock table. * ------------------ */ - Assert(ltable->lockHash->hash == tag_hash); - lock = (LOCK *) hash_search(ltable->lockHash, + Assert(lockMethodTable->lockHash->hash == tag_hash); + lock = (LOCK *) hash_search(lockMethodTable->lockHash, (Pointer) &(lock->tag), HASH_REMOVE, &found); @@ -1069,10 +1069,10 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * with the remaining locks. * -------------------------- */ - if (!(lock->activeHolders[locktype])) + if (!(lock->activeHolders[lockmode])) { /* change the conflict mask. No more of this lock type. */ - lock->mask &= BITS_OFF[locktype]; + lock->mask &= BITS_OFF[lockmode]; } if (wakeupNeeded) @@ -1083,7 +1083,7 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) * himself. * -------------------------- */ - ProcLockWakeup(&(lock->waitProcs), (char *) ltable, (char *) lock); + ProcLockWakeup(&(lock->waitProcs), lockmethod, lock); } SpinRelease(masterLock); @@ -1091,15 +1091,15 @@ LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype) } /* - * GrantLock -- udpate the lock data structure to show + * GrantLock -- update the lock data structure to show * the new lock holder. */ void -GrantLock(LOCK *lock, LOCKTYPE locktype) +GrantLock(LOCK *lock, LOCKMODE lockmode) { lock->nActive++; - lock->activeHolders[locktype]++; - lock->mask |= BITS_ON[locktype]; + lock->activeHolders[lockmode]++; + lock->mask |= BITS_ON[lockmode]; } #ifdef USER_LOCKS @@ -1110,12 +1110,12 @@ GrantLock(LOCK *lock, LOCKTYPE locktype) * same queue of user locks which can't be removed from the * normal lock queue at the end of a transaction. They must * however be removed when the backend exits. - * A dummy tableId 0 is used to indicate that we are releasing + * A dummy lockmethod 0 is used to indicate that we are releasing * the user locks, from the code added to ProcKill(). */ #endif bool -LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue) +LockReleaseAll(LOCKMETHOD lockmethod, SHM_QUEUE *lockQueue) { PROC_QUEUE *waitQueue; int done; @@ -1123,9 +1123,9 @@ LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue) XIDLookupEnt *tmp = NULL; SHMEM_OFFSET end = MAKE_OFFSET(lockQueue); SPINLOCK masterLock; - LOCKTAB *ltable; + LOCKMETHODTABLE *lockMethodTable; int i, - nLockTypes; + numLockModes; LOCK *lock; bool found; @@ -1134,21 +1134,21 @@ LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue) count, nskip; - is_user_lock_table = (tableId == 0); + is_user_lock_table = (lockmethod == 0); #ifdef USER_LOCKS_DEBUG - elog(NOTICE, "LockReleaseAll: tableId=%d, pid=%d", tableId, MyProcPid); + elog(NOTICE, "LockReleaseAll: lockmethod=%d, pid=%d", lockmethod, MyProcPid); #endif if (is_user_lock_table) - tableId = 1; + lockmethod = 1; #endif - Assert(tableId < NumTables); - ltable = AllTables[tableId]; - if (!ltable) + Assert(lockmethod < NumLockMethods); + lockMethodTable = LockMethodTable[lockmethod]; + if (!lockMethodTable) return (FALSE); - nLockTypes = ltable->ctl->nLockTypes; - masterLock = ltable->ctl->masterLock; + numLockModes = lockMethodTable->ctl->numLockModes; + masterLock = lockMethodTable->ctl->masterLock; if (SHMQueueEmpty(lockQueue)) return TRUE; @@ -1254,7 +1254,7 @@ LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue) lock->nHolding -= xidLook->nHolding; lock->nActive -= xidLook->nHolding; Assert(lock->nActive >= 0); - for (i = 1; i <= nLockTypes; i++) + for (i = 1; i <= numLockModes; i++) { lock->holders[i] -= xidLook->holders[i]; lock->activeHolders[i] -= xidLook->holders[i]; @@ -1278,7 +1278,7 @@ LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue) #ifdef USER_LOCKS SHMQueueDelete(&xidLook->queue); #endif - if ((!hash_search(ltable->xidHash, (Pointer) xidLook, HASH_REMOVE, &found)) + if ((!hash_search(lockMethodTable->xidHash, (Pointer) xidLook, HASH_REMOVE, &found)) || !found) { SpinRelease(masterLock); @@ -1294,9 +1294,9 @@ LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue) * -------------------- */ - Assert(ltable->lockHash->hash == tag_hash); + Assert(lockMethodTable->lockHash->hash == tag_hash); lock = (LOCK *) - hash_search(ltable->lockHash, (Pointer) &(lock->tag), HASH_REMOVE, &found); + hash_search(lockMethodTable->lockHash, (Pointer) &(lock->tag), HASH_REMOVE, &found); if ((!lock) || (!found)) { SpinRelease(masterLock); @@ -1313,7 +1313,7 @@ LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue) * -------------------- */ waitQueue = &(lock->waitProcs); - ProcLockWakeup(waitQueue, (char *) ltable, (char *) lock); + ProcLockWakeup(waitQueue, lockmethod, lock); } #ifdef USER_LOCKS @@ -1352,7 +1352,7 @@ LockShmemSize() nXidSegs = 1 << (int) my_log2((nLockBuckets - 1) / DEF_SEGSIZE + 1); size += MAXALIGN(NBACKENDS * sizeof(PROC)); /* each MyProc */ - size += MAXALIGN(NBACKENDS * sizeof(LOCKCTL)); /* each ltable->ctl */ + size += MAXALIGN(NBACKENDS * sizeof(LOCKMETHODCTL)); /* each lockMethodTable->ctl */ size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */ size += MAXALIGN(my_log2(NLOCKENTS) * sizeof(void *)); @@ -1404,7 +1404,7 @@ DeadLockCheck(SHM_QUEUE *lockQueue, LOCK *findlock, bool skip_check) SHMEM_OFFSET end = MAKE_OFFSET(lockQueue); LOCK *lock; - LOCKTAB *ltable; + LOCKMETHODTABLE *lockMethodTable; XIDLookupEnt *result, item; HTAB *xidTable; @@ -1420,8 +1420,8 @@ DeadLockCheck(SHM_QUEUE *lockQueue, LOCK *findlock, bool skip_check) checked_procs[0] = MyProc; nprocs = 1; - ltable = AllTables[1]; - xidTable = ltable->xidHash; + lockMethodTable = LockMethodTable[1]; + xidTable = lockMethodTable->xidHash; MemSet(&item, 0, XID_TAGSIZE); TransactionIdStore(MyProc->xid, &item.tag.xid); @@ -1499,8 +1499,8 @@ DeadLockCheck(SHM_QUEUE *lockQueue, LOCK *findlock, bool skip_check) Assert(skip_check); Assert(MyProc->prio == 2); - ltable = AllTables[1]; - xidTable = ltable->xidHash; + lockMethodTable = LockMethodTable[1]; + xidTable = lockMethodTable->xidHash; MemSet(&item, 0, XID_TAGSIZE); TransactionIdStore(proc->xid, &item.tag.xid); @@ -1575,12 +1575,12 @@ DumpLocks() XIDLookupEnt *tmp = NULL; SHMEM_OFFSET end; SPINLOCK masterLock; - int nLockTypes; + int numLockModes; LOCK *lock; count; - int tableId = 1; - LOCKTAB *ltable; + int lockmethod = 1; + LOCKMETHODTABLE *lockMethodTable; ShmemPIDLookup(MyProcPid, &location); if (location == INVALID_OFFSET) @@ -1590,13 +1590,13 @@ DumpLocks() return; lockQueue = &proc->lockQueue; - Assert(tableId < NumTables); - ltable = AllTables[tableId]; - if (!ltable) + Assert(lockmethod < NumLockMethods); + lockMethodTable = LockMethodTable[lockmethod]; + if (!lockMethodTable) return; - nLockTypes = ltable->ctl->nLockTypes; - masterLock = ltable->ctl->masterLock; + numLockModes = lockMethodTable->ctl->numLockModes; + masterLock = lockMethodTable->ctl->masterLock; if (SHMQueueEmpty(lockQueue)) return; diff --git a/src/backend/storage/lmgr/multi.c b/src/backend/storage/lmgr/multi.c index d63c32615e..beb6d2fde8 100644 --- a/src/backend/storage/lmgr/multi.c +++ b/src/backend/storage/lmgr/multi.c @@ -12,7 +12,7 @@ * * * 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: * (1) The lock.c module assumes that the caller here is doing @@ -30,10 +30,10 @@ #include "miscadmin.h" /* MyDatabaseId */ static bool -MultiAcquire(LockTableId tableId, LOCKTAG *tag, LOCKTYPE locktype, +MultiAcquire(LOCKMETHOD lockmethod, LOCKTAG *tag, LOCKMODE lockmode, PG_LOCK_LEVEL level); static bool -MultiRelease(LockTableId tableId, LOCKTAG *tag, LOCKTYPE locktype, +MultiRelease(LOCKMETHOD lockmethod, LOCKTAG *tag, LOCKMODE lockmode, PG_LOCK_LEVEL level); /* @@ -78,25 +78,27 @@ static int MultiPrios[] = { * Lock table identifier for this lock table. The multi-level * lock table is ONE lock table, not three. */ -LockTableId MultiTableId = (LockTableId) NULL; -LockTableId ShortTermTableId = (LockTableId) NULL; +LOCKMETHOD MultiTableId = (LOCKMETHOD) NULL; +#ifdef NOT_USED +LOCKMETHOD ShortTermTableId = (LOCKMETHOD) NULL; +#endif /* * Create the lock table described by MultiConflicts and Multiprio. */ -LockTableId +LOCKMETHOD InitMultiLevelLocks() { - int tableId; + int lockmethod; - tableId = LockTableInit("LockTable", MultiConflicts, MultiPrios, 5); - MultiTableId = tableId; + lockmethod = LockMethodTableInit("MultiLevelLockTable", MultiConflicts, MultiPrios, 5); + MultiTableId = lockmethod; if (!(MultiTableId)) elog(ERROR, "InitMultiLocks: couldnt initialize lock table"); /* ----------------------- * No short term lock table for now. -Jeff 15 July 1991 * - * ShortTermTableId = LockTableRename(tableId); + * ShortTermTableId = LockTableRename(lockmethod); * if (! (ShortTermTableId)) { * elog(ERROR,"InitMultiLocks: couldnt rename lock table"); * } @@ -111,7 +113,7 @@ InitMultiLevelLocks() * Returns: TRUE if the lock can be set, FALSE otherwise. */ bool -MultiLockReln(LockInfo linfo, LOCKTYPE locktype) +MultiLockReln(LockInfo linfo, LOCKMODE lockmode) { LOCKTAG tag; @@ -122,7 +124,7 @@ MultiLockReln(LockInfo linfo, LOCKTYPE locktype) MemSet(&tag, 0, sizeof(tag)); tag.relId = linfo->lRelId.relId; 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) * at the page and relation level. */ bool -MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) +MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode) { LOCKTAG tag; @@ -149,14 +151,14 @@ MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) /* not locking any valid Tuple, just the page */ tag.tupleId = *tidPtr; - return (MultiAcquire(MultiTableId, &tag, locktype, TUPLE_LEVEL)); + return (MultiAcquire(MultiTableId, &tag, lockmode, TUPLE_LEVEL)); } /* * same as above at page level */ bool -MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) +MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode) { LOCKTAG tag; @@ -179,7 +181,7 @@ MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) tag.relId = linfo->lRelId.relId; tag.dbId = linfo->lRelId.dbId; 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) * Side Effects: */ static bool -MultiAcquire(LockTableId tableId, +MultiAcquire(LOCKMETHOD lockmethod, LOCKTAG *tag, - LOCKTYPE locktype, + LOCKMODE lockmode, PG_LOCK_LEVEL level) { - LOCKTYPE locks[N_LEVELS]; + LOCKMODE locks[N_LEVELS]; int i, status; LOCKTAG xxTag, @@ -213,19 +215,19 @@ MultiAcquire(LockTableId tableId, switch (level) { case RELN_LEVEL: - locks[0] = locktype; + locks[0] = lockmode; locks[1] = NO_LOCK; locks[2] = NO_LOCK; break; case PAGE_LEVEL: - locks[0] = locktype + INTENT; - locks[1] = locktype; + locks[0] = lockmode + INTENT; + locks[1] = lockmode; locks[2] = NO_LOCK; break; case TUPLE_LEVEL: - locks[0] = locktype + INTENT; - locks[1] = locktype + INTENT; - locks[2] = locktype; + locks[0] = lockmode + INTENT; + locks[1] = lockmode + INTENT; + locks[2] = lockmode; break; default: elog(ERROR, "MultiAcquire: bad lock level"); @@ -274,7 +276,7 @@ MultiAcquire(LockTableId tableId, break; } - status = LockAcquire(tableId, tmpTag, locks[i]); + status = LockAcquire(lockmethod, tmpTag, locks[i]); if (!status) { @@ -285,7 +287,7 @@ MultiAcquire(LockTableId tableId, * the last level lock we successfully acquired */ retStatus = FALSE; - MultiRelease(tableId, tag, locktype, i); + MultiRelease(lockmethod, tag, lockmode, i); /* now leave the loop. Don't try for any more locks */ break; } @@ -300,7 +302,7 @@ MultiAcquire(LockTableId tableId, */ #ifdef NOT_USED bool -MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) +MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode) { LOCKTAG tag; @@ -316,7 +318,7 @@ MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) tag.dbId = linfo->lRelId.dbId; BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid)); - return (MultiRelease(MultiTableId, &tag, locktype, PAGE_LEVEL)); + return (MultiRelease(MultiTableId, &tag, lockmode, PAGE_LEVEL)); } #endif @@ -326,7 +328,7 @@ MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype) * ------------------ */ bool -MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype) +MultiReleaseReln(LockInfo linfo, LOCKMODE lockmode) { LOCKTAG tag; @@ -340,7 +342,7 @@ MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype) tag.relId = linfo->lRelId.relId; 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) * Returns: TRUE if successful, FALSE otherwise. */ static bool -MultiRelease(LockTableId tableId, +MultiRelease(LOCKMETHOD lockmethod, LOCKTAG *tag, - LOCKTYPE locktype, + LOCKMODE lockmode, PG_LOCK_LEVEL level) { - LOCKTYPE locks[N_LEVELS]; + LOCKMODE locks[N_LEVELS]; int i, status; LOCKTAG xxTag, @@ -366,22 +368,22 @@ MultiRelease(LockTableId tableId, switch (level) { case RELN_LEVEL: - locks[0] = locktype; + locks[0] = lockmode; locks[1] = NO_LOCK; locks[2] = NO_LOCK; break; case PAGE_LEVEL: - locks[0] = locktype + INTENT; - locks[1] = locktype; + locks[0] = lockmode + INTENT; + locks[1] = lockmode; locks[2] = NO_LOCK; break; case TUPLE_LEVEL: - locks[0] = locktype + INTENT; - locks[1] = locktype + INTENT; - locks[2] = locktype; + locks[0] = lockmode + INTENT; + locks[1] = lockmode + INTENT; + locks[2] = lockmode; break; default: - elog(ERROR, "MultiRelease: bad locktype"); + elog(ERROR, "MultiRelease: bad lockmode"); } /* @@ -423,7 +425,7 @@ MultiRelease(LockTableId tableId, ItemPointerCopy(&tmpTag->tupleId, &tag->tupleId); break; } - status = LockRelease(tableId, tmpTag, locks[i]); + status = LockRelease(lockmethod, tmpTag, locks[i]); if (!status) elog(ERROR, "MultiRelease: couldn't release after error"); } diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 9be4f1bb96..d4e14fb9c4 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -7,7 +7,7 @@ * * * 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 @@ * This is so that we can support more backends. (system-wide semaphore * 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 #include @@ -580,7 +580,7 @@ ProcWakeup(PROC *proc, int errType) * released. */ int -ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock) +ProcLockWakeup(PROC_QUEUE *queue, LOCKMETHOD lockmethod, LOCK *lock) { PROC *proc; int count; @@ -590,8 +590,8 @@ ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock) proc = (PROC *) MAKE_PTR(queue->links.prev); count = 0; - while ((LockResolveConflicts((LOCKTAB *) ltable, - (LOCK *) lock, + while ((LockResolveConflicts(lockmethod, + lock, proc->token, proc->xid) == STATUS_OK)) { @@ -602,7 +602,7 @@ ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock) * between the time we release the lock master (spinlock) and the * time that the awoken process begins executing again. */ - GrantLock((LOCK *) lock, proc->token); + GrantLock(lock, proc->token); queue->size--; /* diff --git a/src/backend/storage/lmgr/single.c b/src/backend/storage/lmgr/single.c index ccae34b3d5..d58657b2c3 100644 --- a/src/backend/storage/lmgr/single.c +++ b/src/backend/storage/lmgr/single.c @@ -13,7 +13,7 @@ * * * 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 @@ * Returns: TRUE if the lock can be set, FALSE otherwise. */ bool -SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action) +SingleLockReln(LockInfo linfo, LOCKMODE lockmode, int action) { LOCKTAG tag; @@ -47,9 +47,9 @@ SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action) tag.tupleId.ip_posid = InvalidOffsetNumber; if (action == UNLOCK) - return (LockRelease(MultiTableId, &tag, locktype)); + return (LockRelease(MultiTableId, &tag, lockmode)); else - return (LockAcquire(MultiTableId, &tag, locktype)); + return (LockAcquire(MultiTableId, &tag, lockmode)); } /* @@ -63,7 +63,7 @@ SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action) bool SingleLockPage(LockInfo linfo, ItemPointer tidPtr, - LOCKTYPE locktype, + LOCKMODE lockmode, int action) { LOCKTAG tag; @@ -80,7 +80,7 @@ SingleLockPage(LockInfo linfo, if (action == UNLOCK) - return (LockRelease(MultiTableId, &tag, locktype)); + return (LockRelease(MultiTableId, &tag, lockmode)); else - return (LockAcquire(MultiTableId, &tag, locktype)); + return (LockAcquire(MultiTableId, &tag, lockmode)); } diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h index e429bb0047..f0371dc29a 100644 --- a/src/include/storage/lmgr.h +++ b/src/include/storage/lmgr.h @@ -6,7 +6,7 @@ * * 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); extern void RelationUnsetWIntentLock(Relation relation); /* single.c */ -extern bool SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action); +extern bool SingleLockReln(LockInfo linfo, LOCKMODE lockmode, int action); extern bool SingleLockPage(LockInfo linfo, ItemPointer tidPtr, - LOCKTYPE locktype, int action); + LOCKMODE lockmode, int action); /* proc.c */ extern void InitProcGlobal(IPCKey key); diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h index df70507ad1..48ac1ae553 100644 --- a/src/include/storage/lock.h +++ b/src/include/storage/lock.h @@ -6,7 +6,7 @@ * * 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; #define NLOCKS_PER_XACT 40 #define NLOCKENTS NLOCKS_PER_XACT*NBACKENDS -typedef int LOCK_TYPE; -typedef int LOCKTYPE; -typedef int LockTableId; +typedef int LOCKMODE; +typedef int LOCKMETHOD; -/* MAX_LOCKTYPES cannot be larger than the bits in MASK */ -#define MAX_LOCKTYPES 6 +/* MAX_LOCKMODES cannot be larger than the bits in MASK */ +#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 * 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 /*typedef struct LOCK LOCK; */ -typedef struct ltag +typedef struct LTAG { Oid relId; Oid dbId; @@ -67,31 +66,31 @@ typedef struct ltag /* This is the control structure for a lock table. It * lives in shared memory: * - * tableID -- the handle used by the lock table's clients to - * refer to the table. + * lockmethod -- the handle used by the lock table's clients to + * 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 * * conflictTab -- this is an array of bitmasks showing lock * type conflicts. conflictTab[i] is a mask with the j-th bit * 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 * starvation). * * masterlock -- synchronizes access to the table * */ -typedef struct lockctl +typedef struct LOCKMETHODCTL { - LockTableId tableId; - int nLockTypes; - int conflictTab[MAX_LOCKTYPES]; - int prio[MAX_LOCKTYPES]; + LOCKMETHOD lockmethod; + int numLockModes; + int conflictTab[MAX_LOCKMODES]; + int prio[MAX_LOCKMODES]; SPINLOCK masterLock; -} LOCKCTL; +} LOCKMETHODCTL; /* * lockHash -- hash table on lock Ids, @@ -99,12 +98,12 @@ typedef struct lockctl * multiple processes are holding the lock * ctl - control structure described above. */ -typedef struct ltable +typedef struct LOCKMETHODTABLE { HTAB *lockHash; HTAB *xidHash; - LOCKCTL *ctl; -} LOCKTAB; + LOCKMETHODCTL *ctl; +} LOCKMETHODTABLE; /* ----------------------- * A transaction never conflicts with its own locks. Hence, if @@ -148,7 +147,7 @@ typedef struct XIDLookupEnt XIDTAG tag; /* data */ - int holders[MAX_LOCKTYPES]; + int holders[MAX_LOCKMODES]; int nHolding; SHM_QUEUE queue; } XIDLookupEnt; @@ -156,7 +155,7 @@ typedef struct XIDLookupEnt #define XID_TAGSIZE (sizeof(XIDTAG)) /* originally in procq.h */ -typedef struct procQueue +typedef struct PROC_QUEUE { SHM_QUEUE links; int size; @@ -174,7 +173,7 @@ typedef struct procQueue * lock. * nHolding -- total locks of all types. */ -typedef struct Lock +typedef struct LOCK { /* hash key */ LOCKTAG tag; @@ -182,18 +181,18 @@ typedef struct Lock /* data */ int mask; PROC_QUEUE waitProcs; - int holders[MAX_LOCKTYPES]; + int holders[MAX_LOCKMODES]; int nHolding; - int activeHolders[MAX_LOCKTYPES]; + int activeHolders[MAX_LOCKMODES]; int nActive; } LOCK; #define LockGetLock_nHolders(l) l->nHolders -#define LockDecrWaitHolders(lock, locktype) \ +#define LockDecrWaitHolders(lock, lockmode) \ ( \ lock->nHolding--, \ - lock->holders[locktype]-- \ + lock->holders[lockmode]-- \ ) #define LockLockTable() SpinAcquire(LockMgrLock); @@ -206,16 +205,16 @@ extern SPINLOCK LockMgrLock; */ extern void InitLocks(void); extern void LockDisable(int status); -extern LockTableId -LockTableInit(char *tabName, MASK *conflictsP, int *prioP, - int ntypes); -extern bool LockAcquire(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype); +extern LOCKMETHOD +LockMethodTableInit(char *tabName, MASK *conflictsP, int *prioP, + int numModes); +extern bool LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, LOCKMODE lockmode); extern int -LockResolveConflicts(LOCKTAB *ltable, LOCK *lock, LOCKTYPE locktype, +LockResolveConflicts(LOCKMETHOD lockmethod, LOCK *lock, LOCKMODE lockmode, TransactionId xid); -extern bool LockRelease(LockTableId tableId, LOCKTAG *lockName, LOCKTYPE locktype); -extern void GrantLock(LOCK *lock, LOCKTYPE locktype); -extern bool LockReleaseAll(LockTableId tableId, SHM_QUEUE *lockQueue); +extern bool LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, LOCKMODE lockmode); +extern void GrantLock(LOCK *lock, LOCKMODE lockmode); +extern bool LockReleaseAll(LOCKMETHOD lockmethod, SHM_QUEUE *lockQueue); extern int LockShmemSize(void); extern bool LockingDisabled(void); extern bool DeadLockCheck(SHM_QUEUE *lockQueue, LOCK *findlock, bool skip_check); diff --git a/src/include/storage/multilev.h b/src/include/storage/multilev.h index 2163ffd964..95091c9f62 100644 --- a/src/include/storage/multilev.h +++ b/src/include/storage/multilev.h @@ -7,7 +7,7 @@ * * 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; /* multi.c */ -extern LockTableId MultiTableId; -extern LockTableId ShortTermTableId; +extern LOCKMETHOD MultiTableId; +#ifdef NOT_USED +extern LOCKMETHOD ShortTermTableId; +#endif /* * function prototypes */ -extern LockTableId InitMultiLevelLocks(void); -extern bool MultiLockReln(LockInfo linfo, LOCKTYPE locktype); -extern bool MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype); -extern bool MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype); -extern bool MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype); +extern LOCKMETHOD InitMultiLevelLocks(void); +extern bool MultiLockReln(LockInfo linfo, LOCKMODE lockmode); +extern bool MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode); +extern bool MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode); +extern bool MultiReleaseReln(LockInfo linfo, LOCKMODE lockmode); #endif /* MULTILEV_H */ diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index c41df70e89..f809fad7af 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -6,7 +6,7 @@ * * 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); extern int ProcSleep(PROC_QUEUE *queue, SPINLOCK spinlock, int token, 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 ProcReleaseSpins(PROC *proc); extern void ProcFreeAllSemaphores(void); diff --git a/src/tools/backend/index.html b/src/tools/backend/index.html index f736439fa0..3f032e081c 100644 --- a/src/tools/backend/index.html +++ b/src/tools/backend/index.html @@ -25,13 +25,13 @@ structure, like The query is then identified as a Utility function or a more complex query. A Utility query is processed by a query-specific function in -commands. A complex query, like SELECT, UPDATE, and -DELETE requires much more handling. +commands. A complex query, like SELECT, UPDATE, and +DELETE requires much more handling.

The parser takes a complex query, and creates a Query structure that contains all the elements used by complex queries. Query.qual holds the -WHERE clause qualification, which is filled in by +WHERE clause qualification, which is filled in by transformWhereClause(). Each table referenced in the query is represented by a RangeTableEntry, and they @@ -39,19 +39,19 @@ are linked together to form the range table of the query, which is generated by makeRangeTable(). Query.rtable holds the queries range table.

-Certain queries, like SELECT, return columns of data. Other -queries, like INSERT and UPDATE, specify the columns +Certain queries, like SELECT, return columns of data. Other +queries, like INSERT and UPDATE, specify the columns modified by the query. These column references are converted to Resdom entries, which are linked together to make up the target list of the query. The target list is stored in Query.targetList, which is generated by transformTargetList().

-Other query elements, like aggregates(SUM()), GROUP BY, -ORDER BY are also stored in their own Query fields. +Other query elements, like aggregates(SUM()), GROUP BY, +ORDER BY are also stored in their own Query fields.

-The next step is for the Query to be modified by any VIEWS or -RULES that may apply to the query. This is performed by the VIEWS or +RULES that may apply to the query. This is performed by the rewrite system.

The optimizer takes the Query @@ -60,7 +60,7 @@ HREF="../..//include/nodes/plannodes.h">Plan, which contains the operations to be performed to execute the query. The path module determines the best table join order and join type of each table in the RangeTable, using -Query.qual(WHERE clause) to consider optimal index usage. +Query.qual(WHERE clause) to consider optimal index usage.

The Plan is then passed to the executor for execution, and the result @@ -81,15 +81,25 @@ data/index buffer cache block

  • Shared Buf Lookup Table - lookup of buffer cache block address using table name and block number( BufferTag) -
  • LockTable (ctl) - lock table -structure, specifiying table, lock types, and backends holding or -waiting on lock -
  • LockTable (lock hash) - lookup of LockTable structures using relation, -database object ids -
  • LockTable (xid hash) - lookup of LockTable structures using -transaction id, LockTable address +
  • MultiLevelLockTable (ctl) - LOCKCTL control structure for +each locking method. Currently, only multi-level locking is used. +
  • MultiLevelLockTable (lock hash) - the LOCK structure, looked up using +relation, database object ids(LOCKTAG). The lock table structure contains the +lock modes(read, write) and circular linked list of backends (PROC structure pointers) waiting +on the lock. +
  • 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 +XIDLookupEnt structure also +contains a pointer to the backend's PROC.lockQueue.
  • Proc Header - information -about each backend, including locks held/waiting, indexed by process id +about each backend, including locks held/waiting, indexed by process id Each data structure is created by calling ShmemInitStruct(), and