Minor code rationalization: FlushRelationBuffers just returns void,
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 31 May 2004 19:24:05 +0000 (19:24 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 31 May 2004 19:24:05 +0000 (19:24 +0000)
rather than an error code, and does elog(ERROR) not elog(WARNING)
when it detects a problem.  All callers were simply elog(ERROR)'ing on
failure return anyway, and I find it hard to envision a caller that would
not, so we may as well simplify the callers and produce the more useful
error message directly.

src/backend/access/nbtree/nbtree.c
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/commands/cluster.c
src/backend/commands/vacuum.c
src/backend/commands/vacuumlazy.c
src/backend/storage/buffer/bufmgr.c
src/include/storage/bufmgr.h

index ededa6231de3bc97d9c61db3d8819d63185f4fb3..f89ec91caf3d46d009d9486f4bad99251d05edb4 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.115 2004/05/08 19:09:24 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.116 2004/05/31 19:24:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -784,8 +784,6 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
        }
        if (new_pages != num_pages)
        {
-           int         i;
-
            /*
             * Okay to truncate.
             *
@@ -795,9 +793,7 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
             * blocks we aren't deleting, but it's the closest thing in
             * bufmgr's API.
             */
-           i = FlushRelationBuffers(rel, new_pages);
-           if (i < 0)
-               elog(ERROR, "FlushRelationBuffers returned %d", i);
+           FlushRelationBuffers(rel, new_pages);
 
            /*
             * Do the physical truncation.
index a7ffe38b53155f1611f7a4104d7c843ecd785c47..d67d62053118747d86b1ce14ec8b8404d8a6bcae 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.265 2004/05/26 04:41:07 neilc Exp $
+ *   $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.266 2004/05/31 19:24:05 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -1175,7 +1175,6 @@ void
 heap_drop_with_catalog(Oid rid)
 {
    Relation    rel;
-   int         i;
 
    /*
     * Open and lock the relation.
@@ -1186,9 +1185,7 @@ heap_drop_with_catalog(Oid rid)
     * Release all buffers that belong to this relation, after writing any
     * that are dirty
     */
-   i = FlushRelationBuffers(rel, (BlockNumber) 0);
-   if (i < 0)
-       elog(ERROR, "FlushRelationBuffers returned %d", i);
+   FlushRelationBuffers(rel, (BlockNumber) 0);
 
    /*
     * remove inheritance information
index 0ccecac66808f7986c7886255bc7c6c7aae1daab..8ada0915bd29a9fa1e603b4a8fd39e5dd6b77458 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.232 2004/05/26 04:41:07 neilc Exp $
+ *   $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.233 2004/05/31 19:24:05 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -766,7 +766,6 @@ index_drop(Oid indexId)
    Relation    indexRelation;
    HeapTuple   tuple;
    bool        hasexprs;
-   int         i;
 
    Assert(OidIsValid(indexId));
 
@@ -826,9 +825,7 @@ index_drop(Oid indexId)
    /*
     * flush buffer cache and physically remove the file
     */
-   i = FlushRelationBuffers(userIndexRelation, (BlockNumber) 0);
-   if (i < 0)
-       elog(ERROR, "FlushRelationBuffers returned %d", i);
+   FlushRelationBuffers(userIndexRelation, (BlockNumber) 0);
 
    if (userIndexRelation->rd_smgr == NULL)
        userIndexRelation->rd_smgr = smgropen(userIndexRelation->rd_node);
index d9c4397176b9f50ac2985bf0a7cb892626910497..0483eaf2d3c33a17f142762baa7e0e8075089072 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.124 2004/05/26 04:41:10 neilc Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.125 2004/05/31 19:24:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -660,7 +660,6 @@ swap_relfilenodes(Oid r1, Oid r2)
    Form_pg_class relform1,
                relform2;
    Oid         swaptemp;
-   int         i;
    CatalogIndexState indstate;
 
    /* We need writable copies of both pg_class tuples. */
@@ -687,15 +686,11 @@ swap_relfilenodes(Oid r1, Oid r2)
     * forget about'em.  (XXX this might not be necessary anymore?)
     */
    rel = relation_open(r1, NoLock);
-   i = FlushRelationBuffers(rel, 0);
-   if (i < 0)
-       elog(ERROR, "FlushRelationBuffers returned %d", i);
+   FlushRelationBuffers(rel, 0);
    relation_close(rel, NoLock);
 
    rel = relation_open(r2, NoLock);
-   i = FlushRelationBuffers(rel, 0);
-   if (i < 0)
-       elog(ERROR, "FlushRelationBuffers returned %d", i);
+   FlushRelationBuffers(rel, 0);
    relation_close(rel, NoLock);
 
    /*
index b2ebda8e975b4af405c732ac30a3c8c44bc57e26..aa6491af1c0eda0dc771dc545b49a5b076237c6f 100644 (file)
@@ -13,7 +13,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.278 2004/05/26 04:41:12 neilc Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.279 2004/05/31 19:24:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1031,9 +1031,7 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
             * tuples have correct on-row commit status on disk (see
             * bufmgr.c's comments for FlushRelationBuffers()).
             */
-           i = FlushRelationBuffers(onerel, vacrelstats->rel_pages);
-           if (i < 0)
-               elog(ERROR, "FlushRelationBuffers returned %d", i);
+           FlushRelationBuffers(onerel, vacrelstats->rel_pages);
        }
    }
 
@@ -2542,9 +2540,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
     * tuples have correct on-row commit status on disk (see bufmgr.c's
     * comments for FlushRelationBuffers()).
     */
