From: Tom Lane Date: Fri, 6 Jan 2006 00:16:09 +0000 (+0000) Subject: Convert Assert checking for empty page into a regular test and elog. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=c80137b34c74361e0554add92350c7f7df148403;p=users%2Fbernd%2Fpostgres.git Convert Assert checking for empty page into a regular test and elog. The consequences of overwriting a non-empty page are bad enough that we should not omit this test in production builds. --- diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c index 5a950ddf37..2546e72c62 100644 --- a/src/backend/access/heap/hio.c +++ b/src/backend/access/heap/hio.c @@ -246,13 +246,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,11 +254,31 @@ 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. Double-check that it really + * is empty (this should never happen, but if it does we don't want to + * risk wiping out valid data). + */ pageHeader = (Page) BufferGetPage(buffer); - Assert(PageIsNew((PageHeader) pageHeader)); + + if (!PageIsNew((PageHeader) pageHeader)) + elog(ERROR, "page %u of relation \"%s\" should be empty but is not", + BufferGetBlockNumber(buffer), + RelationGetRelationName(relation)); + PageInit(pageHeader, BufferGetPageSize(buffer), 0); if (len > PageGetFreeSpace(pageHeader))