mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
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.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.58 1999/07/19 07:07:23 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.59 1999/09/18 19:07:32 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -139,13 +139,16 @@ inv_create(int flags)
|
||||
|
||||
/* make the relation visible in this transaction */
|
||||
CommandCounterIncrement();
|
||||
r = heap_openr(objname);
|
||||
|
||||
if (!RelationIsValid(r))
|
||||
{
|
||||
elog(ERROR, "cannot create large object on %s under inversion",
|
||||
smgrout(DEFAULT_SMGR));
|
||||
}
|
||||
/*--------------------
|
||||
* We hold AccessShareLock on any large object we have open
|
||||
* by inv_create or inv_open; it is released by inv_close.
|
||||
* Note this will not conflict with ExclusiveLock or ShareLock
|
||||
* that we acquire when actually reading/writing; it just prevents
|
||||
* deletion of the large object while we have it open.
|
||||
*--------------------
|
||||
*/
|
||||
r = heap_openr(objname, AccessShareLock);
|
||||
|
||||
/*
|
||||
* Now create a btree index on the relation's olastbyte attribute to
|
||||
@@ -205,10 +208,7 @@ inv_open(Oid lobjId, int flags)
|
||||
char *indname;
|
||||
Relation indrel;
|
||||
|
||||
r = heap_open(lobjId);
|
||||
|
||||
if (!RelationIsValid(r))
|
||||
return (LargeObjectDesc *) NULL;
|
||||
r = heap_open(lobjId, AccessShareLock);
|
||||
|
||||
indname = pstrdup((r->rd_rel->relname).data);
|
||||
|
||||
@@ -262,8 +262,8 @@ inv_close(LargeObjectDesc *obj_desc)
|
||||
obj_desc->iscan = NULL;
|
||||
}
|
||||
|
||||
heap_close(obj_desc->heap_r);
|
||||
index_close(obj_desc->index_r);
|
||||
heap_close(obj_desc->heap_r, AccessShareLock);
|
||||
|
||||
pfree(obj_desc);
|
||||
}
|
||||
@@ -279,7 +279,7 @@ inv_destroy(Oid lobjId)
|
||||
Relation r;
|
||||
|
||||
r = (Relation) RelationIdGetRelation(lobjId);
|
||||
if (!RelationIsValid(r) || r->rd_rel->relkind == RELKIND_INDEX)
|
||||
if (!RelationIsValid(r) || r->rd_rel->relkind != RELKIND_LOBJECT)
|
||||
return -1;
|
||||
|
||||
heap_destroy_with_catalog(r->rd_rel->relname.data);
|
||||
@@ -497,7 +497,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
|
||||
|
||||
if (!(obj_desc->flags & IFS_WRLOCK))
|
||||
{
|
||||
LockRelation(obj_desc->heap_r, ShareLock);
|
||||
LockRelation(obj_desc->heap_r, ExclusiveLock);
|
||||
obj_desc->flags |= (IFS_WRLOCK | IFS_RDLOCK);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user