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.
This commit is contained in:
parent
6fcaaf29da
commit
d0096a41fa
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.216 2005/08/20 23:26:10 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.217 2005/08/22 00:41:28 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -339,7 +339,7 @@ typedef struct XLogCtlInsert
|
|||||||
{
|
{
|
||||||
XLogwrtResult LogwrtResult; /* a recent value of LogwrtResult */
|
XLogwrtResult LogwrtResult; /* a recent value of LogwrtResult */
|
||||||
XLogRecPtr PrevRecord; /* start of previously-inserted record */
|
XLogRecPtr PrevRecord; /* start of previously-inserted record */
|
||||||
uint16 curridx; /* current block index in cache */
|
int curridx; /* current block index in cache */
|
||||||
XLogPageHeader currpage; /* points to header of block in cache */
|
XLogPageHeader currpage; /* points to header of block in cache */
|
||||||
char *currpos; /* current insertion point in cache */
|
char *currpos; /* current insertion point in cache */
|
||||||
XLogRecPtr RedoRecPtr; /* current redo point for insertions */
|
XLogRecPtr RedoRecPtr; /* current redo point for insertions */
|
||||||
@ -351,7 +351,7 @@ typedef struct XLogCtlInsert
|
|||||||
typedef struct XLogCtlWrite
|
typedef struct XLogCtlWrite
|
||||||
{
|
{
|
||||||
XLogwrtResult LogwrtResult; /* current value of LogwrtResult */
|
XLogwrtResult LogwrtResult; /* current value of LogwrtResult */
|
||||||
uint16 curridx; /* cache index of next block to write */
|
int curridx; /* cache index of next block to write */
|
||||||
} XLogCtlWrite;
|
} XLogCtlWrite;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -375,8 +375,8 @@ typedef struct XLogCtlData
|
|||||||
*/
|
*/
|
||||||
char *pages; /* buffers for unwritten XLOG pages */
|
char *pages; /* buffers for unwritten XLOG pages */
|
||||||
XLogRecPtr *xlblocks; /* 1st byte ptr-s + BLCKSZ */
|
XLogRecPtr *xlblocks; /* 1st byte ptr-s + BLCKSZ */
|
||||||
uint32 XLogCacheByte; /* # bytes in xlog buffers */
|
Size XLogCacheByte; /* # bytes in xlog buffers */
|
||||||
uint32 XLogCacheBlck; /* highest allocated xlog buffer index */
|
int XLogCacheBlck; /* highest allocated xlog buffer index */
|
||||||
TimeLineID ThisTimeLineID;
|
TimeLineID ThisTimeLineID;
|
||||||
|
|
||||||
slock_t info_lck; /* locks shared LogwrtRqst/LogwrtResult */
|
slock_t info_lck; /* locks shared LogwrtRqst/LogwrtResult */
|
||||||
@ -497,13 +497,14 @@ static void ReadControlFile(void);
|
|||||||
static char *str_time(time_t tnow);
|
static char *str_time(time_t tnow);
|
||||||
static void issue_xlog_fsync(void);
|
static void issue_xlog_fsync(void);
|
||||||
|
|
||||||
/* XLog gather-write staffs */
|
/* XLog gather-write stuff */
|
||||||
typedef struct XLogPages
|
typedef struct XLogPages
|
||||||
{
|
{
|
||||||
char *head; /* Head of first page */
|
char *head; /* Start of first page to write */
|
||||||
int size; /* Total bytes of pages == count(pages) * BLCKSZ */
|
Size size; /* Total bytes to write == count(pages) * BLCKSZ */
|
||||||
int offset; /* Offset in xlog segment file */
|
uint32 offset; /* Starting offset in xlog segment file */
|
||||||
} XLogPages;
|
} XLogPages;
|
||||||
|
|
||||||
static void XLogPageReset(XLogPages *pages);
|
static void XLogPageReset(XLogPages *pages);
|
||||||
static void XLogPageWrite(XLogPages *pages, int index);
|
static void XLogPageWrite(XLogPages *pages, int index);
|
||||||
static void XLogPageFlush(XLogPages *pages, int index);
|
static void XLogPageFlush(XLogPages *pages, int index);
|
||||||
@ -539,7 +540,7 @@ XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata)
|
|||||||
XLogRecPtr RecPtr;
|
XLogRecPtr RecPtr;
|
||||||
XLogRecPtr WriteRqst;
|
XLogRecPtr WriteRqst;
|
||||||
uint32 freespace;
|
uint32 freespace;
|
||||||
uint16 curridx;
|
int curridx;
|
||||||
XLogRecData *rdt;
|
XLogRecData *rdt;
|
||||||
Buffer dtbuf[XLR_MAX_BKP_BLOCKS];
|
Buffer dtbuf[XLR_MAX_BKP_BLOCKS];
|
||||||
bool dtbuf_bkp[XLR_MAX_BKP_BLOCKS];
|
bool dtbuf_bkp[XLR_MAX_BKP_BLOCKS];
|
||||||
@ -1154,7 +1155,7 @@ AdvanceXLInsertBuffer(void)
|
|||||||
{
|
{
|
||||||
XLogCtlInsert *Insert = &XLogCtl->Insert;
|
XLogCtlInsert *Insert = &XLogCtl->Insert;
|
||||||
XLogCtlWrite *Write = &XLogCtl->Write;
|
XLogCtlWrite *Write = &XLogCtl->Write;
|
||||||
uint16 nextidx = NextBufIdx(Insert->curridx);
|
int nextidx = NextBufIdx(Insert->curridx);
|
||||||
bool update_needed = true;
|
bool update_needed = true;
|
||||||
XLogRecPtr OldPageRqstPtr;
|
XLogRecPtr OldPageRqstPtr;
|
||||||
XLogwrtRqst WriteRqst;
|
XLogwrtRqst WriteRqst;
|
||||||
@ -1239,7 +1240,7 @@ AdvanceXLInsertBuffer(void)
|
|||||||
else
|
else
|
||||||
NewPageEndPtr.xrecoff += BLCKSZ;
|
NewPageEndPtr.xrecoff += BLCKSZ;
|
||||||
XLogCtl->xlblocks[nextidx] = NewPageEndPtr;
|
XLogCtl->xlblocks[nextidx] = NewPageEndPtr;
|
||||||
NewPage = (XLogPageHeader) (XLogCtl->pages + nextidx * BLCKSZ);
|
NewPage = (XLogPageHeader) (XLogCtl->pages + nextidx * (Size) BLCKSZ);
|
||||||
Insert->curridx = nextidx;
|
Insert->curridx = nextidx;
|
||||||
Insert->currpage = NewPage;
|
Insert->currpage = NewPage;
|
||||||
Insert->currpos = ((char *) NewPage) + SizeOfXLogShortPHD;
|
Insert->currpos = ((char *) NewPage) + SizeOfXLogShortPHD;
|
||||||
@ -3625,19 +3626,19 @@ XLOGShmemSize(void)
|
|||||||
void
|
void
|
||||||
XLOGShmemInit(void)
|
XLOGShmemInit(void)
|
||||||
{
|
{
|
||||||
bool foundXLog,
|
bool foundCFile,
|
||||||
foundCFile;
|
foundXLog;
|
||||||
char *allocptr;
|
char *allocptr;
|
||||||
|
|
||||||
XLogCtl = (XLogCtlData *)
|
|
||||||
ShmemInitStruct("XLOG Ctl", XLOGShmemSize(), &foundXLog);
|
|
||||||
ControlFile = (ControlFileData *)
|
ControlFile = (ControlFileData *)
|
||||||
ShmemInitStruct("Control File", sizeof(ControlFileData), &foundCFile);
|
ShmemInitStruct("Control File", sizeof(ControlFileData), &foundCFile);
|
||||||
|
XLogCtl = (XLogCtlData *)
|
||||||
|
ShmemInitStruct("XLOG Ctl", XLOGShmemSize(), &foundXLog);
|
||||||
|
|
||||||
if (foundXLog || foundCFile)
|
if (foundCFile || foundXLog)
|
||||||
{
|
{
|
||||||
/* both should be present or neither */
|
/* both should be present or neither */
|
||||||
Assert(foundXLog && foundCFile);
|
Assert(foundCFile && foundXLog);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3658,13 +3659,13 @@ XLOGShmemInit(void)
|
|||||||
*/
|
*/
|
||||||
allocptr = (char *) TYPEALIGN(ALIGNOF_XLOG_BUFFER, allocptr);
|
allocptr = (char *) TYPEALIGN(ALIGNOF_XLOG_BUFFER, allocptr);
|
||||||
XLogCtl->pages = allocptr;
|
XLogCtl->pages = allocptr;
|
||||||
memset(XLogCtl->pages, 0, BLCKSZ * XLOGbuffers);
|
memset(XLogCtl->pages, 0, (Size) BLCKSZ * XLOGbuffers);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do basic initialization of XLogCtl shared data. (StartupXLOG will
|
* Do basic initialization of XLogCtl shared data. (StartupXLOG will
|
||||||
* fill in additional info.)
|
* fill in additional info.)
|
||||||
*/
|
*/
|
||||||
XLogCtl->XLogCacheByte = BLCKSZ * XLOGbuffers;
|
XLogCtl->XLogCacheByte = (Size) BLCKSZ * XLOGbuffers;
|
||||||
XLogCtl->XLogCacheBlck = XLOGbuffers - 1;
|
XLogCtl->XLogCacheBlck = XLOGbuffers - 1;
|
||||||
XLogCtl->Insert.currpage = (XLogPageHeader) (XLogCtl->pages);
|
XLogCtl->Insert.currpage = (XLogPageHeader) (XLogCtl->pages);
|
||||||
SpinLockInit(&XLogCtl->info_lck);
|
SpinLockInit(&XLogCtl->info_lck);
|
||||||
@ -5899,7 +5900,7 @@ remove_backup_label(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* XLog gather-write staffs */
|
/* XLog gather-write stuff */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
XLogPageReset(XLogPages *pages)
|
XLogPageReset(XLogPages *pages)
|
||||||
@ -5910,12 +5911,12 @@ XLogPageReset(XLogPages *pages)
|
|||||||
static void
|
static void
|
||||||
XLogPageWrite(XLogPages *pages, int index)
|
XLogPageWrite(XLogPages *pages, int index)
|
||||||
{
|
{
|
||||||
char *page = XLogCtl->pages + index * BLCKSZ;
|
char *page = XLogCtl->pages + index * (Size) BLCKSZ;
|
||||||
int size = BLCKSZ;
|
Size size = BLCKSZ;
|
||||||
int offset = (LogwrtResult.Write.xrecoff - BLCKSZ) % XLogSegSize;
|
uint32 offset = (LogwrtResult.Write.xrecoff - BLCKSZ) % XLogSegSize;
|
||||||
|
|
||||||
if (pages->head + pages->size == page
|
if (pages->head + pages->size == page &&
|
||||||
&& pages->offset + pages->size == offset)
|
pages->offset + pages->size == offset)
|
||||||
{ /* Pages are continuous. Append new page. */
|
{ /* Pages are continuous. Append new page. */
|
||||||
pages->size += size;
|
pages->size += size;
|
||||||
}
|
}
|
||||||
@ -5932,7 +5933,7 @@ static void
|
|||||||
XLogPageFlush(XLogPages *pages, int index)
|
XLogPageFlush(XLogPages *pages, int index)
|
||||||
{
|
{
|
||||||
if (!pages->head)
|
if (!pages->head)
|
||||||
{ /* No needs to write pages. */
|
{ /* Nothing to write */
|
||||||
XLogCtl->Write.curridx = index;
|
XLogCtl->Write.curridx = index;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -5957,8 +5958,9 @@ XLogPageFlush(XLogPages *pages, int index)
|
|||||||
errno = ENOSPC;
|
errno = ENOSPC;
|
||||||
ereport(PANIC,
|
ereport(PANIC,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write to log file %u, segment %u at offset %u: %m",
|
errmsg("could not write to log file %u, segment %u length %u at offset %u: %m",
|
||||||
openLogId, openLogSeg, openLogOff)));
|
openLogId, openLogSeg,
|
||||||
|
(unsigned int) pages->size, openLogOff)));
|
||||||
}
|
}
|
||||||
|
|
||||||
openLogOff += pages->size;
|
openLogOff += pages->size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user