Skip to content

Commit f8a0516

Browse files
committed
Bgwriter should PANIC if it runs out of memory for pending-fsyncs
hash table. This is a pretty unlikely scenario, since the table should be tiny, but we can't guarantee continued correct operation if it does occur. Spotted by Qingqing Zhou.
1 parent 6d9ee03 commit f8a0516

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/backend/postmaster/bgwriter.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.15 2005/03/04 20:21:06 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.16 2005/05/28 17:21:32 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -616,7 +616,7 @@ ForwardFsyncRequest(RelFileNode rnode, BlockNumber segno)
616616
*
617617
* This is exported because it must be called during CreateCheckPoint;
618618
* we have to be sure we have accepted all pending requests *after* we
619-
* establish the checkpoint redo pointer. Since CreateCheckPoint
619+
* establish the checkpoint REDO pointer. Since CreateCheckPoint
620620
* sometimes runs in non-bgwriter processes, do nothing if not bgwriter.
621621
*/
622622
void
@@ -629,6 +629,15 @@ AbsorbFsyncRequests(void)
629629
if (!am_bg_writer)
630630
return;
631631

632+
/*
633+
* We have to PANIC if we fail to absorb all the pending requests
634+
* (eg, because our hashtable runs out of memory). This is because
635+
* the system cannot run safely if we are unable to fsync what we
636+
* have been told to fsync. Fortunately, the hashtable is so small
637+
* that the problem is quite unlikely to arise in practice.
638+
*/
639+
START_CRIT_SECTION();
640+
632641
/*
633642
* We try to avoid holding the lock for a long time by copying the
634643
* request array.
@@ -647,6 +656,9 @@ AbsorbFsyncRequests(void)
647656

648657
for (request = requests; n > 0; request++, n--)
649658
RememberFsyncRequest(request->rnode, request->segno);
659+
650660
if (requests)
651661
pfree(requests);
662+
663+
END_CRIT_SECTION();
652664
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy