7
7
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.65 2001/04/05 16:55:21 tgl Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.65.2.1 2001/06/06 17:18:56 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -1068,9 +1068,15 @@ XLogWrite(XLogwrtRqst WriteRqst)
1068
1068
1069
1069
/* OK to write the page */
1070
1070
from = XLogCtl -> pages + Write -> curridx * BLCKSZ ;
1071
+ errno = 0 ;
1071
1072
if (write (openLogFile ,from ,BLCKSZ )!= BLCKSZ )
1073
+ {
1074
+ /* if write didn't set errno, assume problem is no disk space */
1075
+ if (errno == 0 )
1076
+ errno = ENOSPC ;
1072
1077
elog (STOP ,"write(logfile %u seg %u off %u) failed: %m" ,
1073
1078
openLogId ,openLogSeg ,openLogOff );
1079
+ }
1074
1080
openLogOff += BLCKSZ ;
1075
1081
1076
1082
/*
@@ -1323,6 +1329,7 @@ XLogFileInit(uint32 log, uint32 seg,
1323
1329
MemSet (zbuffer ,0 ,sizeof (zbuffer ));
1324
1330
for (nbytes = 0 ;nbytes < XLogSegSize ;nbytes += sizeof (zbuffer ))
1325
1331
{
1332
+ errno = 0 ;
1326
1333
if ((int )write (fd ,zbuffer ,sizeof (zbuffer ))!= (int )sizeof (zbuffer ))
1327
1334
{
1328
1335
int save_errno = errno ;
@@ -1332,7 +1339,8 @@ XLogFileInit(uint32 log, uint32 seg,
1332
1339
* space
1333
1340
*/
1334
1341
unlink (tmppath );
1335
- errno = save_errno ;
1342
+ /* if write didn't set errno, assume problem is no disk space */
1343
+ errno = save_errno ?save_errno :ENOSPC ;
1336
1344
1337
1345
elog (STOP ,"ZeroFill(%s) failed: %m" ,tmppath );
1338
1346
}
@@ -1987,8 +1995,14 @@ WriteControlFile(void)
1987
1995
elog (STOP ,"WriteControlFile failed to create control file (%s): %m" ,
1988
1996
ControlFilePath );
1989
1997
1998
+ errno = 0 ;
1990
1999
if (write (fd ,buffer ,BLCKSZ )!= BLCKSZ )
2000
+ {
2001
+ /* if write didn't set errno, assume problem is no disk space */
2002
+ if (errno == 0 )
2003
+ errno = ENOSPC ;
1991
2004
elog (STOP ,"WriteControlFile failed to write control file: %m" );
2005
+ }
1992
2006
1993
2007
if (pg_fsync (fd )!= 0 )
1994
2008
elog (STOP ,"WriteControlFile failed to fsync control file: %m" );
@@ -2085,8 +2099,14 @@ UpdateControlFile(void)
2085
2099
if (fd < 0 )
2086
2100
elog (STOP ,"open(\"%s\") failed: %m" ,ControlFilePath );
2087
2101
2102
+ errno = 0 ;
2088
2103
if (write (fd ,ControlFile ,sizeof (ControlFileData ))!= sizeof (ControlFileData ))
2104
+ {
2105
+ /* if write didn't set errno, assume problem is no disk space */
2106
+ if (errno == 0 )
2107
+ errno = ENOSPC ;
2089
2108
elog (STOP ,"write(cntlfile) failed: %m" );
2109
+ }
2090
2110
2091
2111
if (pg_fsync (fd )!= 0 )
2092
2112
elog (STOP ,"fsync(cntlfile) failed: %m" );
@@ -2224,8 +2244,14 @@ BootStrapXLOG(void)
2224
2244
use_existent = false;
2225
2245
openLogFile = XLogFileInit (0 ,0 ,& use_existent , false);
2226
2246
2247
+ errno = 0 ;
2227
2248
if (write (openLogFile ,buffer ,BLCKSZ )!= BLCKSZ )
2249
+ {
2250
+ /* if write didn't set errno, assume problem is no disk space */
2251
+ if (errno == 0 )
2252
+ errno = ENOSPC ;
2228
2253
elog (STOP ,"BootStrapXLOG failed to write logfile: %m" );
2254
+ }
2229
2255
2230
2256
if (pg_fsync (openLogFile )!= 0 )
2231
2257
elog (STOP ,"BootStrapXLOG failed to fsync logfile: %m" );
@@ -2816,15 +2842,22 @@ CreateCheckPoint(bool shutdown)
2816
2842
elog (STOP ,"XLog concurrent activity while data base is shutting down" );
2817
2843
2818
2844
/*
2819
- * Remember location of prior checkpoint's earliest info. Oldest item
2820
- * is redo or undo, whichever is older; but watch out for case that
2821
- * undo = 0.
2845
+ * Select point at which we can truncate the log, which we base on the
2846
+ * prior checkpoint's earliest info.
2847
+ *
2848
+ * With UNDO support: oldest item is redo or undo, whichever is older;
2849
+ * but watch out for case that undo = 0.
2850
+ *
2851
+ * Without UNDO support: just use the redo pointer. This allows xlog
2852
+ * space to be freed much faster when there are long-running transactions.
2822
2853
*/
2854
+ #ifdef NOT_USED
2823
2855
if (ControlFile -> checkPointCopy .undo .xrecoff != 0 &&
2824
2856
XLByteLT (ControlFile -> checkPointCopy .undo ,
2825
2857
ControlFile -> checkPointCopy .redo ))
2826
2858
XLByteToSeg (ControlFile -> checkPointCopy .undo ,_logId ,_logSeg );
2827
2859
else
2860
+ #endif
2828
2861
XLByteToSeg (ControlFile -> checkPointCopy .redo ,_logId ,_logSeg );
2829
2862
2830
2863
/*