Convert Assert checking for empty page into a regular test and elog.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 6 Jan 2006 00:15:50 +0000 (00:15 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 6 Jan 2006 00:15:50 +0000 (00:15 +0000)
The consequences of overwriting a non-empty page are bad enough that
we should not omit this test in production builds.

src/backend/access/heap/hio.c

index d66c43c3021f3d4cf7def04c0a40cdeb91c27ffb..c2a9b34336e2e5ff846f21b2437f3b40e5c44526 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/heap/hio.c,v 1.59 2005/11/22 18:17:06 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/heap/hio.c,v 1.60 2006/01/06 00:15:50 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -281,10 +281,17 @@ RelationGetBufferForTuple(Relation relation, Size len,
                UnlockRelationForExtension(relation, ExclusiveLock);
 
        /*
-        * We need to initialize the empty new page.
+        * 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))