Commit 58d4f951 authored by Hiroshi Inoue's avatar Hiroshi Inoue

Ensure to hold an exclusive lock while reindexing a relation.

This is mainly to help developers to understand the code.
parent 9df188bc
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.159 2001/08/10 18:57:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.160 2001/08/17 23:50:00 inoue Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -2016,11 +2016,16 @@ reindex_relation(Oid relid, bool force) ...@@ -2016,11 +2016,16 @@ reindex_relation(Oid relid, bool force)
if (IsIgnoringSystemIndexes()) if (IsIgnoringSystemIndexes())
upd_pg_class_inplace = true; upd_pg_class_inplace = true;
/*
* Ensure to hold an exclusive lock throughout the
* transaction. The lock could be less intensive
* but now it's AccessExclusiveLock for simplicity.
*/
rel = heap_open(relid, AccessExclusiveLock);
/* /*
* ignore the indexes of the target system relation while processing * ignore the indexes of the target system relation while processing
* reindex. * reindex.
*/ */
rel = RelationIdGetRelation(relid);
if (!IsIgnoringSystemIndexes() && IsSystemRelationName(NameStr(rel->rd_rel->relname))) if (!IsIgnoringSystemIndexes() && IsSystemRelationName(NameStr(rel->rd_rel->relname)))
deactivate_needed = true; deactivate_needed = true;
#ifndef ENABLE_REINDEX_NAILED_RELATIONS #ifndef ENABLE_REINDEX_NAILED_RELATIONS
...@@ -2055,7 +2060,10 @@ reindex_relation(Oid relid, bool force) ...@@ -2055,7 +2060,10 @@ reindex_relation(Oid relid, bool force)
else else
elog(ERROR, "the target relation %u is shared", relid); elog(ERROR, "the target relation %u is shared", relid);
} }
RelationClose(rel); /*
* Continue to hold the lock.
*/
heap_close(rel, NoLock);
old = SetReindexProcessing(true); old = SetReindexProcessing(true);
if (deactivate_needed) if (deactivate_needed)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment