summaryrefslogtreecommitdiff
path: root/src/backend/storage/lmgr
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-09-18 19:08:25 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-09-18 19:08:25 +0000
commitbd272cace63effa23d68a6b344a07e326b6a41e2 (patch)
tree3026c545c238bd38eadc7fb1fac89d636cf51673 /src/backend/storage/lmgr
parent6c86fd5ba49bc03949ea1c788023f39da9c0b9fe (diff)
downloadpostgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.tar.gz
Mega-commit to make heap_open/heap_openr/heap_close take an
additional argument specifying the kind of lock to acquire/release (or 'NoLock' to do no lock processing). Ensure that all relations are locked with some appropriate lock level before being examined --- this ensures that relevant shared-inval messages have been processed and should prevent problems caused by concurrent VACUUM. Fix several bugs having to do with mismatched increment/decrement of relation ref count and mismatched heap_open/close (which amounts to the same thing). A bogus ref count on a relation doesn't matter much *unless* a SI Inval message happens to arrive at the wrong time, which is probably why we got away with this sloppiness for so long. Repair missing grab of AccessExclusiveLock in DROP TABLE, ALTER/RENAME TABLE, etc, as noted by Hiroshi. Recommend 'make clean all' after pulling this update; I modified the Relation struct layout slightly. Will post further discussion to pghackers list shortly.
Diffstat (limited to 'src/backend/storage/lmgr')
-rw-r--r--src/backend/storage/lmgr/lmgr.c82
-rw-r--r--src/backend/storage/lmgr/lock.c6
2 files changed, 19 insertions, 69 deletions
diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c
index 839533952b..2aaaf69e83 100644
--- a/src/backend/storage/lmgr/lmgr.c
+++ b/src/backend/storage/lmgr/lmgr.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.34 1999/09/04 18:42:14 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.35 1999/09/18 19:07:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -20,11 +20,12 @@
#include "postgres.h"
+
#include "access/transam.h"
#include "catalog/catalog.h"
+#include "miscadmin.h"
#include "utils/inval.h"
-extern Oid MyDatabaseId;
static LOCKMASK LockConflicts[] = {
(int) NULL,
@@ -106,37 +107,25 @@ InitLockTable()
/*
* RelationInitLockInfo
* Initializes the lock information in a relation descriptor.
+ *
+ * relcache.c must call this during creation of any reldesc.
*/
void
RelationInitLockInfo(Relation relation)
{
- LockInfo info;
char *relname;
- MemoryContext oldcxt;
- extern Oid MyDatabaseId; /* XXX use include */
- extern GlobalMemory CacheCxt;
Assert(RelationIsValid(relation));
Assert(OidIsValid(RelationGetRelid(relation)));
- info = (LockInfo) relation->lockInfo;
-
- if (LockInfoIsValid(info))
- return;
-
relname = (char *) RelationGetRelationName(relation);
- oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
- info = (LockInfo) palloc(sizeof(LockInfoData));
- MemoryContextSwitchTo(oldcxt);
+ relation->rd_lockInfo.lockRelId.relId = RelationGetRelid(relation);
- info->lockRelId.relId = RelationGetRelid(relation);
if (IsSharedSystemRelationName(relname))
- info->lockRelId.dbId = InvalidOid;
+ relation->rd_lockInfo.lockRelId.dbId = InvalidOid;
else
- info->lockRelId.dbId = MyDatabaseId;
-
- relation->lockInfo = (Pointer) info;
+ relation->rd_lockInfo.lockRelId.dbId = MyDatabaseId;
}
/*
@@ -145,20 +134,14 @@ RelationInitLockInfo(Relation relation)
void
LockRelation(Relation relation, LOCKMODE lockmode)
{
- LockInfo lockinfo;
LOCKTAG tag;
if (LockingDisabled())
return;
- if (!LockInfoIsValid(relation->lockInfo))
- RelationInitLockInfo(relation);
-
- lockinfo = (LockInfo) relation->lockInfo;
-
MemSet(&tag, 0, sizeof(tag));
- tag.relId = lockinfo->lockRelId.relId;
- tag.dbId = lockinfo->lockRelId.dbId;
+ tag.relId = relation->rd_lockInfo.lockRelId.relId;
+ tag.dbId = relation->rd_lockInfo.lockRelId.dbId;
tag.objId.blkno = InvalidBlockNumber;
LockAcquire(LockTableId, &tag, lockmode);
@@ -180,28 +163,17 @@ LockRelation(Relation relation, LOCKMODE lockmode)
void
UnlockRelation(Relation relation, LOCKMODE lockmode)
{
- LockInfo lockinfo;
LOCKTAG tag;
if (LockingDisabled())
return;
- lockinfo = (LockInfo) relation->lockInfo;
-
- if (!LockInfoIsValid(lockinfo))
- {
- elog(ERROR,
- "Releasing a lock on %s with invalid lock information",
- RelationGetRelationName(relation));
- }
-
MemSet(&tag, 0, sizeof(tag));
- tag.relId = lockinfo->lockRelId.relId;
- tag.dbId = lockinfo->lockRelId.dbId;
+ tag.relId = relation->rd_lockInfo.lockRelId.relId;
+ tag.dbId = relation->rd_lockInfo.lockRelId.dbId;
tag.objId.blkno = InvalidBlockNumber;
LockRelease(LockTableId, &tag, lockmode);
- return;
}
/*
@@ -210,24 +182,17 @@ UnlockRelation(Relation relation, LOCKMODE lockmode)
void
LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
{
- LockInfo lockinfo;
LOCKTAG tag;
if (LockingDisabled())
return;
- if (!LockInfoIsValid(relation->lockInfo))
- RelationInitLockInfo(relation);
-
- lockinfo = (LockInfo) relation->lockInfo;
-
MemSet(&tag, 0, sizeof(tag));
- tag.relId = lockinfo->lockRelId.relId;
- tag.dbId = lockinfo->lockRelId.dbId;
+ tag.relId = relation->rd_lockInfo.lockRelId.relId;
+ tag.dbId = relation->rd_lockInfo.lockRelId.dbId;
tag.objId.blkno = blkno;
LockAcquire(LockTableId, &tag, lockmode);
- return;
}
/*
@@ -236,28 +201,17 @@ LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
void
UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
{
- LockInfo lockinfo;
LOCKTAG tag;
if (LockingDisabled())
return;
- lockinfo = (LockInfo) relation->lockInfo;
-
- if (!LockInfoIsValid(lockinfo))
- {
- elog(ERROR,
- "Releasing a lock on %s with invalid lock information",
- RelationGetRelationName(relation));
- }
-
MemSet(&tag, 0, sizeof(tag));
- tag.relId = lockinfo->lockRelId.relId;
- tag.dbId = lockinfo->lockRelId.dbId;
+ tag.relId = relation->rd_lockInfo.lockRelId.relId;
+ tag.dbId = relation->rd_lockInfo.lockRelId.dbId;
tag.objId.blkno = blkno;
LockRelease(LockTableId, &tag, lockmode);
- return;
}
void
@@ -274,7 +228,6 @@ XactLockTableInsert(TransactionId xid)
tag.objId.xid = xid;
LockAcquire(LockTableId, &tag, ExclusiveLock);
- return;
}
void
@@ -291,7 +244,6 @@ XactLockTableDelete(TransactionId xid)
tag.objId.xid = xid;
LockRelease(LockTableId, &tag, ExclusiveLock);
- return;
}
void
@@ -316,6 +268,4 @@ XactLockTableWait(TransactionId xid)
*/
if (!TransactionIdDidCommit(xid) && !TransactionIdDidAbort(xid))
TransactionIdAbort(xid);
-
- return;
}
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 427cc749c8..3f5322c9f0 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.61 1999/07/17 20:17:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.62 1999/09/18 19:07:38 tgl Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@@ -596,7 +596,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, LOCKMODE lockmode)
if (!result)
{
elog(NOTICE, "LockAcquire: xid table corrupted");
- return STATUS_ERROR;
+ return FALSE;
}
/*
@@ -1117,7 +1117,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, LOCKMODE lockmode)
TPRINTF(TRACE_USERLOCKS, "LockRelease: no lock with this tag");
else
#endif
- elog(NOTICE, "LockReplace: xid table corrupted");
+ elog(NOTICE, "LockRelease: xid table corrupted");
return FALSE;
}
XID_PRINT("LockRelease: found", result);