-   i = FlushRelationBuffers(onerel, blkno);
-   if (i < 0)
-       elog(ERROR, "FlushRelationBuffers returned %d", i);
+   FlushRelationBuffers(onerel, blkno);
 
    /* truncate relation, if needed */
    if (blkno < nblocks)
@@ -2606,9 +2602,7 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages)
    Assert(vacrelstats->rel_pages >= vacuum_pages->empty_end_pages);
    relblocks = vacrelstats->rel_pages - vacuum_pages->empty_end_pages;
 
-   i = FlushRelationBuffers(onerel, relblocks);
-   if (i < 0)
-       elog(ERROR, "FlushRelationBuffers returned %d", i);
+   FlushRelationBuffers(onerel, relblocks);
 
    /* truncate relation if there are some empty end-pages */
    if (vacuum_pages->empty_end_pages > 0)
index af1b646be467e619a558510d3fd6752ad2374f6d..f67c1c76feec9086fbc833e3ebc8072b521e9f52 100644 (file)
@@ -31,7 +31,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.40 2004/05/08 19:09:25 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.41 2004/05/31 19:24:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -731,9 +731,7 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
     * will also write out dirty buffers for blocks we aren't deleting,
     * but it's the closest thing in bufmgr's API.
     */
-   i = FlushRelationBuffers(onerel, new_rel_pages);
-   if (i < 0)
-       elog(ERROR, "FlushRelationBuffers returned %d", i);
+   FlushRelationBuffers(onerel, new_rel_pages);
 
    /*
     * Do the physical truncation.
index 2386bc89bf3b7eaf22be77b5448924e89529412f..bc6c0f6993cbd029a991d1810bdce63ca4a3bacc 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.167 2004/05/31 03:48:02 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.168 2004/05/31 19:24:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1287,9 +1287,7 @@ PrintPinnedBufs(void)
  *
  *     This function writes all dirty pages of a relation out to disk.
  *     Furthermore, pages that have blocknumber >= firstDelBlock are
- *     actually removed from the buffer pool.  An error code is returned
- *     if we fail to dump a dirty buffer or if we find one of
- *     the target pages is pinned into the cache.
+ *     actually removed from the buffer pool.
  *
  *     This is called by DROP TABLE to clear buffers for the relation
  *     from the buffer pool.  Note that we must write dirty buffers,
@@ -1319,13 +1317,11 @@ PrintPinnedBufs(void)
  *     to still be present in the cache due to failure of an earlier
  *     transaction.  So, must flush dirty buffers without complaint.
  *
- *     Returns: 0 - Ok, -1 - FAILED TO CLEAR DIRTY BIT, -2 - PINNED
- *
  *     XXX currently it sequentially searches the buffer pool, should be
  *     changed to more clever ways of searching.
  * --------------------------------------------------------------------
  */
-int
+void
 FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
 {
    int         i;
@@ -1364,18 +1360,15 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
                    error_context_stack = errcontext.previous;
                }
                if (LocalRefCount[i] > 0)
-               {
-                   elog(WARNING, "FlushRelationBuffers(\"%s\" (local), %u): block %u is referenced (%d)",
+                   elog(ERROR, "FlushRelationBuffers(\"%s\" (local), %u): block %u is referenced (%d)",
                         RelationGetRelationName(rel), firstDelBlock,
                         bufHdr->tag.blockNum, LocalRefCount[i]);
-                   return (-2);
-               }
                if (bufHdr->tag.blockNum >= firstDelBlock)
                    bufHdr->tag.rnode.relNode = InvalidOid;
            }
        }
 
-       return 0;
+       return;
    }
 
    LWLockAcquire(BufMgrLock, LW_EXCLUSIVE);
@@ -1403,31 +1396,21 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
                }
                UnpinBuffer(bufHdr);
                if (bufHdr->flags & BM_DIRTY || bufHdr->cntxDirty)
-               {
-                   LWLockRelease(BufMgrLock);
-                   elog(WARNING, "FlushRelationBuffers(\"%s\", %u): block %u was re-dirtied",
+                   elog(ERROR, "FlushRelationBuffers(\"%s\", %u): block %u was re-dirtied",
                         RelationGetRelationName(rel), firstDelBlock,
                         bufHdr->tag.blockNum);
-                   return -1;
-               }
            }
            if (bufHdr->refcount != 0)
-           {
-               LWLockRelease(BufMgrLock);
-               elog(WARNING, "FlushRelationBuffers(\"%s\", %u): block %u is referenced (private %d, global %u)",
+               elog(ERROR, "FlushRelationBuffers(\"%s\", %u): block %u is referenced (private %d, global %u)",
                     RelationGetRelationName(rel), firstDelBlock,
                     bufHdr->tag.blockNum,
                     PrivateRefCount[i], bufHdr->refcount);
-               return -2;
-           }
            if (bufHdr->tag.blockNum >= firstDelBlock)
                StrategyInvalidateBuffer(bufHdr);
        }
    }
 
    LWLockRelease(BufMgrLock);
-
-   return 0;
 }
 
 /*
index 95b426bb8b93f21faa93c2069167eb8fe048ea49..7defaf93f885c782e213d3316004e5e9c4aa8b5a 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.81 2004/05/31 03:48:10 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.82 2004/05/31 19:24:05 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -152,7 +152,7 @@ extern void FlushBufferPool(void);
 extern BlockNumber BufferGetBlockNumber(Buffer buffer);
 extern BlockNumber RelationGetNumberOfBlocks(Relation relation);
 extern void RelationTruncate(Relation rel, BlockNumber nblocks);
-extern int FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock);
+extern void FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock);
 extern void DropRelationBuffers(Relation rel);
 extern void DropRelFileNodeBuffers(RelFileNode rnode, bool istemp,
                                   BlockNumber firstDelBlock);