diff options
Diffstat (limited to 'src/backend/access/heap/hio.c')
-rw-r--r-- | src/backend/access/heap/hio.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c index 9c7d72a7e4e..fe7c1069edc 100644 --- a/src/backend/access/heap/hio.c +++ b/src/backend/access/heap/hio.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Id: hio.c,v 1.50 2003/09/25 06:57:57 petere Exp $ + * $Id: hio.c,v 1.50.2.1 2005/05/07 21:33:21 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -247,13 +247,6 @@ RelationGetBufferForTuple(Relation relation, Size len, buffer = ReadBuffer(relation, P_NEW); /* - * Release the file-extension lock; it's now OK for someone else to - * extend the relation some more. - */ - if (needLock) - UnlockPage(relation, 0, ExclusiveLock); - - /* * We can be certain that locking the otherBuffer first is OK, since * it must have a lower page number. */ @@ -261,9 +254,22 @@ RelationGetBufferForTuple(Relation relation, Size len, LockBuffer(otherBuffer, BUFFER_LOCK_EXCLUSIVE); /* - * We need to initialize the empty new page. + * Now acquire lock on the new page. */ LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); + + /* + * Release the file-extension lock; it's now OK for someone else to + * extend the relation some more. Note that we cannot release this + * lock before we have buffer lock on the new page, or we risk a + * race condition against vacuumlazy.c --- see comments therein. + */ + if (needLock) + UnlockPage(relation, 0, ExclusiveLock); + + /* + * We need to initialize the empty new page. + */ pageHeader = (Page) BufferGetPage(buffer); Assert(PageIsNew((PageHeader) pageHeader)); PageInit(pageHeader, BufferGetPageSize(buffer), 0); |