Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8875d09

Browse files
committed
Fix oversight in coding of _bt_start_vacuum: we can't assume that the LWLock
will be released by transaction abort before _bt_end_vacuum gets called. If either of these "can't happen" errors actually happened, we'd freeze up trying to acquire an already-held lock. Latest word is that this does not explain Martin Pitt's trouble report, but it still looks like a bug.
1 parent 452427d commit 8875d09

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/backend/access/nbtree/nbtutils.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.82 2007/01/09 02:14:10 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.83 2007/03/30 00:12:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1214,13 +1214,25 @@ _bt_start_vacuum(Relation rel)
12141214
vac = &btvacinfo->vacuums[i];
12151215
if (vac->relid.relId == rel->rd_lockInfo.lockRelId.relId &&
12161216
vac->relid.dbId == rel->rd_lockInfo.lockRelId.dbId)
1217+
{
1218+
/*
1219+
* Unlike most places in the backend, we have to explicitly
1220+
* release our LWLock before throwing an error. This is because
1221+
* we expect _bt_end_vacuum() to be called before transaction
1222+
* abort cleanup can run to release LWLocks.
1223+
*/
1224+
LWLockRelease(BtreeVacuumLock);
12171225
elog(ERROR, "multiple active vacuums for index \"%s\"",
12181226
RelationGetRelationName(rel));
1227+
}
12191228
}
12201229

12211230
/* OK, add an entry */
12221231
if (btvacinfo->num_vacuums >= btvacinfo->max_vacuums)
1232+
{
1233+
LWLockRelease(BtreeVacuumLock);
12231234
elog(ERROR, "out of btvacinfo slots");
1235+
}
12241236
vac = &btvacinfo->vacuums[btvacinfo->num_vacuums];
12251237
vac->relid = rel->rd_lockInfo.lockRelId;
12261238
vac->cycleid = result;

0 commit comments

Comments
 (0)