diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-14 22:15:33 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-14 22:15:33 +0000 |
commit | 8563ccae2caf0119355c5c80cfa59da19ce809d6 (patch) | |
tree | c53bd9d44280939a986d44e26d7ee1f29216cb3e /src/backend/storage/lmgr/lmgr.c | |
parent | f5835b4b8d569e4d7814886f9e7b90c36d8a4fb5 (diff) | |
download | postgresql-8563ccae2caf0119355c5c80cfa59da19ce809d6.tar.gz postgresql-8563ccae2caf0119355c5c80cfa59da19ce809d6.zip |
Simplify shared-memory lock data structures as per recent discussion:
it is sufficient to track whether a backend holds a lock or not, and
store information about transaction vs. session locks only in the
inside-the-backend LocalLockTable. Since there can now be but one
PROCLOCK per lock per backend, LockCountMyLocks() is no longer needed,
thus eliminating some O(N^2) behavior when a backend holds many locks.
Also simplify the LockAcquire/LockRelease API by passing just a
'sessionLock' boolean instead of a transaction ID. The previous API
was designed with the idea that per-transaction lock holding would be
important for subtransactions, but now that we have subtransactions we
know that this is unwanted. While at it, add an 'isTempObject' parameter
to LockAcquire to indicate whether the lock is being taken on a temp
table. This is not used just yet, but will be needed shortly for
two-phase commit.
Diffstat (limited to 'src/backend/storage/lmgr/lmgr.c')
-rw-r--r-- | src/backend/storage/lmgr/lmgr.c | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c index b7c5903c8a1..351ef27bee7 100644 --- a/src/backend/storage/lmgr/lmgr.c +++ b/src/backend/storage/lmgr/lmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.75 2005/05/29 22:45:02 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.76 2005/06/14 22:15:32 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -142,8 +142,8 @@ LockRelation(Relation relation, LOCKMODE lockmode) relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); - res = LockAcquire(LockTableId, &tag, GetTopTransactionId(), - lockmode, false); + res = LockAcquire(LockTableId, &tag, relation->rd_istemp, + lockmode, false, false); /* * Check to see if the relcache entry has been invalidated while we @@ -179,8 +179,8 @@ ConditionalLockRelation(Relation relation, LOCKMODE lockmode) relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); - res = LockAcquire(LockTableId, &tag, GetTopTransactionId(), - lockmode, true); + res = LockAcquire(LockTableId, &tag, relation->rd_istemp, + lockmode, false, true); if (res == LOCKACQUIRE_NOT_AVAIL) return false; @@ -214,7 +214,7 @@ UnlockRelation(Relation relation, LOCKMODE lockmode) relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); - LockRelease(LockTableId, &tag, GetTopTransactionId(), lockmode); + LockRelease(LockTableId, &tag, lockmode, false); } /* @@ -230,14 +230,14 @@ UnlockRelation(Relation relation, LOCKMODE lockmode) * relcache entry is up to date. */ void -LockRelationForSession(LockRelId *relid, LOCKMODE lockmode) +LockRelationForSession(LockRelId *relid, bool istemprel, LOCKMODE lockmode) { LOCKTAG tag; SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId); - (void) LockAcquire(LockTableId, &tag, InvalidTransactionId, - lockmode, false); + (void) LockAcquire(LockTableId, &tag, istemprel, + lockmode, true, false); } /* @@ -250,7 +250,7 @@ UnlockRelationForSession(LockRelId *relid, LOCKMODE lockmode) SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId); - LockRelease(LockTableId, &tag, InvalidTransactionId, lockmode); + LockRelease(LockTableId, &tag, lockmode, true); } /* @@ -272,8 +272,8 @@ LockRelationForExtension(Relation relation, LOCKMODE lockmode) relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); - (void) LockAcquire(LockTableId, &tag, GetTopTransactionId(), - lockmode, false); + (void) LockAcquire(LockTableId, &tag, relation->rd_istemp, + lockmode, false, false); } /* @@ -288,7 +288,7 @@ UnlockRelationForExtension(Relation relation, LOCKMODE lockmode) relation->rd_lockInfo.lockRelId.dbId, relation->rd_lockInfo.lockRelId.relId); - LockRelease(LockTableId, &tag, GetTopTransactionId(), lockmode); + LockRelease(LockTableId, &tag, lockmode, false); } /* @@ -307,8 +307,8 @@ LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode) relation->rd_lockInfo.lockRelId.relId, blkno); - (void) LockAcquire(LockTableId, &tag, GetTopTransactionId(), - lockmode, false); + (void) LockAcquire(LockTableId, &tag, relation->rd_istemp, + lockmode, false, false); } /* @@ -327,8 +327,8 @@ ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode) relation->rd_lockInfo.lockRelId.relId, blkno); - return (LockAcquire(LockTableId, &tag, GetTopTransactionId(), - lockmode, true) != LOCKACQUIRE_NOT_AVAIL); + return (LockAcquire(LockTableId, &tag, relation->rd_istemp, + lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL); } /* @@ -344,7 +344,7 @@ UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode) relation->rd_lockInfo.lockRelId.relId, blkno); - LockRelease(LockTableId, &tag, GetTopTransactionId(), lockmode); + LockRelease(LockTableId, &tag, lockmode, false); } /* @@ -365,8 +365,8 @@ LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode) ItemPointerGetBlockNumber(tid), ItemPointerGetOffsetNumber(tid)); - (void) LockAcquire(LockTableId, &tag, GetTopTransactionId(), - lockmode, false); + (void) LockAcquire(LockTableId, &tag, relation->rd_istemp, + lockmode, false, false); } /* @@ -383,7 +383,7 @@ UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode) ItemPointerGetBlockNumber(tid), ItemPointerGetOffsetNumber(tid)); - LockRelease(LockTableId, &tag, GetTopTransactionId(), lockmode); + LockRelease(LockTableId, &tag, lockmode, false); } /* @@ -400,8 +400,8 @@ XactLockTableInsert(TransactionId xid) SET_LOCKTAG_TRANSACTION(tag, xid); - (void) LockAcquire(LockTableId, &tag, GetTopTransactionId(), - ExclusiveLock, false); + (void) LockAcquire(LockTableId, &tag, false, + ExclusiveLock, false, false); } /* @@ -419,7 +419,7 @@ XactLockTableDelete(TransactionId xid) SET_LOCKTAG_TRANSACTION(tag, xid); - LockRelease(LockTableId, &tag, GetTopTransactionId(), ExclusiveLock); + LockRelease(LockTableId, &tag, ExclusiveLock, false); } /* @@ -438,19 +438,18 @@ void XactLockTableWait(TransactionId xid) { LOCKTAG tag; - TransactionId myxid = GetTopTransactionId(); for (;;) { Assert(TransactionIdIsValid(xid)); - Assert(!TransactionIdEquals(xid, myxid)); + Assert(!TransactionIdEquals(xid, GetTopTransactionId())); SET_LOCKTAG_TRANSACTION(tag, xid); - (void) LockAcquire(LockTableId, &tag, myxid, - ShareLock, false); + (void) LockAcquire(LockTableId, &tag, false, + ShareLock, false, false); - LockRelease(LockTableId, &tag, myxid, ShareLock); + LockRelease(LockTableId, &tag, ShareLock, false); if (!TransactionIdIsInProgress(xid)) break; @@ -470,9 +469,11 @@ XactLockTableWait(TransactionId xid) * LockDatabaseObject * * Obtain a lock on a general object of the current database. Don't use - * this for shared objects (such as tablespaces). It's usually unwise to - * apply it to entire relations, also, since a lock taken this way will - * NOT conflict with LockRelation. + * this for shared objects (such as tablespaces). It's unwise to apply it + * to relations, also, since a lock taken this way will NOT conflict with + * LockRelation, and also may be wrongly marked if the relation is temp. + * (If we ever invent temp objects that aren't tables, we'll want to extend + * the API of this routine to include an isTempObject flag.) */ void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, @@ -486,8 +487,8 @@ LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, objid, objsubid); - (void) LockAcquire(LockTableId, &tag, GetTopTransactionId(), - lockmode, false); + (void) LockAcquire(LockTableId, &tag, false, + lockmode, false, false); } /* @@ -505,7 +506,7 @@ UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, objid, objsubid); - LockRelease(LockTableId, &tag, GetTopTransactionId(), lockmode); + LockRelease(LockTableId, &tag, lockmode, false); } /* @@ -525,8 +526,8 @@ LockSharedObject(Oid classid, Oid objid, uint16 objsubid, objid, objsubid); - (void) LockAcquire(LockTableId, &tag, GetTopTransactionId(), - lockmode, false); + (void) LockAcquire(LockTableId, &tag, false, + lockmode, false, false); } /* @@ -544,5 +545,5 @@ UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, objid, objsubid); - LockRelease(LockTableId, &tag, GetTopTransactionId(), lockmode); + LockRelease(LockTableId, &tag, lockmode, false); } |