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.216 2005/08/20 23:26:10 tgl Exp $
10+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.217 2005/08/22 00:41:28 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
112112
113113/*
114114 * Limitation of buffer-alignment for direct IO depends on OS and filesystem,
115- * but BLCKSZ is assumed to be enough for it.
115+ * but BLCKSZ is assumed to be enough for it.
116116 */
117117#ifdef O_DIRECT
118118#define ALIGNOF_XLOG_BUFFER BLCKSZ
@@ -339,7 +339,7 @@ typedef struct XLogCtlInsert
339339{
340340XLogwrtResult LogwrtResult ;/* a recent value of LogwrtResult */
341341XLogRecPtr PrevRecord ;/* start of previously-inserted record */
342- uint16 curridx ;/* current block index in cache */
342+ int curridx ;/* current block index in cache */
343343XLogPageHeader currpage ;/* points to header of block in cache */
344344char * currpos ;/* current insertion point in cache */
345345XLogRecPtr RedoRecPtr ;/* current redo point for insertions */
@@ -351,7 +351,7 @@ typedef struct XLogCtlInsert
351351typedef struct XLogCtlWrite
352352{
353353XLogwrtResult LogwrtResult ;/* current value of LogwrtResult */
354- uint16 curridx ;/* cache index of next block to write */
354+ int curridx ;/* cache index of next block to write */
355355}XLogCtlWrite ;
356356
357357/*
@@ -375,8 +375,8 @@ typedef struct XLogCtlData
375375 */
376376char * pages ;/* buffers for unwritten XLOG pages */
377377XLogRecPtr * xlblocks ;/* 1st byte ptr-s + BLCKSZ */
378- uint32 XLogCacheByte ;/* # bytes in xlog buffers */
379- uint32 XLogCacheBlck ;/* highest allocated xlog buffer index */
378+ Size XLogCacheByte ;/* # bytes in xlog buffers */
379+ int XLogCacheBlck ;/* highest allocated xlog buffer index */
380380TimeLineID ThisTimeLineID ;
381381
382382slock_t info_lck ;/* locks shared LogwrtRqst/LogwrtResult */
@@ -497,13 +497,14 @@ static void ReadControlFile(void);
497497static char * str_time (time_t tnow );
498498static void issue_xlog_fsync (void );
499499
500- /* XLog gather-writestaffs */
500+ /* XLog gather-writestuff */
501501typedef struct XLogPages
502502{
503- char * head ;/*Head of first page */
504- int size ;/* Total bytesof pages == count(pages) * BLCKSZ */
505- int offset ;/*Offset in xlog segment file */
503+ char * head ;/*Start of first page to write */
504+ Size size ;/* Total bytesto write == count(pages) * BLCKSZ */
505+ uint32 offset ;/*Starting offset in xlog segment file */
506506}XLogPages ;
507+
507508static void XLogPageReset (XLogPages * pages );
508509static void XLogPageWrite (XLogPages * pages ,int index );
509510static void XLogPageFlush (XLogPages * pages ,int index );
@@ -539,7 +540,7 @@ XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata)
539540XLogRecPtr RecPtr ;
540541XLogRecPtr WriteRqst ;
541542uint32 freespace ;
542- uint16 curridx ;
543+ int curridx ;
543544XLogRecData * rdt ;
544545Buffer dtbuf [XLR_MAX_BKP_BLOCKS ];
545546bool dtbuf_bkp [XLR_MAX_BKP_BLOCKS ];
@@ -1154,7 +1155,7 @@ AdvanceXLInsertBuffer(void)
11541155{
11551156XLogCtlInsert * Insert = & XLogCtl -> Insert ;
11561157XLogCtlWrite * Write = & XLogCtl -> Write ;
1157- uint16 nextidx = NextBufIdx (Insert -> curridx );
1158+ int nextidx = NextBufIdx (Insert -> curridx );
11581159bool update_needed = true;
11591160XLogRecPtr OldPageRqstPtr ;
11601161XLogwrtRqst WriteRqst ;
@@ -1239,7 +1240,7 @@ AdvanceXLInsertBuffer(void)
12391240else
12401241NewPageEndPtr .xrecoff += BLCKSZ ;
12411242XLogCtl -> xlblocks [nextidx ]= NewPageEndPtr ;
1242- NewPage = (XLogPageHeader ) (XLogCtl -> pages + nextidx * BLCKSZ );
1243+ NewPage = (XLogPageHeader ) (XLogCtl -> pages + nextidx * ( Size ) BLCKSZ );
12431244Insert -> curridx = nextidx ;
12441245Insert -> currpage = NewPage ;
12451246Insert -> currpos = ((char * )NewPage )+ SizeOfXLogShortPHD ;
@@ -3625,19 +3626,19 @@ XLOGShmemSize(void)
36253626void
36263627XLOGShmemInit (void )
36273628{
3628- bool foundXLog ,
3629- foundCFile ;
3629+ bool foundCFile ,
3630+ foundXLog ;
36303631char * allocptr ;
36313632
3632- XLogCtl = (XLogCtlData * )
3633- ShmemInitStruct ("XLOG Ctl" ,XLOGShmemSize (),& foundXLog );
36343633ControlFile = (ControlFileData * )
36353634ShmemInitStruct ("Control File" ,sizeof (ControlFileData ),& foundCFile );
3635+ XLogCtl = (XLogCtlData * )
3636+ ShmemInitStruct ("XLOG Ctl" ,XLOGShmemSize (),& foundXLog );
36363637
3637- if (foundXLog || foundCFile )
3638+ if (foundCFile || foundXLog )
36383639{
36393640/* both should be present or neither */
3640- Assert (foundXLog && foundCFile );
3641+ Assert (foundCFile && foundXLog );
36413642return ;
36423643}
36433644
@@ -3658,13 +3659,13 @@ XLOGShmemInit(void)
36583659 */
36593660allocptr = (char * )TYPEALIGN (ALIGNOF_XLOG_BUFFER ,allocptr );
36603661XLogCtl -> pages = allocptr ;
3661- memset (XLogCtl -> pages ,0 ,BLCKSZ * XLOGbuffers );
3662+ memset (XLogCtl -> pages ,0 ,( Size ) BLCKSZ * XLOGbuffers );
36623663
36633664/*
36643665 * Do basic initialization of XLogCtl shared data. (StartupXLOG will
36653666 * fill in additional info.)
36663667 */
3667- XLogCtl -> XLogCacheByte = BLCKSZ * XLOGbuffers ;
3668+ XLogCtl -> XLogCacheByte = ( Size ) BLCKSZ * XLOGbuffers ;
36683669XLogCtl -> XLogCacheBlck = XLOGbuffers - 1 ;
36693670XLogCtl -> Insert .currpage = (XLogPageHeader ) (XLogCtl -> pages );
36703671SpinLockInit (& XLogCtl -> info_lck );
@@ -5747,7 +5748,7 @@ pg_stop_backup(PG_FUNCTION_ARGS)
57475748BACKUP_LABEL_FILE )));
57485749
57495750RemoveOldBackupHistory ();
5750-
5751+
57515752/*
57525753 * Notify archiver that history file may be archived immediately
57535754 */
@@ -5899,7 +5900,7 @@ remove_backup_label(void)
58995900}
59005901
59015902
5902- /* XLog gather-writestaffs */
5903+ /* XLog gather-writestuff */
59035904
59045905static void
59055906XLogPageReset (XLogPages * pages )
@@ -5910,12 +5911,12 @@ XLogPageReset(XLogPages *pages)
59105911static void
59115912XLogPageWrite (XLogPages * pages ,int index )
59125913{
5913- char * page = XLogCtl -> pages + index * BLCKSZ ;
5914- int size = BLCKSZ ;
5915- int offset = (LogwrtResult .Write .xrecoff - BLCKSZ ) %XLogSegSize ;
5914+ char * page = XLogCtl -> pages + index * ( Size ) BLCKSZ ;
5915+ Size size = BLCKSZ ;
5916+ uint32 offset = (LogwrtResult .Write .xrecoff - BLCKSZ ) %XLogSegSize ;
59165917
5917- if (pages -> head + pages -> size == page
5918- && pages -> offset + pages -> size == offset )
5918+ if (pages -> head + pages -> size == page &&
5919+ pages -> offset + pages -> size == offset )
59195920{/* Pages are continuous. Append new page. */
59205921pages -> size += size ;
59215922}
@@ -5932,11 +5933,11 @@ static void
59325933XLogPageFlush (XLogPages * pages ,int index )
59335934{
59345935if (!pages -> head )
5935- {/*No needs to write pages. */
5936+ {/*Nothing to write */
59365937XLogCtl -> Write .curridx = index ;
59375938return ;
59385939}
5939-
5940+
59405941/* Need to seek in the file? */
59415942if (openLogOff != pages -> offset )
59425943{
@@ -5957,8 +5958,9 @@ XLogPageFlush(XLogPages *pages, int index)
59575958errno = ENOSPC ;
59585959ereport (PANIC ,
59595960(errcode_for_file_access (),
5960- errmsg ("could not write to log file %u, segment %u at offset %u: %m" ,
5961- openLogId ,openLogSeg ,openLogOff )));
5961+ errmsg ("could not write to log file %u, segment %u length %u at offset %u: %m" ,
5962+ openLogId ,openLogSeg ,
5963+ (unsignedint )pages -> size ,openLogOff )));
59625964}
59635965
59645966openLogOff += pages -> size ;