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.68 2001/06/03 14:53:56 petere Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.69 2001/06/06 17:07:38 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 of log file %u, segment %u, offset %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 failed to create or write %s: %m" , tmppath );
1338
1346
}
@@ -1990,8 +1998,14 @@ WriteControlFile(void)
1990
1998
elog (STOP , "WriteControlFile: could not create control file (%s): %m" ,
1991
1999
ControlFilePath );
1992
2000
2001
+ errno = 0 ;
1993
2002
if (write (fd , buffer , BLCKSZ ) != BLCKSZ )
2003
+ {
2004
+ /* if write didn't set errno, assume problem is no disk space */
2005
+ if (errno == 0 )
2006
+ errno = ENOSPC ;
1994
2007
elog (STOP , "WriteControlFile: write to control file failed: %m" );
2008
+ }
1995
2009
1996
2010
if (pg_fsync (fd ) != 0 )
1997
2011
elog (STOP , "WriteControlFile: fsync of control file failed: %m" );
@@ -2109,8 +2123,14 @@ UpdateControlFile(void)
2109
2123
if (fd < 0 )
2110
2124
elog (STOP , "could not open control file (%s): %m" , ControlFilePath );
2111
2125
2126
+ errno = 0 ;
2112
2127
if (write (fd , ControlFile , sizeof (ControlFileData )) != sizeof (ControlFileData ))
2128
+ {
2129
+ /* if write didn't set errno, assume problem is no disk space */
2130
+ if (errno == 0 )
2131
+ errno = ENOSPC ;
2113
2132
elog (STOP , "write to control file failed: %m" );
2133
+ }
2114
2134
2115
2135
if (pg_fsync (fd ) != 0 )
2116
2136
elog (STOP , "fsync of control file failed: %m" );
@@ -2248,8 +2268,14 @@ BootStrapXLOG(void)
2248
2268
use_existent = false;
2249
2269
openLogFile = XLogFileInit (0 , 0 , & use_existent , false);
2250
2270
2271
+ errno = 0 ;
2251
2272
if (write (openLogFile , buffer , BLCKSZ ) != BLCKSZ )
2273
+ {
2274
+ /* if write didn't set errno, assume problem is no disk space */
2275
+ if (errno == 0 )
2276
+ errno = ENOSPC ;
2252
2277
elog (STOP , "BootStrapXLOG failed to write log file: %m" );
2278
+ }
2253
2279
2254
2280
if (pg_fsync (openLogFile ) != 0 )
2255
2281
elog (STOP , "BootStrapXLOG failed to fsync log file: %m" );
@@ -2852,15 +2878,22 @@ CreateCheckPoint(bool shutdown)
2852
2878
elog (STOP , "concurrent transaction log activity while database system is shutting down" );
2853
2879
2854
2880
/*
2855
- * Remember location of prior checkpoint's earliest info. Oldest item
2856
- * is redo or undo, whichever is older; but watch out for case that
2857
- * undo = 0.
2881
+ * Select point at which we can truncate the log, which we base on the
2882
+ * prior checkpoint's earliest info.
2883
+ *
2884
+ * With UNDO support: oldest item is redo or undo, whichever is older;
2885
+ * but watch out for case that undo = 0.
2886
+ *
2887
+ * Without UNDO support: just use the redo pointer. This allows xlog
2888
+ * space to be freed much faster when there are long-running transactions.
2858
2889
*/
2890
+ #ifdef NOT_USED
2859
2891
if (ControlFile -> checkPointCopy .undo .xrecoff != 0 &&
2860
2892
XLByteLT (ControlFile -> checkPointCopy .undo ,
2861
2893
ControlFile -> checkPointCopy .redo ))
2862
2894
XLByteToSeg (ControlFile -> checkPointCopy .undo , _logId , _logSeg );
2863
2895
else
2896
+ #endif
2864
2897
XLByteToSeg (ControlFile -> checkPointCopy .redo , _logId , _logSeg );
2865
2898
2866
2899
/*
0 commit comments