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

Commit 1c72d0d

Browse files
committed
Fix relcache to account properly for subtransaction status of 'new'
relcache entries. Also, change TransactionIdIsCurrentTransactionId() so that if consulted during transaction abort, it will not say that the aborted xact is still current. (It would be better to ensure that it's never called at all during abort, but I'm not sure we can easily guarantee that.) In combination, these fix a crash we have seen occasionally during parallel regression tests of 8.0.
1 parent f900af7 commit 1c72d0d

File tree

7 files changed

+132
-55
lines changed

7 files changed

+132
-55
lines changed

src/backend/access/hash/hashpage.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.43 2003/11/29 19:51:40 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.44 2004/08/28 20:31:43 tgl Exp $
1212
*
1313
* NOTES
1414
* Postgres hash pages look like ordinary relation pages. The opaque
@@ -44,14 +44,12 @@ static void _hash_splitbucket(Relation rel, Buffer metabuf,
4444

4545
/*
4646
* We use high-concurrency locking on hash indexes (see README for an overview
47-
* of the locking rules). There are two cases in which we don't do locking.
48-
* One is when the index is newly created in the current transaction. Since
49-
* the creating transaction has not committed, no one else can see the index,
50-
* and there's no reason to take locks. The second case is for temp
51-
* relations, which no one else can see either. (We still take buffer-level
52-
* locks, but not lmgr locks.)
47+
* of the locking rules). However, we can skip taking lmgr locks when the
48+
* index is local to the current backend (ie, either temp or new in the
49+
* current transaction). No one else can see it, so there's no reason to
50+
* take locks. We still take buffer-level locks, but not lmgr locks.
5351
*/
54-
#define USELOCKING(rel) (!((rel)->rd_isnew || (rel)->rd_istemp))
52+
#define USELOCKING(rel) (!RELATION_IS_LOCAL(rel))
5553

5654

5755
/*

src/backend/access/heap/hio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/hio.c,v 1.51 2003/11/29 22:39:39 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/hio.c,v 1.52 2004/08/28 20:31:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -232,7 +232,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
232232
* page. We can skip locking for new or temp relations, however,
233233
* since no one else could be accessing them.
234234
*/
235-
needLock = !(relation->rd_isnew || relation->rd_istemp);
235+
needLock = !RELATION_IS_LOCAL(relation);
236236

237237
if (needLock)
238238
LockPage(relation, 0, ExclusiveLock);

src/backend/access/nbtree/nbtpage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.77 2004/07/21 22:31:20 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.78 2004/08/28 20:31:43 tgl Exp $
1313
*
1414
* NOTES
1515
* Postgres btree pages look like ordinary relation pages. The opaque
@@ -483,7 +483,7 @@ _bt_getbuf(Relation rel, BlockNumber blkno, int access)
483483
* new page. We can skip locking for new or temp relations,
484484
* however, since no one else could be accessing them.
485485
*/
486-
needLock = !(rel->rd_isnew || rel->rd_istemp);
486+
needLock = !RELATION_IS_LOCAL(rel);
487487

488488
if (needLock)
489489
LockPage(rel, 0, ExclusiveLock);

src/backend/access/transam/xact.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.179 2004/08/25 18:43:42 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.180 2004/08/28 20:31:43 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -40,6 +40,7 @@
4040
#include "utils/inval.h"
4141
#include "utils/memutils.h"
4242
#include "utils/portal.h"
43+
#include "utils/relcache.h"
4344
#include "utils/resowner.h"
4445
#include "pgstat.h"
4546

@@ -352,7 +353,7 @@ GetCurrentTransactionNestLevel(void)
352353
bool
353354
TransactionIdIsCurrentTransactionId(TransactionId xid)
354355
{
355-
TransactionState s = CurrentTransactionState;
356+
TransactionState s;
356357

357358
if (AMI_OVERRIDE)
358359
{
@@ -363,21 +364,23 @@ TransactionIdIsCurrentTransactionId(TransactionId xid)
363364
/*
364365
* We will return true for the Xid of the current subtransaction,
365366
* any of its subcommitted children, any of its parents, or any of
366-
* their previously subcommitted children.
367+
* their previously subcommitted children. However, a transaction
368+
* being aborted is no longer "current", even though it may still
369+
* have an entry on the state stack.
367370
*/
368-
while (s != NULL)
371+
for (s = CurrentTransactionState; s != NULL; s = s->parent)
369372
{
370373
ListCell *cell;
371374

375+
if (s->state == TRANS_ABORT)
376+
continue;
372377
if (TransactionIdEquals(xid, s->transactionIdData))
373378
return true;
374379
foreach(cell, s->childXids)
375380
{
376381
if (TransactionIdEquals(xid, lfirst_xid(cell)))
377382
return true;
378383
}
379-
380-
s = s->parent;
381384
}
382385

383386
return false;
@@ -2997,6 +3000,8 @@ CommitSubTransaction(void)
29973000
ResourceOwnerRelease(s->curTransactionOwner,
29983001
RESOURCE_RELEASE_BEFORE_LOCKS,
29993002
true, false);
3003+
AtEOSubXact_RelationCache(true, s->transactionIdData,
3004+
s->parent->transactionIdData);
30003005
AtEOSubXact_Inval(true);
30013006
ResourceOwnerRelease(s->curTransactionOwner,
30023007
RESOURCE_RELEASE_LOCKS,
@@ -3090,6 +3095,8 @@ AbortSubTransaction(void)
30903095
ResourceOwnerRelease(s->curTransactionOwner,
30913096
RESOURCE_RELEASE_BEFORE_LOCKS,
30923097
false, false);
3098+
AtEOSubXact_RelationCache(false, s->transactionIdData,
3099+
s->parent->transactionIdData);
30933100
AtEOSubXact_Inval(false);
30943101
ResourceOwnerRelease(s->curTransactionOwner,
30953102
RESOURCE_RELEASE_LOCKS,

0 commit comments

Comments
 (0)