1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +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:
Tom Lane
1999-09-18 19:08:25 +00:00
parent 6c86fd5ba4
commit bd272cace6
70 changed files with 1094 additions and 1215 deletions

View File

@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/Attic/locks.c,v 1.21 1999/07/16 04:59:39 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/Attic/locks.c,v 1.22 1999/09/18 19:07:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -184,7 +184,7 @@ checkLockPerms(List *locks, Query *parsetree, int rt_index)
* Get the usename of the rules event relation owner
*/
rte = (RangeTblEntry *) nth(rt_index - 1, parsetree->rtable);
ev_rel = heap_openr(rte->relname);
ev_rel = heap_openr(rte->relname, AccessShareLock);
usertup = SearchSysCacheTuple(USESYSID,
ObjectIdGetDatum(ev_rel->rd_rel->relowner),
0, 0, 0);
@ -193,7 +193,7 @@ checkLockPerms(List *locks, Query *parsetree, int rt_index)
elog(ERROR, "cache lookup for userid %d failed",
ev_rel->rd_rel->relowner);
}
heap_close(ev_rel);
heap_close(ev_rel, AccessShareLock);
evowner = nameout(&(((Form_pg_shadow) GETSTRUCT(usertup))->usename));
/*

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.35 1999/07/19 07:07:21 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.36 1999/09/18 19:07:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -78,9 +78,7 @@ InsertRule(char *rulname,
extern void eval_as_new_xact();
char *template;
eventrel = heap_openr(evobj);
if (eventrel == NULL)
elog(ERROR, "rules cannot be defined on relations not in schema");
eventrel = heap_openr(evobj, AccessShareLock);
eventrel_oid = RelationGetRelid(eventrel);
/*
@ -90,7 +88,7 @@ InsertRule(char *rulname,
evslot_index = -1;
else
evslot_index = attnameAttNum(eventrel, (char *) evslot);
heap_close(eventrel);
heap_close(eventrel, AccessShareLock);
if (evinstead)
is_instead = "t";
@ -258,9 +256,7 @@ DefineQueryRewrite(RuleStmt *stmt)
* ... the targetlist of the SELECT action must exactly match the
* event relation, ...
*/
event_relation = heap_openr(event_obj->relname);
if (event_relation == NULL)
elog(ERROR, "virtual relations not supported yet");
event_relation = heap_openr(event_obj->relname, AccessShareLock);
if (event_relation->rd_att->natts != length(query->targetList))
elog(ERROR, "select rules target list must match event relations structure");
@ -297,7 +293,7 @@ DefineQueryRewrite(RuleStmt *stmt)
}
}
heap_close(event_relation);
heap_close(event_relation, AccessShareLock);
/*
* LIMIT in view is not supported
@ -332,9 +328,7 @@ DefineQueryRewrite(RuleStmt *stmt)
* This rule is allowed - install it.
*/
event_relation = heap_openr(event_obj->relname);
if (event_relation == NULL)
elog(ERROR, "virtual relations not supported yet");
event_relation = heap_openr(event_obj->relname, AccessShareLock);
ev_relid = RelationGetRelid(event_relation);
if (eslot_string == NULL)
@ -347,7 +341,7 @@ DefineQueryRewrite(RuleStmt *stmt)
event_attno = attnameAttNum(event_relation, eslot_string);
event_attype = attnumTypeId(event_relation, event_attno);
}
heap_close(event_relation);
heap_close(event_relation, AccessShareLock);
/* fix bug about instead nothing */
ValidateRule(event_type, event_obj->relname,

View File

@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.55 1999/08/25 23:21:43 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.56 1999/09/18 19:07:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -2059,10 +2059,10 @@ fireRIRrules(Query *parsetree)
continue;
}
rel = heap_openr(rte->relname);
rel = heap_openr(rte->relname, AccessShareLock);
if (rel->rd_rules == NULL)
{
heap_close(rel);
heap_close(rel, AccessShareLock);
continue;
}
@ -2112,7 +2112,7 @@ fireRIRrules(Query *parsetree)
&modified);
}
heap_close(rel);
heap_close(rel, AccessShareLock);
}
fireRIRonSubselect((Node *) parsetree);
@ -2452,9 +2452,9 @@ RewriteQuery(Query *parsetree, bool *instead_flag, List **qual_products)
* the statement is an update, insert or delete - fire rules on it.
*/
rt_entry = rt_fetch(result_relation, parsetree->rtable);
rt_entry_relation = heap_openr(rt_entry->relname);
rt_entry_relation = heap_openr(rt_entry->relname, AccessShareLock);
rt_entry_locks = rt_entry_relation->rd_rules;
heap_close(rt_entry_relation);
heap_close(rt_entry_relation, AccessShareLock);
if (rt_entry_locks != NULL)
{
@ -2469,7 +2469,6 @@ RewriteQuery(Query *parsetree, bool *instead_flag, List **qual_products)
}
return product_queries;
}
@ -2585,7 +2584,7 @@ RewritePreprocessQuery(Query *parsetree)
rte = (RangeTblEntry *) nth(parsetree->resultRelation - 1,
parsetree->rtable);
rd = heap_openr(rte->relname);
rd = heap_openr(rte->relname, AccessShareLock);
foreach(tl, parsetree->targetList)
{
@ -2597,7 +2596,7 @@ RewritePreprocessQuery(Query *parsetree)
tle->resdom->resno = 0;
}
heap_close(rd);
heap_close(rd, AccessShareLock);
}
}

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.28 1999/07/17 20:17:39 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.29 1999/09/18 19:07:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -76,7 +76,7 @@ RemoveRewriteRule(char *ruleName)
/*
* Open the pg_rewrite relation.
*/
RewriteRelation = heap_openr(RewriteRelationName);
RewriteRelation = heap_openr(RewriteRelationName, RowExclusiveLock);
/*
* Scan the RuleRelation ('pg_rewrite') until we find a tuple
@ -90,7 +90,7 @@ RemoveRewriteRule(char *ruleName)
*/
if (!HeapTupleIsValid(tuple))
{
heap_close(RewriteRelation);
heap_close(RewriteRelation, RowExclusiveLock);
elog(ERROR, "Rule '%s' not found\n", ruleName);
}
@ -125,7 +125,7 @@ RemoveRewriteRule(char *ruleName)
heap_delete(RewriteRelation, &tuple->t_self, NULL);
pfree(tuple);
heap_close(RewriteRelation);
heap_close(RewriteRelation, RowExclusiveLock);
}
/*
@ -144,7 +144,7 @@ RelationRemoveRules(Oid relid)
/*
* Open the pg_rewrite relation.
*/
RewriteRelation = heap_openr(RewriteRelationName);
RewriteRelation = heap_openr(RewriteRelationName, RowExclusiveLock);
/*
* Scan the RuleRelation ('pg_rewrite') for all the tuples that has
@ -162,5 +162,5 @@ RelationRemoveRules(Oid relid)
heap_delete(RewriteRelation, &tuple->t_self, NULL);
heap_endscan(scanDesc);
heap_close(RewriteRelation);
heap_close(RewriteRelation, RowExclusiveLock);
}

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.36 1999/07/16 04:59:41 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.37 1999/09/18 19:07:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -40,7 +40,7 @@ RuleIdGetActionInfo(Oid ruleoid, bool *instead_flag, Query **parseTrees)
char *rule_evqual_string = NULL;
Node *rule_evqual = NULL;
ruleRelation = heap_openr(RewriteRelationName);
ruleRelation = heap_openr(RewriteRelationName, AccessShareLock);
ruleTupdesc = RelationGetDescr(ruleRelation);
ruletuple = SearchSysCacheTuple(RULOID,
ObjectIdGetDatum(ruleoid),
@ -68,7 +68,7 @@ RuleIdGetActionInfo(Oid ruleoid, bool *instead_flag, Query **parseTrees)
ruleparse = (Query *) stringToNode(ruleaction);
rule_evqual = (Node *) stringToNode(rule_evqual_string);
heap_close(ruleRelation);
heap_close(ruleRelation, AccessShareLock);
*parseTrees = ruleparse;
return rule_evqual;
@ -79,23 +79,11 @@ RuleIdGetActionInfo(Oid ruleoid, bool *instead_flag, Query **parseTrees)
int
IsDefinedRewriteRule(char *ruleName)
{
Relation RewriteRelation = NULL;
HeapTuple tuple;
/*
* Open the pg_rewrite relation.
*/
RewriteRelation = heap_openr(RewriteRelationName);
tuple = SearchSysCacheTuple(REWRITENAME,
PointerGetDatum(ruleName),
0, 0, 0);
/*
* return whether or not the rewrite rule existed
*/
heap_close(RewriteRelation);
return HeapTupleIsValid(tuple);
}
@ -111,12 +99,12 @@ setRelhasrulesInRelation(Oid relationId, bool relhasrules)
* pg_relation), find the appropriate tuple, and add the specified
* lock to it.
*/
relationRelation = heap_openr(RelationRelationName, RowExclusiveLock);
tuple = SearchSysCacheTupleCopy(RELOID,
ObjectIdGetDatum(relationId),
0, 0, 0);
Assert(HeapTupleIsValid(tuple));
relationRelation = heap_openr(RelationRelationName);
((Form_pg_class) GETSTRUCT(tuple))->relhasrules = relhasrules;
heap_replace(relationRelation, &tuple->t_self, tuple, NULL);
@ -126,7 +114,7 @@ setRelhasrulesInRelation(Oid relationId, bool relhasrules)
CatalogCloseIndices(Num_pg_class_indices, idescs);
pfree(tuple);
heap_close(relationRelation);
heap_close(relationRelation, RowExclusiveLock);
}
void
@ -162,7 +150,7 @@ prs2_addToRelation(Oid relid,
thisRule->actions = actions;
thisRule->isInstead = isInstead;
relation = heap_open(relid);
relation = heap_open(relid, AccessShareLock);
/*
* modify or create a RuleLock cached by Relation
@ -200,9 +188,7 @@ prs2_addToRelation(Oid relid,
rulelock->numLocks++;
}
heap_close(relation);
return;
heap_close(relation, AccessShareLock);
}
void
@ -214,7 +200,7 @@ prs2_deleteFromRelation(Oid relid, Oid ruleId)
int i;
MemoryContext oldcxt;
relation = heap_open(relid);
relation = heap_open(relid, AccessShareLock);
rulelock = relation->rd_rules;
Assert(rulelock != NULL);
@ -245,5 +231,5 @@ prs2_deleteFromRelation(Oid relid, Oid ruleId)
rulelock->numLocks--;
}
heap_close(relation);
heap_close(relation, AccessShareLock);
}