* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.231 2006/03/31 23:32:05 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.232 2006/04/03 23:35:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Limitation of buffer-alignment for direct IO depends on OS and filesystem,
- * but BLCKSZ is assumed to be enough for it.
+ * but XLOG_BLCKSZ is assumed to be enough for it.
*/
#ifdef O_DIRECT
-#define ALIGNOF_XLOG_BUFFER BLCKSZ
+#define ALIGNOF_XLOG_BUFFER XLOG_BLCKSZ
#else
#define ALIGNOF_XLOG_BUFFER ALIGNOF_BUFFER
#endif
* and xlblocks values depends on WALInsertLock and WALWriteLock.
*/
char *pages; /* buffers for unwritten XLOG pages */
- XLogRecPtr *xlblocks; /* 1st byte ptr-s + BLCKSZ */
+ XLogRecPtr *xlblocks; /* 1st byte ptr-s + XLOG_BLCKSZ */
Size XLogCacheByte; /* # bytes in xlog buffers */
int XLogCacheBlck; /* highest allocated xlog buffer index */
TimeLineID ThisTimeLineID;
/* Free space remaining in the current xlog page buffer */
#define INSERT_FREESPACE(Insert) \
- (BLCKSZ - ((Insert)->currpos - (char *) (Insert)->currpage))
+ (XLOG_BLCKSZ - ((Insert)->currpos - (char *) (Insert)->currpage))
/* Construct XLogRecPtr value for current insertion point */
#define INSERT_RECPTR(recptr,Insert,curridx) \
static uint32 readSeg = 0;
static uint32 readOff = 0;
-/* Buffer for currently read page (BLCKSZ bytes) */
+/* Buffer for currently read page (XLOG_BLCKSZ bytes) */
static char *readBuf = NULL;
/* Buffer for current ReadRecord result (expandable) */
* If cache is half filled then try to acquire write lock and do
* XLogWrite. Ignore any fractional blocks in performing this check.
*/
- LogwrtRqst.Write.xrecoff -= LogwrtRqst.Write.xrecoff % BLCKSZ;
+ LogwrtRqst.Write.xrecoff -= LogwrtRqst.Write.xrecoff % XLOG_BLCKSZ;
if (LogwrtRqst.Write.xlogid != LogwrtResult.Write.xlogid ||
(LogwrtRqst.Write.xrecoff >= LogwrtResult.Write.xrecoff +
XLogCtl->XLogCacheByte / 2))
{
/* crossing a logid boundary */
NewPageEndPtr.xlogid += 1;
- NewPageEndPtr.xrecoff = BLCKSZ;
+ NewPageEndPtr.xrecoff = XLOG_BLCKSZ;
}
else
- NewPageEndPtr.xrecoff += BLCKSZ;
+ NewPageEndPtr.xrecoff += XLOG_BLCKSZ;
XLogCtl->xlblocks[nextidx] = NewPageEndPtr;
- NewPage = (XLogPageHeader) (XLogCtl->pages + nextidx * (Size) BLCKSZ);
+ NewPage = (XLogPageHeader) (XLogCtl->pages + nextidx * (Size) XLOG_BLCKSZ);
Insert->curridx = nextidx;
Insert->currpage = NewPage;
* Be sure to re-zero the buffer so that bytes beyond what we've written
* will look like zeroes and not valid XLOG records...
*/
- MemSet((char *) NewPage, 0, BLCKSZ);
+ MemSet((char *) NewPage, 0, XLOG_BLCKSZ);
/*
* Fill the new page's header
/* NewPage->xlp_info = 0; */ /* done by memset */
NewPage ->xlp_tli = ThisTimeLineID;
NewPage ->xlp_pageaddr.xlogid = NewPageEndPtr.xlogid;
- NewPage ->xlp_pageaddr.xrecoff = NewPageEndPtr.xrecoff - BLCKSZ;
+ NewPage ->xlp_pageaddr.xrecoff = NewPageEndPtr.xrecoff - XLOG_BLCKSZ;
/*
* If first page of an XLOG segment file, make it a long header.
{
/* first of group */
startidx = curridx;
- startoffset = (LogwrtResult.Write.xrecoff - BLCKSZ) % XLogSegSize;
+ startoffset = (LogwrtResult.Write.xrecoff - XLOG_BLCKSZ) % XLogSegSize;
}
npages++;
* segment.
*/
finishing_seg = !ispartialpage &&
- (startoffset + npages * BLCKSZ) >= XLogSegSize;
+ (startoffset + npages * XLOG_BLCKSZ) >= XLogSegSize;
if (!XLByteLT(LogwrtResult.Write, WriteRqst.Write) ||
curridx == XLogCtl->XLogCacheBlck ||
}
/* OK to write the page(s) */
- from = XLogCtl->pages + startidx * (Size) BLCKSZ;
- nbytes = npages * (Size) BLCKSZ;
+ from = XLogCtl->pages + startidx * (Size) XLOG_BLCKSZ;
+ nbytes = npages * (Size) XLOG_BLCKSZ;
errno = 0;
if (write(openLogFile, from, nbytes) != nbytes)
{
{
char path[MAXPGPATH];
char tmppath[MAXPGPATH];
- char zbuffer[BLCKSZ];
+ char zbuffer[XLOG_BLCKSZ];
uint32 installed_log;
uint32 installed_seg;
int max_advance;
{
char path[MAXPGPATH];
char tmppath[MAXPGPATH];
- char buffer[BLCKSZ];
+ char buffer[XLOG_BLCKSZ];
int srcfd;
int fd;
int nbytes;
* (2) a static char array isn't guaranteed to have any particular
* alignment, whereas malloc() will provide MAXALIGN'd storage.
*/
- readBuf = (char *) malloc(BLCKSZ);
+ readBuf = (char *) malloc(XLOG_BLCKSZ);
Assert(readBuf != NULL);
}
goto got_record;
}
/* align old recptr to next page */
- if (tmpRecPtr.xrecoff % BLCKSZ != 0)
- tmpRecPtr.xrecoff += (BLCKSZ - tmpRecPtr.xrecoff % BLCKSZ);
+ if (tmpRecPtr.xrecoff % XLOG_BLCKSZ != 0)
+ tmpRecPtr.xrecoff += (XLOG_BLCKSZ - tmpRecPtr.xrecoff % XLOG_BLCKSZ);
if (tmpRecPtr.xrecoff >= XLogFileSize)
{
(tmpRecPtr.xlogid)++;
readOff = (uint32) (-1); /* force read to occur below */
}
- targetPageOff = ((RecPtr->xrecoff % XLogSegSize) / BLCKSZ) * BLCKSZ;
+ targetPageOff = ((RecPtr->xrecoff % XLogSegSize) / XLOG_BLCKSZ) * XLOG_BLCKSZ;
if (readOff != targetPageOff)
{
readOff = targetPageOff;
readId, readSeg, readOff)));
goto next_record_is_invalid;
}
- if (read(readFile, readBuf, BLCKSZ) != BLCKSZ)
+ if (read(readFile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
{
ereport(emode,
(errcode_for_file_access(),
goto next_record_is_invalid;
}
pageHeaderSize = XLogPageHeaderSize((XLogPageHeader) readBuf);
- targetRecOff = RecPtr->xrecoff % BLCKSZ;
+ targetRecOff = RecPtr->xrecoff % XLOG_BLCKSZ;
if (targetRecOff == 0)
{
/*
RecPtr->xlogid, RecPtr->xrecoff)));
goto next_record_is_invalid;
}
- record = (XLogRecord *) ((char *) readBuf + RecPtr->xrecoff % BLCKSZ);
+ record = (XLogRecord *) ((char *) readBuf + RecPtr->xrecoff % XLOG_BLCKSZ);
got_record:;
/*
* Allocate or enlarge readRecordBuf as needed. To avoid useless small
- * increases, round its size to a multiple of BLCKSZ, and make sure it's
- * at least 4*BLCKSZ to start with. (That is enough for all "normal"
- * records, but very large commit or abort records might need more space.)
+ * increases, round its size to a multiple of XLOG_BLCKSZ, and make sure
+ * it's at least 4*Max(BLCKSZ, XLOG_BLCKSZ) to start with. (That is
+ * enough for all "normal" records, but very large commit or abort records
+ * might need more space.)
*/
total_len = record->xl_tot_len;
if (total_len > readRecordBufSize)
{
uint32 newSize = total_len;
- newSize += BLCKSZ - (newSize % BLCKSZ);
- newSize = Max(newSize, 4 * BLCKSZ);
+ newSize += XLOG_BLCKSZ - (newSize % XLOG_BLCKSZ);
+ newSize = Max(newSize, 4 * Max(BLCKSZ, XLOG_BLCKSZ));
if (readRecordBuf)
free(readRecordBuf);
readRecordBuf = (char *) malloc(newSize);
buffer = readRecordBuf;
nextRecord = NULL;
- len = BLCKSZ - RecPtr->xrecoff % BLCKSZ;
+ len = XLOG_BLCKSZ - RecPtr->xrecoff % XLOG_BLCKSZ;
if (total_len > len)
{
/* Need to reassemble record */
buffer += len;
for (;;)
{
- readOff += BLCKSZ;
+ readOff += XLOG_BLCKSZ;
if (readOff >= XLogSegSize)
{
close(readFile);
goto next_record_is_invalid;
readOff = 0;
}
- if (read(readFile, readBuf, BLCKSZ) != BLCKSZ)
+ if (read(readFile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
{
ereport(emode,
(errcode_for_file_access(),
readId, readSeg, readOff)));
goto next_record_is_invalid;
}
- len = BLCKSZ - pageHeaderSize - SizeOfXLogContRecord;
+ len = XLOG_BLCKSZ - pageHeaderSize - SizeOfXLogContRecord;
if (contrecord->xl_rem_len > len)
{
memcpy(buffer, (char *) contrecord + SizeOfXLogContRecord, len);
if (!RecordIsValid(record, *RecPtr, emode))
goto next_record_is_invalid;
pageHeaderSize = XLogPageHeaderSize((XLogPageHeader) readBuf);
- if (BLCKSZ - SizeOfXLogRecord >= pageHeaderSize +
+ if (XLOG_BLCKSZ - SizeOfXLogRecord >= pageHeaderSize +
MAXALIGN(SizeOfXLogContRecord + contrecord->xl_rem_len))
{
nextRecord = (XLogRecord *) ((char *) contrecord +
/* Record does not cross a page boundary */
if (!RecordIsValid(record, *RecPtr, emode))
goto next_record_is_invalid;
- if (BLCKSZ - SizeOfXLogRecord >= RecPtr->xrecoff % BLCKSZ +
+ if (XLOG_BLCKSZ - SizeOfXLogRecord >= RecPtr->xrecoff % XLOG_BLCKSZ +
MAXALIGN(total_len))
nextRecord = (XLogRecord *) ((char *) record + MAXALIGN(total_len));
EndRecPtr.xlogid = RecPtr->xlogid;
ControlFile->blcksz = BLCKSZ;
ControlFile->relseg_size = RELSEG_SIZE;
+ ControlFile->xlog_blcksz = XLOG_BLCKSZ;
ControlFile->xlog_seg_size = XLOG_SEG_SIZE;
ControlFile->nameDataLen = NAMEDATALEN;
" but the server was compiled with RELSEG_SIZE %d.",
ControlFile->relseg_size, RELSEG_SIZE),
errhint("It looks like you need to recompile or initdb.")));
+ if (ControlFile->xlog_blcksz != XLOG_BLCKSZ)
+ ereport(FATAL,
+ (errmsg("database files are incompatible with server"),
+ errdetail("The database cluster was initialized with XLOG_BLCKSZ %d,"
+ " but the server was compiled with XLOG_BLCKSZ %d.",
+ ControlFile->xlog_blcksz, XLOG_BLCKSZ),
+ errhint("It looks like you need to recompile or initdb.")));
if (ControlFile->xlog_seg_size != XLOG_SEG_SIZE)
ereport(FATAL,
(errmsg("database files are incompatible with server"),
/* extra alignment padding for XLOG I/O buffers */
size = add_size(size, ALIGNOF_XLOG_BUFFER);
/* and the buffers themselves */
- size = add_size(size, mul_size(BLCKSZ, XLOGbuffers));
+ size = add_size(size, mul_size(XLOG_BLCKSZ, XLOGbuffers));
/*
* Note: we don't count ControlFileData, it comes out of the "slop factor"
*/
allocptr = (char *) TYPEALIGN(ALIGNOF_XLOG_BUFFER, allocptr);
XLogCtl->pages = allocptr;
- memset(XLogCtl->pages, 0, (Size) BLCKSZ * XLOGbuffers);
+ memset(XLogCtl->pages, 0, (Size) XLOG_BLCKSZ * XLOGbuffers);
/*
* Do basic initialization of XLogCtl shared data. (StartupXLOG will fill
* in additional info.)
*/
- XLogCtl->XLogCacheByte = (Size) BLCKSZ *XLOGbuffers;
+ XLogCtl->XLogCacheByte = (Size) XLOG_BLCKSZ * XLOGbuffers;
XLogCtl->XLogCacheBlck = XLOGbuffers - 1;
XLogCtl->Insert.currpage = (XLogPageHeader) (XLogCtl->pages);
ThisTimeLineID = 1;
/* page buffer must be aligned suitably for O_DIRECT */
- buffer = (char *) palloc(BLCKSZ + ALIGNOF_XLOG_BUFFER);
+ buffer = (char *) palloc(XLOG_BLCKSZ + ALIGNOF_XLOG_BUFFER);
page = (XLogPageHeader) TYPEALIGN(ALIGNOF_XLOG_BUFFER, buffer);
- memset(page, 0, BLCKSZ);
+ memset(page, 0, XLOG_BLCKSZ);
/* Set up information for the initial checkpoint record */
checkPoint.redo.xlogid = 0;
/* Write the first page with the initial record */
errno = 0;
- if (write(openLogFile, page, BLCKSZ) != BLCKSZ)
+ if (write(openLogFile, page, XLOG_BLCKSZ) != XLOG_BLCKSZ)
{
/* if write didn't set errno, assume problem is no disk space */
if (errno == 0)
Insert->PrevRecord = LastRec;
XLogCtl->xlblocks[0].xlogid = openLogId;
XLogCtl->xlblocks[0].xrecoff =
- ((EndOfLog.xrecoff - 1) / BLCKSZ + 1) * BLCKSZ;
+ ((EndOfLog.xrecoff - 1) / XLOG_BLCKSZ + 1) * XLOG_BLCKSZ;
/*
* Tricky point here: readBuf contains the *last* block that the LastRec
* record spans, not the one it starts in. The last block is indeed the
* one we want to use.
*/
- Assert(readOff == (XLogCtl->xlblocks[0].xrecoff - BLCKSZ) % XLogSegSize);
- memcpy((char *) Insert->currpage, readBuf, BLCKSZ);
+ Assert(readOff == (XLogCtl->xlblocks[0].xrecoff - XLOG_BLCKSZ) % XLogSegSize);
+ memcpy((char *) Insert->currpage, readBuf, XLOG_BLCKSZ);
Insert->currpos = (char *) Insert->currpage +
- (EndOfLog.xrecoff + BLCKSZ - XLogCtl->xlblocks[0].xrecoff);
+ (EndOfLog.xrecoff + XLOG_BLCKSZ - XLogCtl->xlblocks[0].xrecoff);
LogwrtResult.Write = LogwrtResult.Flush = EndOfLog;
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.40 2006/03/05 15:58:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.41 2006/04/03 23:35:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
ControlFile.floatFormat = FLOATFORMAT_VALUE;
ControlFile.blcksz = BLCKSZ;
ControlFile.relseg_size = RELSEG_SIZE;
+ ControlFile.xlog_blcksz = XLOG_BLCKSZ;
ControlFile.xlog_seg_size = XLOG_SEG_SIZE;
ControlFile.nameDataLen = NAMEDATALEN;
ControlFile.indexMaxKeys = INDEX_MAX_KEYS;
/* we don't print floatFormat since can't say much useful about it */
printf(_("Database block size: %u\n"), ControlFile.blcksz);
printf(_("Blocks per segment of large relation: %u\n"), ControlFile.relseg_size);
+ printf(_("WAL block size: %u\n"), ControlFile.xlog_blcksz);
+ printf(_("Bytes per WAL segment: %u\n"), ControlFile.xlog_seg_size);
printf(_("Maximum length of identifiers: %u\n"), ControlFile.nameDataLen);
printf(_("Maximum columns in an index: %u\n"), ControlFile.indexMaxKeys);
printf(_("Date/time type storage: %s\n"),
int nbytes;
/* Use malloc() to ensure buffer is MAXALIGNED */
- buffer = (char *) malloc(BLCKSZ);
+ buffer = (char *) malloc(XLOG_BLCKSZ);
page = (XLogPageHeader) buffer;
- memset(buffer, 0, BLCKSZ);
+ memset(buffer, 0, XLOG_BLCKSZ);
/* Set up the XLOG page header */
page->xlp_magic = XLOG_PAGE_MAGIC;
}
errno = 0;
- if (write(fd, buffer, BLCKSZ) != BLCKSZ)
+ if (write(fd, buffer, XLOG_BLCKSZ) != XLOG_BLCKSZ)
{
/* if write didn't set errno, assume problem is no disk space */
if (errno == 0)
}
/* Fill the rest of the file with zeroes */
- memset(buffer, 0, BLCKSZ);
- for (nbytes = BLCKSZ; nbytes < XLogSegSize; nbytes += BLCKSZ)
+ memset(buffer, 0, XLOG_BLCKSZ);
+ for (nbytes = XLOG_BLCKSZ; nbytes < XLogSegSize; nbytes += XLOG_BLCKSZ)
{
errno = 0;
- if (write(fd, buffer, BLCKSZ) != BLCKSZ)
+ if (write(fd, buffer, XLOG_BLCKSZ) != XLOG_BLCKSZ)
{
if (errno == 0)
errno = ENOSPC;