Skip to content

Commit d0096a4

Browse files
committed
Fix some inconsistent choices of datatypes in xlog.c. Make buffer
indexes all be int, rather than variously int, uint16 and uint32; add some casts where necessary to support large buffer arrays.
1 parent 6fcaaf2 commit d0096a4

File tree

1 file changed

+34
-32
lines changed
  • src/backend/access/transam

1 file changed

+34
-32
lines changed

src/backend/access/transam/xlog.c

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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
*/
@@ -112,7 +112,7 @@
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
{
340340
XLogwrtResult LogwrtResult; /* a recent value of LogwrtResult */
341341
XLogRecPtr PrevRecord; /* start of previously-inserted record */
342-
uint16 curridx; /* current block index in cache */
342+
int curridx; /* current block index in cache */
343343
XLogPageHeader currpage; /* points to header of block in cache */
344344
char *currpos; /* current insertion point in cache */
345345
XLogRecPtr RedoRecPtr; /* current redo point for insertions */
@@ -351,7 +351,7 @@ typedef struct XLogCtlInsert
351351
typedef struct XLogCtlWrite
352352
{
353353
XLogwrtResult 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
*/
376376
char *pages; /* buffers for unwritten XLOG pages */
377377
XLogRecPtr *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 */
380380
TimeLineID ThisTimeLineID;
381381

382382
slock_t info_lck; /* locks shared LogwrtRqst/LogwrtResult */
@@ -497,13 +497,14 @@ static void ReadControlFile(void);
497497
static char *str_time(time_t tnow);
498498
static void issue_xlog_fsync(void);
499499

500-
/* XLog gather-write staffs */
500+
/* XLog gather-write stuff */
501501
typedef struct XLogPages
502502
{
503-
char *head; /* Head of first page */
504-
int size; /* Total bytes of 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 bytes to write == count(pages) * BLCKSZ */
505+
uint32 offset; /* Starting offset in xlog segment file */
506506
} XLogPages;
507+
507508
static void XLogPageReset(XLogPages *pages);
508509
static void XLogPageWrite(XLogPages *pages, int index);
509510
static void XLogPageFlush(XLogPages *pages, int index);
@@ -539,7 +540,7 @@ XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata)
539540
XLogRecPtr RecPtr;
540541
XLogRecPtr WriteRqst;
541542
uint32 freespace;
542-
uint16 curridx;
543+
int curridx;
543544
XLogRecData *rdt;
544545
Buffer dtbuf[XLR_MAX_BKP_BLOCKS];
545546
bool dtbuf_bkp[XLR_MAX_BKP_BLOCKS];
@@ -1154,7 +1155,7 @@ AdvanceXLInsertBuffer(void)
11541155
{
11551156
XLogCtlInsert *Insert = &XLogCtl->Insert;
11561157
XLogCtlWrite *Write = &XLogCtl->Write;
1157-
uint16 nextidx = NextBufIdx(Insert->curridx);
1158+
int nextidx = NextBufIdx(Insert->curridx);
11581159
bool update_needed = true;
11591160
XLogRecPtr OldPageRqstPtr;
11601161
XLogwrtRqst WriteRqst;
@@ -1239,7 +1240,7 @@ AdvanceXLInsertBuffer(void)
12391240
else
12401241
NewPageEndPtr.xrecoff += BLCKSZ;
12411242
XLogCtl->xlblocks[nextidx] = NewPageEndPtr;
1242-
NewPage = (XLogPageHeader) (XLogCtl->pages + nextidx * BLCKSZ);
1243+
NewPage = (XLogPageHeader) (XLogCtl->pages + nextidx * (Size) BLCKSZ);
12431244
Insert->curridx = nextidx;
12441245
Insert->currpage = NewPage;
12451246
Insert->currpos = ((char *) NewPage) + SizeOfXLogShortPHD;
@@ -3625,19 +3626,19 @@ XLOGShmemSize(void)
36253626
void
36263627
XLOGShmemInit(void)
36273628
{
3628-
bool foundXLog,
3629-
foundCFile;
3629+
bool foundCFile,
3630+
foundXLog;
36303631
char *allocptr;
36313632

3632-
XLogCtl = (XLogCtlData *)
3633-
ShmemInitStruct("XLOG Ctl", XLOGShmemSize(), &foundXLog);
36343633
ControlFile = (ControlFileData *)
36353634
ShmemInitStruct("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);
36413642
return;
36423643
}
36433644

@@ -3658,13 +3659,13 @@ XLOGShmemInit(void)
36583659
*/
36593660
allocptr = (char *) TYPEALIGN(ALIGNOF_XLOG_BUFFER, allocptr);
36603661
XLogCtl->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;
36683669
XLogCtl->XLogCacheBlck = XLOGbuffers - 1;
36693670
XLogCtl->Insert.currpage = (XLogPageHeader) (XLogCtl->pages);
36703671
SpinLockInit(&XLogCtl->info_lck);
@@ -5747,7 +5748,7 @@ pg_stop_backup(PG_FUNCTION_ARGS)
57475748
BACKUP_LABEL_FILE)));
57485749

57495750
RemoveOldBackupHistory();
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-write staffs */
5903+
/* XLog gather-write stuff */
59035904

59045905
static void
59055906
XLogPageReset(XLogPages *pages)
@@ -5910,12 +5911,12 @@ XLogPageReset(XLogPages *pages)
59105911
static void
59115912
XLogPageWrite(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. */
59205921
pages->size += size;
59215922
}
@@ -5932,11 +5933,11 @@ static void
59325933
XLogPageFlush(XLogPages *pages, int index)
59335934
{
59345935
if (!pages->head)
5935-
{ /* No needs to write pages. */
5936+
{ /* Nothing to write */
59365937
XLogCtl->Write.curridx = index;
59375938
return;
59385939
}
5939-
5940+
59405941
/* Need to seek in the file? */
59415942
if (openLogOff != pages->offset)
59425943
{
@@ -5957,8 +5958,9 @@ XLogPageFlush(XLogPages *pages, int index)
59575958
errno = ENOSPC;
59585959
ereport(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+
(unsigned int) pages->size, openLogOff)));
59625964
}
59635965

59645966
openLogOff += pages->size;

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