aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/vacuum.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-07-31 20:09:10 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-07-31 20:09:10 +0000
commit09d3670df3e4593be1d2299a62d982829016b847 (patch)
tree7a62e91c1cf595d0334dd2c196d1c79835cc267b /src/backend/commands/vacuum.c
parent4cd72b53b9975bab5f4ca0792cf4f54c84829404 (diff)
downloadpostgresql-09d3670df3e4593be1d2299a62d982829016b847.tar.gz
postgresql-09d3670df3e4593be1d2299a62d982829016b847.zip
Change the relation_open protocol so that we obtain lock on a relation
(table or index) before trying to open its relcache entry. This fixes race conditions in which someone else commits a change to the relation's catalog entries while we are in process of doing relcache load. Problems of that ilk have been reported sporadically for years, but it was not really practical to fix until recently --- for instance, the recent addition of WAL-log support for in-place updates helped. Along the way, remove pg_am.amconcurrent: all AMs are now expected to support concurrent update.
Diffstat (limited to 'src/backend/commands/vacuum.c')
-rw-r--r--src/backend/commands/vacuum.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index eb0fce72edb..c21be2f4788 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.336 2006/07/30 02:07:18 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.337 2006/07/31 20:09:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1138,7 +1138,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
* same process.
*/
onerelid = onerel->rd_lockInfo.lockRelId;
- LockRelationForSession(&onerelid, onerel->rd_istemp, lmode);
+ LockRelationIdForSession(&onerelid, lmode);
/*
* Remember the relation's TOAST relation for later
@@ -1175,7 +1175,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
/*
* Now release the session-level lock on the master table.
*/
- UnlockRelationForSession(&onerelid, lmode);
+ UnlockRelationIdForSession(&onerelid, lmode);
return;
}
@@ -3476,6 +3476,8 @@ vac_open_indexes(Relation relation, LOCKMODE lockmode,
ListCell *indexoidscan;
int i;
+ Assert(lockmode != NoLock);
+
indexoidlist = RelationGetIndexList(relation);
*nindexes = list_length(indexoidlist);
@@ -3489,11 +3491,8 @@ vac_open_indexes(Relation relation, LOCKMODE lockmode,
foreach(indexoidscan, indexoidlist)
{
Oid indexoid = lfirst_oid(indexoidscan);
- Relation ind;
- ind = index_open(indexoid);
- (*Irel)[i++] = ind;
- LockRelation(ind, lockmode);
+ (*Irel)[i++] = index_open(indexoid, lockmode);
}
list_free(indexoidlist);
@@ -3513,9 +3512,7 @@ vac_close_indexes(int nindexes, Relation *Irel, LOCKMODE lockmode)
{
Relation ind = Irel[nindexes];
- if (lockmode != NoLock)
- UnlockRelation(ind, lockmode);
- index_close(ind);
+ index_close(ind, lockmode);
}
pfree(Irel);
}