aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/regproc.c
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/utils/adt/regproc.c
parent6c86fd5ba49bc03949ea1c788023f39da9c0b9fe (diff)
downloadpostgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.tar.gz
postgresql-bd272cace63effa23d68a6b344a07e326b6a41e2.zip
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/utils/adt/regproc.c')
-rw-r--r--src/backend/utils/adt/regproc.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 754eea3a96e..b3179e864c1 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.42 1999/07/17 20:17:59 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.43 1999/09/18 19:07:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -78,7 +78,7 @@ regprocin(char *pro_name_or_oid)
(RegProcedure) F_NAMEEQ,
PointerGetDatum(pro_name_or_oid));
- hdesc = heap_openr(ProcedureRelationName);
+ hdesc = heap_openr(ProcedureRelationName, AccessShareLock);
idesc = index_openr(ProcedureNameIndex);
sd = index_beginscan(idesc, false, 1, skey);
@@ -102,6 +102,7 @@ regprocin(char *pro_name_or_oid)
index_endscan(sd);
pfree(sd);
index_close(idesc);
+ heap_close(hdesc, AccessShareLock);
if (matches > 1)
elog(ERROR, "There is more than one procedure named %s.\n\tSupply the pg_proc oid inside single quotes.", pro_name_or_oid);
@@ -116,13 +117,7 @@ regprocin(char *pro_name_or_oid)
ScanKeyData key;
bool isnull;
- proc = heap_openr(ProcedureRelationName);
- if (!RelationIsValid(proc))
- {
- elog(ERROR, "regprocin: could not open %s",
- ProcedureRelationName);
- return 0;
- }
+ proc = heap_openr(ProcedureRelationName, AccessShareLock);
ScanKeyEntryInitialize(&key,
(bits16) 0,
(AttrNumber) 1,
@@ -132,8 +127,8 @@ regprocin(char *pro_name_or_oid)
procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key);
if (!HeapScanIsValid(procscan))
{
- heap_close(proc);
- elog(ERROR, "regprocin: could not being scan of %s",
+ heap_close(proc, AccessShareLock);
+ elog(ERROR, "regprocin: could not begin scan of %s",
ProcedureRelationName);
return 0;
}
@@ -151,7 +146,7 @@ regprocin(char *pro_name_or_oid)
result = (RegProcedure) 0;
heap_endscan(procscan);
- heap_close(proc);
+ heap_close(proc, AccessShareLock);
}
return (int32) result;
@@ -193,12 +188,7 @@ regprocout(RegProcedure proid)
HeapScanDesc procscan;
ScanKeyData key;
- proc = heap_openr(ProcedureRelationName);
- if (!RelationIsValid(proc))
- {
- elog(ERROR, "regprocout: could not open %s", ProcedureRelationName);
- return 0;
- }
+ proc = heap_openr(ProcedureRelationName, AccessShareLock);
ScanKeyEntryInitialize(&key,
(bits16) 0,
(AttrNumber) ObjectIdAttributeNumber,
@@ -208,8 +198,8 @@ regprocout(RegProcedure proid)
procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key);
if (!HeapScanIsValid(procscan))
{
- heap_close(proc);
- elog(ERROR, "regprocout: could not being scan of %s",
+ heap_close(proc, AccessShareLock);
+ elog(ERROR, "regprocout: could not begin scan of %s",
ProcedureRelationName);
return 0;
}
@@ -232,8 +222,7 @@ regprocout(RegProcedure proid)
result[1] = '\0';
}
heap_endscan(procscan);
- heap_close(proc);
- return result;
+ heap_close(proc, AccessShareLock);
}
return result;