77 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
10- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.185 2005/04/15 18:48:10 tgl Exp $
10+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.186 2005/04/15 22:19:48 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -1152,6 +1152,9 @@ XLogWrite(XLogwrtRqst WriteRqst)
11521152 bool ispartialpage ;
11531153 bool use_existent ;
11541154
1155+ /* We should always be inside a critical section here */
1156+ Assert (CritSectionCount > 0 );
1157+
11551158 /*
11561159 * Update local LogwrtResult (caller probably did this already,
11571160 * but...)
@@ -1501,6 +1504,11 @@ XLogFlush(XLogRecPtr record)
15011504 * caller must *not* hold the lock at call.
15021505 *
15031506 * Returns FD of opened file.
1507+ *
1508+ * Note: errors here are ERROR not PANIC because we might or might not be
1509+ * inside a critical section (eg, during checkpoint there is no reason to
1510+ * take down the system on failure). They will promote to PANIC if we are
1511+ * in a critical section.
15041512 */
15051513static int
15061514XLogFileInit (uint32 log , uint32 seg ,
@@ -1528,7 +1536,7 @@ XLogFileInit(uint32 log, uint32 seg,
15281536 if (fd < 0 )
15291537 {
15301538 if (errno != ENOENT )
1531- ereport (PANIC ,
1539+ ereport (ERROR ,
15321540 (errcode_for_file_access (),
15331541 errmsg ("could not open file \"%s\" (log file %u, segment %u): %m" ,
15341542 path , log , seg )));
@@ -1551,7 +1559,7 @@ XLogFileInit(uint32 log, uint32 seg,
15511559 fd = BasicOpenFile (tmppath , O_RDWR | O_CREAT | O_EXCL | PG_BINARY ,
15521560 S_IRUSR | S_IWUSR );
15531561 if (fd < 0 )
1554- ereport (PANIC ,
1562+ ereport (ERROR ,
15551563 (errcode_for_file_access (),
15561564 errmsg ("could not create file \"%s\": %m" , tmppath )));
15571565
@@ -1580,19 +1588,19 @@ XLogFileInit(uint32 log, uint32 seg,
15801588 /* if write didn't set errno, assume problem is no disk space */
15811589 errno = save_errno ? save_errno : ENOSPC ;
15821590
1583- ereport (PANIC ,
1591+ ereport (ERROR ,
15841592 (errcode_for_file_access (),
15851593 errmsg ("could not write to file \"%s\": %m" , tmppath )));
15861594 }
15871595 }
15881596
15891597 if (pg_fsync (fd ) != 0 )
1590- ereport (PANIC ,
1598+ ereport (ERROR ,
15911599 (errcode_for_file_access (),
15921600 errmsg ("could not fsync file \"%s\": %m" , tmppath )));
15931601
15941602 if (close (fd ))
1595- ereport (PANIC ,
1603+ ereport (ERROR ,
15961604 (errcode_for_file_access (),
15971605 errmsg ("could not close file \"%s\": %m" , tmppath )));
15981606
@@ -1622,7 +1630,7 @@ XLogFileInit(uint32 log, uint32 seg,
16221630 fd = BasicOpenFile (path , O_RDWR | PG_BINARY | XLOG_SYNC_BIT ,
16231631 S_IRUSR | S_IWUSR );
16241632 if (fd < 0 )
1625- ereport (PANIC ,
1633+ ereport (ERROR ,
16261634 (errcode_for_file_access (),
16271635 errmsg ("could not open file \"%s\" (log file %u, segment %u): %m" ,
16281636 path , log , seg )));
@@ -1659,7 +1667,7 @@ XLogFileCopy(uint32 log, uint32 seg,
16591667 XLogFilePath (path , srcTLI , srclog , srcseg );
16601668 srcfd = BasicOpenFile (path , O_RDONLY | PG_BINARY , 0 );
16611669 if (srcfd < 0 )
1662- ereport (PANIC ,
1670+ ereport (ERROR ,
16631671 (errcode_for_file_access (),
16641672 errmsg ("could not open file \"%s\": %m" , path )));
16651673
@@ -1674,7 +1682,7 @@ XLogFileCopy(uint32 log, uint32 seg,
16741682 fd = BasicOpenFile (tmppath , O_RDWR | O_CREAT | O_EXCL | PG_BINARY ,
16751683 S_IRUSR | S_IWUSR );
16761684 if (fd < 0 )
1677- ereport (PANIC ,
1685+ ereport (ERROR ,
16781686 (errcode_for_file_access (),
16791687 errmsg ("could not create file \"%s\": %m" , tmppath )));
16801688
@@ -1687,11 +1695,11 @@ XLogFileCopy(uint32 log, uint32 seg,
16871695 if ((int ) read (srcfd , buffer , sizeof (buffer )) != (int ) sizeof (buffer ))
16881696 {
16891697 if (errno != 0 )
1690- ereport (PANIC ,
1698+ ereport (ERROR ,
16911699 (errcode_for_file_access (),
16921700 errmsg ("could not read file \"%s\": %m" , path )));
16931701 else
1694- ereport (PANIC ,
1702+ ereport (ERROR ,
16951703 (errmsg ("not enough data in file \"%s\"" , path )));
16961704 }
16971705 errno = 0 ;
@@ -1707,19 +1715,19 @@ XLogFileCopy(uint32 log, uint32 seg,
17071715 /* if write didn't set errno, assume problem is no disk space */
17081716 errno = save_errno ? save_errno : ENOSPC ;
17091717
1710- ereport (PANIC ,
1718+ ereport (ERROR ,
17111719 (errcode_for_file_access (),
17121720 errmsg ("could not write to file \"%s\": %m" , tmppath )));
17131721 }
17141722 }
17151723
17161724 if (pg_fsync (fd ) != 0 )
1717- ereport (PANIC ,
1725+ ereport (ERROR ,
17181726 (errcode_for_file_access (),
17191727 errmsg ("could not fsync file \"%s\": %m" , tmppath )));
17201728
17211729 if (close (fd ))
1722- ereport (PANIC ,
1730+ ereport (ERROR ,
17231731 (errcode_for_file_access (),
17241732 errmsg ("could not close file \"%s\": %m" , tmppath )));
17251733
@@ -1729,7 +1737,7 @@ XLogFileCopy(uint32 log, uint32 seg,
17291737 * Now move the segment into place with its final name.
17301738 */
17311739 if (!InstallXLogFileSegment (& log , & seg , tmppath , false, NULL , false))
1732- elog (PANIC , "InstallXLogFileSegment should not have failed" );
1740+ elog (ERROR , "InstallXLogFileSegment should not have failed" );
17331741}
17341742
17351743/*
@@ -1806,14 +1814,14 @@ InstallXLogFileSegment(uint32 *log, uint32 *seg, char *tmppath,
18061814 */
18071815#if HAVE_WORKING_LINK
18081816 if (link (tmppath , path ) < 0 )
1809- ereport (PANIC ,
1817+ ereport (ERROR ,
18101818 (errcode_for_file_access (),
18111819 errmsg ("could not link file \"%s\" to \"%s\" (initialization of log file %u, segment %u): %m" ,
18121820 tmppath , path , * log , * seg )));
18131821 unlink (tmppath );
18141822#else
18151823 if (rename (tmppath , path ) < 0 )
1816- ereport (PANIC ,
1824+ ereport (ERROR ,
18171825 (errcode_for_file_access (),
18181826 errmsg ("could not rename file \"%s\" to \"%s\" (initialization of log file %u, segment %u): %m" ,
18191827 tmppath , path , * log , * seg )));
@@ -2205,6 +2213,12 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr,
22052213 (errmsg ("recycled transaction log file \"%s\"" ,
22062214 xlde -> d_name )));
22072215 (* nsegsrecycled )++ ;
2216+ /* Needn't recheck that slot on future iterations */
2217+ if (max_advance > 0 )
2218+ {
2219+ NextLogSeg (endlogId , endlogSeg );
2220+ max_advance -- ;
2221+ }
22082222 }
22092223 else
22102224 {
@@ -2957,7 +2971,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
29572971 fd = BasicOpenFile (tmppath , O_RDWR | O_CREAT | O_EXCL ,
29582972 S_IRUSR | S_IWUSR );
29592973 if (fd < 0 )
2960- ereport (PANIC ,
2974+ ereport (ERROR ,
29612975 (errcode_for_file_access (),
29622976 errmsg ("could not create file \"%s\": %m" , tmppath )));
29632977
@@ -2976,7 +2990,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
29762990 if (srcfd < 0 )
29772991 {
29782992 if (errno != ENOENT )
2979- ereport (FATAL ,
2993+ ereport (ERROR ,
29802994 (errcode_for_file_access (),
29812995 errmsg ("could not open file \"%s\": %m" , path )));
29822996 /* Not there, so assume parent has no parents */
@@ -2988,7 +3002,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
29883002 errno = 0 ;
29893003 nbytes = (int ) read (srcfd , buffer , sizeof (buffer ));
29903004 if (nbytes < 0 || errno != 0 )
2991- ereport (PANIC ,
3005+ ereport (ERROR ,
29923006 (errcode_for_file_access (),
29933007 errmsg ("could not read file \"%s\": %m" , path )));
29943008 if (nbytes == 0 )
@@ -3010,7 +3024,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
30103024 */
30113025 errno = save_errno ? save_errno : ENOSPC ;
30123026
3013- ereport (PANIC ,
3027+ ereport (ERROR ,
30143028 (errcode_for_file_access (),
30153029 errmsg ("could not write to file \"%s\": %m" , tmppath )));
30163030 }
@@ -3048,18 +3062,18 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
30483062 /* if write didn't set errno, assume problem is no disk space */
30493063 errno = save_errno ? save_errno : ENOSPC ;
30503064
3051- ereport (PANIC ,
3065+ ereport (ERROR ,
30523066 (errcode_for_file_access (),
30533067 errmsg ("could not write to file \"%s\": %m" , tmppath )));
30543068 }
30553069
30563070 if (pg_fsync (fd ) != 0 )
3057- ereport (PANIC ,
3071+ ereport (ERROR ,
30583072 (errcode_for_file_access (),
30593073 errmsg ("could not fsync file \"%s\": %m" , tmppath )));
30603074
30613075 if (close (fd ))
3062- ereport (PANIC ,
3076+ ereport (ERROR ,
30633077 (errcode_for_file_access (),
30643078 errmsg ("could not close file \"%s\": %m" , tmppath )));
30653079
@@ -3076,14 +3090,14 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
30763090 */
30773091#if HAVE_WORKING_LINK
30783092 if (link (tmppath , path ) < 0 )
3079- ereport (PANIC ,
3093+ ereport (ERROR ,
30803094 (errcode_for_file_access (),
30813095 errmsg ("could not link file \"%s\" to \"%s\": %m" ,
30823096 tmppath , path )));
30833097 unlink (tmppath );
30843098#else
30853099 if (rename (tmppath , path ) < 0 )
3086- ereport (PANIC ,
3100+ ereport (ERROR ,
30873101 (errcode_for_file_access (),
30883102 errmsg ("could not rename file \"%s\" to \"%s\": %m" ,
30893103 tmppath , path )));
0 commit comments