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

Commit e674707

Browse files
committed
Minor code rationalization: FlushRelationBuffers just returns void,
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.
1 parent a843053 commit e674707

File tree

8 files changed

+24
-64
lines changed

8 files changed

+24
-64
lines changed

src/backend/access/nbtree/nbtree.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.115 2004/05/08 19:09:24 tgl Exp $
15+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.116 2004/05/31 19:24:04 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -784,8 +784,6 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
784784
}
785785
if (new_pages != num_pages)
786786
{
787-
int i;
788-
789787
/*
790788
* Okay to truncate.
791789
*
@@ -795,9 +793,7 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
795793
* blocks we aren't deleting, but it's the closest thing in
796794
* bufmgr's API.
797795
*/
798-
i = FlushRelationBuffers(rel, new_pages);
799-
if (i < 0)
800-
elog(ERROR, "FlushRelationBuffers returned %d", i);
796+
FlushRelationBuffers(rel, new_pages);
801797

802798
/*
803799
* Do the physical truncation.

src/backend/catalog/heap.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.265 2004/05/26 04:41:07 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.266 2004/05/31 19:24:05 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1175,7 +1175,6 @@ void
11751175
heap_drop_with_catalog(Oid rid)
11761176
{
11771177
Relation rel;
1178-
int i;
11791178

11801179
/*
11811180
* Open and lock the relation.
@@ -1186,9 +1185,7 @@ heap_drop_with_catalog(Oid rid)
11861185
* Release all buffers that belong to this relation, after writing any
11871186
* that are dirty
11881187
*/
1189-
i = FlushRelationBuffers(rel, (BlockNumber) 0);
1190-
if (i < 0)
1191-
elog(ERROR, "FlushRelationBuffers returned %d", i);
1188+
FlushRelationBuffers(rel, (BlockNumber) 0);
11921189

11931190
/*
11941191
* remove inheritance information

src/backend/catalog/index.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.232 2004/05/26 04:41:07 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.233 2004/05/31 19:24:05 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -766,7 +766,6 @@ index_drop(Oid indexId)
766766
Relation indexRelation;
767767
HeapTuple tuple;
768768
bool hasexprs;
769-
int i;
770769

771770
Assert(OidIsValid(indexId));
772771

@@ -826,9 +825,7 @@ index_drop(Oid indexId)
826825
/*
827826
* flush buffer cache and physically remove the file
828827
*/
829-
i = FlushRelationBuffers(userIndexRelation, (BlockNumber) 0);
830-
if (i < 0)
831-
elog(ERROR, "FlushRelationBuffers returned %d", i);
828+
FlushRelationBuffers(userIndexRelation, (BlockNumber) 0);
832829

833830
if (userIndexRelation->rd_smgr == NULL)
834831
userIndexRelation->rd_smgr = smgropen(userIndexRelation->rd_node);

src/backend/commands/cluster.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.124 2004/05/26 04:41:10 neilc Exp $
14+
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.125 2004/05/31 19:24:05 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -660,7 +660,6 @@ swap_relfilenodes(Oid r1, Oid r2)
660660
Form_pg_class relform1,
661661
relform2;
662662
Oid swaptemp;
663-
int i;
664663
CatalogIndexState indstate;
665664

666665
/* We need writable copies of both pg_class tuples. */
@@ -687,15 +686,11 @@ swap_relfilenodes(Oid r1, Oid r2)
687686
* forget about'em. (XXX this might not be necessary anymore?)
688687
*/
689688
rel = relation_open(r1, NoLock);
690-
i = FlushRelationBuffers(rel, 0);
691-
if (i < 0)
692-
elog(ERROR, "FlushRelationBuffers returned %d", i);
689+
FlushRelationBuffers(rel, 0);
693690
relation_close(rel, NoLock);
694691

695692
rel = relation_open(r2, NoLock);
696-
i = FlushRelationBuffers(rel, 0);
697-
if (i < 0)
698-
elog(ERROR, "FlushRelationBuffers returned %d", i);
693+
FlushRelationBuffers(rel, 0);
699694
relation_close(rel, NoLock);
700695

701696
/*

src/backend/commands/vacuum.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.278 2004/05/26 04:41:12 neilc Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.279 2004/05/31 19:24:05 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -1031,9 +1031,7 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
10311031
* tuples have correct on-row commit status on disk (see
10321032
* bufmgr.c's comments for FlushRelationBuffers()).
10331033
*/
1034-
i = FlushRelationBuffers(onerel, vacrelstats->rel_pages);
1035-
if (i < 0)
1036-
elog(ERROR, "FlushRelationBuffers returned %d", i);
1034+
FlushRelationBuffers(onerel, vacrelstats->rel_pages);
10371035
}
10381036
}
10391037

@@ -2542,9 +2540,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
25422540
* tuples have correct on-row commit status on disk (see bufmgr.c's
25432541
* comments for FlushRelationBuffers()).
25442542
*/
2545-
i = FlushRelationBuffers(onerel, blkno);
2546-
if (i < 0)
2547-
elog(ERROR, "FlushRelationBuffers returned %d", i);
2543+
FlushRelationBuffers(onerel, blkno);
25482544

25492545
/* truncate relation, if needed */
25502546
if (blkno < nblocks)
@@ -2606,9 +2602,7 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages)
26062602
Assert(vacrelstats->rel_pages >= vacuum_pages->empty_end_pages);
26072603
relblocks = vacrelstats->rel_pages - vacuum_pages->empty_end_pages;
26082604

2609-
i = FlushRelationBuffers(onerel, relblocks);
2610-
if (i < 0)
2611-
elog(ERROR, "FlushRelationBuffers returned %d", i);
2605+
FlushRelationBuffers(onerel, relblocks);
26122606

26132607
/* truncate relation if there are some empty end-pages */
26142608
if (vacuum_pages->empty_end_pages > 0)

src/backend/commands/vacuumlazy.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
*
3333
* IDENTIFICATION
34-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.40 2004/05/08 19:09:25 tgl Exp $
34+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.41 2004/05/31 19:24:05 tgl Exp $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -731,9 +731,7 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
731731
* will also write out dirty buffers for blocks we aren't deleting,
732732
* but it's the closest thing in bufmgr's API.
733733
*/
734-
i = FlushRelationBuffers(onerel, new_rel_pages);
735-
if (i < 0)
736-
elog(ERROR, "FlushRelationBuffers returned %d", i);
734+
FlushRelationBuffers(onerel, new_rel_pages);
737735

738736
/*
739737
* Do the physical truncation.

src/backend/storage/buffer/bufmgr.c

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.167 2004/05/31 03:48:02 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.168 2004/05/31 19:24:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1287,9 +1287,7 @@ PrintPinnedBufs(void)
12871287
*
12881288
* This function writes all dirty pages of a relation out to disk.
12891289
* Furthermore, pages that have blocknumber >= firstDelBlock are
1290-
* actually removed from the buffer pool. An error code is returned
1291-
* if we fail to dump a dirty buffer or if we find one of
1292-
* the target pages is pinned into the cache.
1290+
* actually removed from the buffer pool.
12931291
*
12941292
* This is called by DROP TABLE to clear buffers for the relation
12951293
* from the buffer pool. Note that we must write dirty buffers,
@@ -1319,13 +1317,11 @@ PrintPinnedBufs(void)
13191317
* to still be present in the cache due to failure of an earlier
13201318
* transaction. So, must flush dirty buffers without complaint.
13211319
*
1322-
* Returns: 0 - Ok, -1 - FAILED TO CLEAR DIRTY BIT, -2 - PINNED
1323-
*
13241320
* XXX currently it sequentially searches the buffer pool, should be
13251321
* changed to more clever ways of searching.
13261322
* --------------------------------------------------------------------
13271323
*/
1328-
int
1324+
void
13291325
FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
13301326
{
13311327
int i;
@@ -1364,18 +1360,15 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
13641360
error_context_stack = errcontext.previous;
13651361
}
13661362
if (LocalRefCount[i] > 0)
1367-
{
1368-
elog(WARNING, "FlushRelationBuffers(\"%s\" (local), %u): block %u is referenced (%d)",
1363+
elog(ERROR, "FlushRelationBuffers(\"%s\" (local), %u): block %u is referenced (%d)",
13691364
RelationGetRelationName(rel), firstDelBlock,
13701365
bufHdr->tag.blockNum, LocalRefCount[i]);
1371-
return (-2);
1372-
}
13731366
if (bufHdr->tag.blockNum >= firstDelBlock)
13741367
bufHdr->tag.rnode.relNode = InvalidOid;
13751368
}
13761369
}
13771370

1378-
return 0;
1371+
return;
13791372
}
13801373

13811374
LWLockAcquire(BufMgrLock, LW_EXCLUSIVE);
@@ -1403,31 +1396,21 @@ FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock)
14031396
}
14041397
UnpinBuffer(bufHdr);
14051398
if (bufHdr->flags & BM_DIRTY || bufHdr->cntxDirty)
1406-
{
1407-
LWLockRelease(BufMgrLock);
1408-
elog(WARNING, "FlushRelationBuffers(\"%s\", %u): block %u was re-dirtied",
1399+
elog(ERROR, "FlushRelationBuffers(\"%s\", %u): block %u was re-dirtied",
14091400
RelationGetRelationName(rel), firstDelBlock,
14101401
bufHdr->tag.blockNum);
1411-
return -1;
1412-
}
14131402
}
14141403
if (bufHdr->refcount != 0)
1415-
{
1416-
LWLockRelease(BufMgrLock);
1417-
elog(WARNING, "FlushRelationBuffers(\"%s\", %u): block %u is referenced (private %d, global %u)",
1404+
elog(ERROR, "FlushRelationBuffers(\"%s\", %u): block %u is referenced (private %d, global %u)",
14181405
RelationGetRelationName(rel), firstDelBlock,
14191406
bufHdr->tag.blockNum,
14201407
PrivateRefCount[i], bufHdr->refcount);
1421-
return -2;
1422-
}
14231408
if (bufHdr->tag.blockNum >= firstDelBlock)
14241409
StrategyInvalidateBuffer(bufHdr);
14251410
}
14261411
}
14271412

14281413
LWLockRelease(BufMgrLock);
1429-
1430-
return 0;
14311414
}
14321415

14331416
/*

src/include/storage/bufmgr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.81 2004/05/31 03:48:10 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.82 2004/05/31 19:24:05 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -152,7 +152,7 @@ extern void FlushBufferPool(void);
152152
extern BlockNumber BufferGetBlockNumber(Buffer buffer);
153153
extern BlockNumber RelationGetNumberOfBlocks(Relation relation);
154154
extern void RelationTruncate(Relation rel, BlockNumber nblocks);
155-
extern int FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock);
155+
extern void FlushRelationBuffers(Relation rel, BlockNumber firstDelBlock);
156156
extern void DropRelationBuffers(Relation rel);
157157
extern void DropRelFileNodeBuffers(RelFileNode rnode, bool istemp,
158158
BlockNumber firstDelBlock);

0 commit comments

Comments
 (0)