7
7
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.231 2006/03/31 23:32:05 tgl Exp $
10
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.232 2006/04/03 23:35:03 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
113
113
114
114
/*
115
115
* Limitation of buffer-alignment for direct IO depends on OS and filesystem,
116
- * but BLCKSZ is assumed to be enough for it.
116
+ * but XLOG_BLCKSZ is assumed to be enough for it.
117
117
*/
118
118
#ifdef O_DIRECT
119
- #define ALIGNOF_XLOG_BUFFER BLCKSZ
119
+ #define ALIGNOF_XLOG_BUFFER XLOG_BLCKSZ
120
120
#else
121
121
#define ALIGNOF_XLOG_BUFFER ALIGNOF_BUFFER
122
122
#endif
@@ -374,7 +374,7 @@ typedef struct XLogCtlData
374
374
* and xlblocks values depends on WALInsertLock and WALWriteLock.
375
375
*/
376
376
char * pages ; /* buffers for unwritten XLOG pages */
377
- XLogRecPtr * xlblocks ; /* 1st byte ptr-s + BLCKSZ */
377
+ XLogRecPtr * xlblocks ; /* 1st byte ptr-s + XLOG_BLCKSZ */
378
378
Size XLogCacheByte ; /* # bytes in xlog buffers */
379
379
int XLogCacheBlck ; /* highest allocated xlog buffer index */
380
380
TimeLineID ThisTimeLineID ;
@@ -397,7 +397,7 @@ static ControlFileData *ControlFile = NULL;
397
397
398
398
/* Free space remaining in the current xlog page buffer */
399
399
#define INSERT_FREESPACE (Insert ) \
400
- (BLCKSZ - ((Insert)->currpos - (char *) (Insert)->currpage))
400
+ (XLOG_BLCKSZ - ((Insert)->currpos - (char *) (Insert)->currpage))
401
401
402
402
/* Construct XLogRecPtr value for current insertion point */
403
403
#define INSERT_RECPTR (recptr ,Insert ,curridx ) \
@@ -441,7 +441,7 @@ static uint32 readId = 0;
441
441
static uint32 readSeg = 0 ;
442
442
static uint32 readOff = 0 ;
443
443
444
- /* Buffer for currently read page (BLCKSZ bytes) */
444
+ /* Buffer for currently read page (XLOG_BLCKSZ bytes) */
445
445
static char * readBuf = NULL ;
446
446
447
447
/* Buffer for current ReadRecord result (expandable) */
@@ -706,7 +706,7 @@ begin:;
706
706
* If cache is half filled then try to acquire write lock and do
707
707
* XLogWrite. Ignore any fractional blocks in performing this check.
708
708
*/
709
- LogwrtRqst .Write .xrecoff -= LogwrtRqst .Write .xrecoff % BLCKSZ ;
709
+ LogwrtRqst .Write .xrecoff -= LogwrtRqst .Write .xrecoff % XLOG_BLCKSZ ;
710
710
if (LogwrtRqst .Write .xlogid != LogwrtResult .Write .xlogid ||
711
711
(LogwrtRqst .Write .xrecoff >= LogwrtResult .Write .xrecoff +
712
712
XLogCtl -> XLogCacheByte / 2 ))
@@ -1228,12 +1228,12 @@ AdvanceXLInsertBuffer(void)
1228
1228
{
1229
1229
/* crossing a logid boundary */
1230
1230
NewPageEndPtr .xlogid += 1 ;
1231
- NewPageEndPtr .xrecoff = BLCKSZ ;
1231
+ NewPageEndPtr .xrecoff = XLOG_BLCKSZ ;
1232
1232
}
1233
1233
else
1234
- NewPageEndPtr .xrecoff += BLCKSZ ;
1234
+ NewPageEndPtr .xrecoff += XLOG_BLCKSZ ;
1235
1235
XLogCtl -> xlblocks [nextidx ] = NewPageEndPtr ;
1236
- NewPage = (XLogPageHeader ) (XLogCtl -> pages + nextidx * (Size ) BLCKSZ );
1236
+ NewPage = (XLogPageHeader ) (XLogCtl -> pages + nextidx * (Size ) XLOG_BLCKSZ );
1237
1237
1238
1238
Insert -> curridx = nextidx ;
1239
1239
Insert -> currpage = NewPage ;
@@ -1244,7 +1244,7 @@ AdvanceXLInsertBuffer(void)
1244
1244
* Be sure to re-zero the buffer so that bytes beyond what we've written
1245
1245
* will look like zeroes and not valid XLOG records...
1246
1246
*/
1247
- MemSet ((char * ) NewPage , 0 , BLCKSZ );
1247
+ MemSet ((char * ) NewPage , 0 , XLOG_BLCKSZ );
1248
1248
1249
1249
/*
1250
1250
* Fill the new page's header
@@ -1254,7 +1254,7 @@ AdvanceXLInsertBuffer(void)
1254
1254
/* NewPage->xlp_info = 0; */ /* done by memset */
1255
1255
NewPage -> xlp_tli = ThisTimeLineID ;
1256
1256
NewPage -> xlp_pageaddr .xlogid = NewPageEndPtr .xlogid ;
1257
- NewPage -> xlp_pageaddr .xrecoff = NewPageEndPtr .xrecoff - BLCKSZ ;
1257
+ NewPage -> xlp_pageaddr .xrecoff = NewPageEndPtr .xrecoff - XLOG_BLCKSZ ;
1258
1258
1259
1259
/*
1260
1260
* If first page of an XLOG segment file, make it a long header.
@@ -1428,7 +1428,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
1428
1428
{
1429
1429
/* first of group */
1430
1430
startidx = curridx ;
1431
- startoffset = (LogwrtResult .Write .xrecoff - BLCKSZ ) % XLogSegSize ;
1431
+ startoffset = (LogwrtResult .Write .xrecoff - XLOG_BLCKSZ ) % XLogSegSize ;
1432
1432
}
1433
1433
npages ++ ;
1434
1434
@@ -1439,7 +1439,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
1439
1439
* segment.
1440
1440
*/
1441
1441
finishing_seg = !ispartialpage &&
1442
- (startoffset + npages * BLCKSZ ) >= XLogSegSize ;
1442
+ (startoffset + npages * XLOG_BLCKSZ ) >= XLogSegSize ;
1443
1443
1444
1444
if (!XLByteLT (LogwrtResult .Write , WriteRqst .Write ) ||
1445
1445
curridx == XLogCtl -> XLogCacheBlck ||
@@ -1461,8 +1461,8 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
1461
1461
}
1462
1462
1463
1463
/* OK to write the page(s) */
1464
- from = XLogCtl -> pages + startidx * (Size ) BLCKSZ ;
1465
- nbytes = npages * (Size ) BLCKSZ ;
1464
+ from = XLogCtl -> pages + startidx * (Size ) XLOG_BLCKSZ ;
1465
+ nbytes = npages * (Size ) XLOG_BLCKSZ ;
1466
1466
errno = 0 ;
1467
1467
if (write (openLogFile , from , nbytes ) != nbytes )
1468
1468
{
@@ -1720,7 +1720,7 @@ XLogFileInit(uint32 log, uint32 seg,
1720
1720
{
1721
1721
char path [MAXPGPATH ];
1722
1722
char tmppath [MAXPGPATH ];
1723
- char zbuffer [BLCKSZ ];
1723
+ char zbuffer [XLOG_BLCKSZ ];
1724
1724
uint32 installed_log ;
1725
1725
uint32 installed_seg ;
1726
1726
int max_advance ;
@@ -1858,7 +1858,7 @@ XLogFileCopy(uint32 log, uint32 seg,
1858
1858
{
1859
1859
char path [MAXPGPATH ];
1860
1860
char tmppath [MAXPGPATH ];
1861
- char buffer [BLCKSZ ];
1861
+ char buffer [XLOG_BLCKSZ ];
1862
1862
int srcfd ;
1863
1863
int fd ;
1864
1864
int nbytes ;
@@ -2637,7 +2637,7 @@ ReadRecord(XLogRecPtr *RecPtr, int emode)
2637
2637
* (2) a static char array isn't guaranteed to have any particular
2638
2638
* alignment, whereas malloc() will provide MAXALIGN'd storage.
2639
2639
*/
2640
- readBuf = (char * ) malloc (BLCKSZ );
2640
+ readBuf = (char * ) malloc (XLOG_BLCKSZ );
2641
2641
Assert (readBuf != NULL );
2642
2642
}
2643
2643
@@ -2651,8 +2651,8 @@ ReadRecord(XLogRecPtr *RecPtr, int emode)
2651
2651
goto got_record ;
2652
2652
}
2653
2653
/* align old recptr to next page */
2654
- if (tmpRecPtr .xrecoff % BLCKSZ != 0 )
2655
- tmpRecPtr .xrecoff += (BLCKSZ - tmpRecPtr .xrecoff % BLCKSZ );
2654
+ if (tmpRecPtr .xrecoff % XLOG_BLCKSZ != 0 )
2655
+ tmpRecPtr .xrecoff += (XLOG_BLCKSZ - tmpRecPtr .xrecoff % XLOG_BLCKSZ );
2656
2656
if (tmpRecPtr .xrecoff >= XLogFileSize )
2657
2657
{
2658
2658
(tmpRecPtr .xlogid )++ ;
@@ -2696,7 +2696,7 @@ ReadRecord(XLogRecPtr *RecPtr, int emode)
2696
2696
readOff = (uint32 ) (-1 ); /* force read to occur below */
2697
2697
}
2698
2698
2699
- targetPageOff = ((RecPtr -> xrecoff % XLogSegSize ) / BLCKSZ ) * BLCKSZ ;
2699
+ targetPageOff = ((RecPtr -> xrecoff % XLogSegSize ) / XLOG_BLCKSZ ) * XLOG_BLCKSZ ;
2700
2700
if (readOff != targetPageOff )
2701
2701
{
2702
2702
readOff = targetPageOff ;
@@ -2708,7 +2708,7 @@ ReadRecord(XLogRecPtr *RecPtr, int emode)
2708
2708
readId , readSeg , readOff )));
2709
2709
goto next_record_is_invalid ;
2710
2710
}
2711
- if (read (readFile , readBuf , BLCKSZ ) != BLCKSZ )
2711
+ if (read (readFile , readBuf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
2712
2712
{
2713
2713
ereport (emode ,
2714
2714
(errcode_for_file_access (),
@@ -2720,7 +2720,7 @@ ReadRecord(XLogRecPtr *RecPtr, int emode)
2720
2720
goto next_record_is_invalid ;
2721
2721
}
2722
2722
pageHeaderSize = XLogPageHeaderSize ((XLogPageHeader ) readBuf );
2723
- targetRecOff = RecPtr -> xrecoff % BLCKSZ ;
2723
+ targetRecOff = RecPtr -> xrecoff % XLOG_BLCKSZ ;
2724
2724
if (targetRecOff == 0 )
2725
2725
{
2726
2726
/*
@@ -2746,7 +2746,7 @@ ReadRecord(XLogRecPtr *RecPtr, int emode)
2746
2746
RecPtr -> xlogid , RecPtr -> xrecoff )));
2747
2747
goto next_record_is_invalid ;
2748
2748
}
2749
- record = (XLogRecord * ) ((char * ) readBuf + RecPtr -> xrecoff % BLCKSZ );
2749
+ record = (XLogRecord * ) ((char * ) readBuf + RecPtr -> xrecoff % XLOG_BLCKSZ );
2750
2750
2751
2751
got_record :;
2752
2752
@@ -2811,17 +2811,18 @@ got_record:;
2811
2811
2812
2812
/*
2813
2813
* Allocate or enlarge readRecordBuf as needed. To avoid useless small
2814
- * increases, round its size to a multiple of BLCKSZ, and make sure it's
2815
- * at least 4*BLCKSZ to start with. (That is enough for all "normal"
2816
- * records, but very large commit or abort records might need more space.)
2814
+ * increases, round its size to a multiple of XLOG_BLCKSZ, and make sure
2815
+ * it's at least 4*Max(BLCKSZ, XLOG_BLCKSZ) to start with. (That is
2816
+ * enough for all "normal" records, but very large commit or abort records
2817
+ * might need more space.)
2817
2818
*/
2818
2819
total_len = record -> xl_tot_len ;
2819
2820
if (total_len > readRecordBufSize )
2820
2821
{
2821
2822
uint32 newSize = total_len ;
2822
2823
2823
- newSize += BLCKSZ - (newSize % BLCKSZ );
2824
- newSize = Max (newSize , 4 * BLCKSZ );
2824
+ newSize += XLOG_BLCKSZ - (newSize % XLOG_BLCKSZ );
2825
+ newSize = Max (newSize , 4 * Max ( BLCKSZ , XLOG_BLCKSZ ) );
2825
2826
if (readRecordBuf )
2826
2827
free (readRecordBuf );
2827
2828
readRecordBuf = (char * ) malloc (newSize );
@@ -2839,7 +2840,7 @@ got_record:;
2839
2840
2840
2841
buffer = readRecordBuf ;
2841
2842
nextRecord = NULL ;
2842
- len = BLCKSZ - RecPtr -> xrecoff % BLCKSZ ;
2843
+ len = XLOG_BLCKSZ - RecPtr -> xrecoff % XLOG_BLCKSZ ;
2843
2844
if (total_len > len )
2844
2845
{
2845
2846
/* Need to reassemble record */
@@ -2851,7 +2852,7 @@ got_record:;
2851
2852
buffer += len ;
2852
2853
for (;;)
2853
2854
{
2854
- readOff += BLCKSZ ;
2855
+ readOff += XLOG_BLCKSZ ;
2855
2856
if (readOff >= XLogSegSize )
2856
2857
{
2857
2858
close (readFile );
@@ -2862,7 +2863,7 @@ got_record:;
2862
2863
goto next_record_is_invalid ;
2863
2864
readOff = 0 ;
2864
2865
}
2865
- if (read (readFile , readBuf , BLCKSZ ) != BLCKSZ )
2866
+ if (read (readFile , readBuf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
2866
2867
{
2867
2868
ereport (emode ,
2868
2869
(errcode_for_file_access (),
@@ -2890,7 +2891,7 @@ got_record:;
2890
2891
readId , readSeg , readOff )));
2891
2892
goto next_record_is_invalid ;
2892
2893
}
2893
- len = BLCKSZ - pageHeaderSize - SizeOfXLogContRecord ;
2894
+ len = XLOG_BLCKSZ - pageHeaderSize - SizeOfXLogContRecord ;
2894
2895
if (contrecord -> xl_rem_len > len )
2895
2896
{
2896
2897
memcpy (buffer , (char * ) contrecord + SizeOfXLogContRecord , len );
@@ -2905,7 +2906,7 @@ got_record:;
2905
2906
if (!RecordIsValid (record , * RecPtr , emode ))
2906
2907
goto next_record_is_invalid ;
2907
2908
pageHeaderSize = XLogPageHeaderSize ((XLogPageHeader ) readBuf );
2908
- if (BLCKSZ - SizeOfXLogRecord >= pageHeaderSize +
2909
+ if (XLOG_BLCKSZ - SizeOfXLogRecord >= pageHeaderSize +
2909
2910
MAXALIGN (SizeOfXLogContRecord + contrecord -> xl_rem_len ))
2910
2911
{
2911
2912
nextRecord = (XLogRecord * ) ((char * ) contrecord +
@@ -2922,7 +2923,7 @@ got_record:;
2922
2923
/* Record does not cross a page boundary */
2923
2924
if (!RecordIsValid (record , * RecPtr , emode ))
2924
2925
goto next_record_is_invalid ;
2925
- if (BLCKSZ - SizeOfXLogRecord >= RecPtr -> xrecoff % BLCKSZ +
2926
+ if (XLOG_BLCKSZ - SizeOfXLogRecord >= RecPtr -> xrecoff % XLOG_BLCKSZ +
2926
2927
MAXALIGN (total_len ))
2927
2928
nextRecord = (XLogRecord * ) ((char * ) record + MAXALIGN (total_len ));
2928
2929
EndRecPtr .xlogid = RecPtr -> xlogid ;
@@ -3404,6 +3405,7 @@ WriteControlFile(void)
3404
3405
3405
3406
ControlFile -> blcksz = BLCKSZ ;
3406
3407
ControlFile -> relseg_size = RELSEG_SIZE ;
3408
+ ControlFile -> xlog_blcksz = XLOG_BLCKSZ ;
3407
3409
ControlFile -> xlog_seg_size = XLOG_SEG_SIZE ;
3408
3410
3409
3411
ControlFile -> nameDataLen = NAMEDATALEN ;
@@ -3572,6 +3574,13 @@ ReadControlFile(void)
3572
3574
" but the server was compiled with RELSEG_SIZE %d." ,
3573
3575
ControlFile -> relseg_size , RELSEG_SIZE ),
3574
3576
errhint ("It looks like you need to recompile or initdb." )));
3577
+ if (ControlFile -> xlog_blcksz != XLOG_BLCKSZ )
3578
+ ereport (FATAL ,
3579
+ (errmsg ("database files are incompatible with server" ),
3580
+ errdetail ("The database cluster was initialized with XLOG_BLCKSZ %d,"
3581
+ " but the server was compiled with XLOG_BLCKSZ %d." ,
3582
+ ControlFile -> xlog_blcksz , XLOG_BLCKSZ ),
3583
+ errhint ("It looks like you need to recompile or initdb." )));
3575
3584
if (ControlFile -> xlog_seg_size != XLOG_SEG_SIZE )
3576
3585
ereport (FATAL ,
3577
3586
(errmsg ("database files are incompatible with server" ),
@@ -3696,7 +3705,7 @@ XLOGShmemSize(void)
3696
3705
/* extra alignment padding for XLOG I/O buffers */
3697
3706
size = add_size (size , ALIGNOF_XLOG_BUFFER );
3698
3707
/* and the buffers themselves */
3699
- size = add_size (size , mul_size (BLCKSZ , XLOGbuffers ));
3708
+ size = add_size (size , mul_size (XLOG_BLCKSZ , XLOGbuffers ));
3700
3709
3701
3710
/*
3702
3711
* Note: we don't count ControlFileData, it comes out of the "slop factor"
@@ -3743,13 +3752,13 @@ XLOGShmemInit(void)
3743
3752
*/
3744
3753
allocptr = (char * ) TYPEALIGN (ALIGNOF_XLOG_BUFFER , allocptr );
3745
3754
XLogCtl -> pages = allocptr ;
3746
- memset (XLogCtl -> pages , 0 , (Size ) BLCKSZ * XLOGbuffers );
3755
+ memset (XLogCtl -> pages , 0 , (Size ) XLOG_BLCKSZ * XLOGbuffers );
3747
3756
3748
3757
/*
3749
3758
* Do basic initialization of XLogCtl shared data. (StartupXLOG will fill
3750
3759
* in additional info.)
3751
3760
*/
3752
- XLogCtl -> XLogCacheByte = (Size ) BLCKSZ * XLOGbuffers ;
3761
+ XLogCtl -> XLogCacheByte = (Size ) XLOG_BLCKSZ * XLOGbuffers ;
3753
3762
3754
3763
XLogCtl -> XLogCacheBlck = XLOGbuffers - 1 ;
3755
3764
XLogCtl -> Insert .currpage = (XLogPageHeader ) (XLogCtl -> pages );
@@ -3801,9 +3810,9 @@ BootStrapXLOG(void)
3801
3810
ThisTimeLineID = 1 ;
3802
3811
3803
3812
/* page buffer must be aligned suitably for O_DIRECT */
3804
- buffer = (char * ) palloc (BLCKSZ + ALIGNOF_XLOG_BUFFER );
3813
+ buffer = (char * ) palloc (XLOG_BLCKSZ + ALIGNOF_XLOG_BUFFER );
3805
3814
page = (XLogPageHeader ) TYPEALIGN (ALIGNOF_XLOG_BUFFER , buffer );
3806
- memset (page , 0 , BLCKSZ );
3815
+ memset (page , 0 , XLOG_BLCKSZ );
3807
3816
3808
3817
/* Set up information for the initial checkpoint record */
3809
3818
checkPoint .redo .xlogid = 0 ;
@@ -3855,7 +3864,7 @@ BootStrapXLOG(void)
3855
3864
3856
3865
/* Write the first page with the initial record */
3857
3866
errno = 0 ;
3858
- if (write (openLogFile , page , BLCKSZ ) != BLCKSZ )
3867
+ if (write (openLogFile , page , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
3859
3868
{
3860
3869
/* if write didn't set errno, assume problem is no disk space */
3861
3870
if (errno == 0 )
@@ -4712,17 +4721,17 @@ StartupXLOG(void)
4712
4721
Insert -> PrevRecord = LastRec ;
4713
4722
XLogCtl -> xlblocks [0 ].xlogid = openLogId ;
4714
4723
XLogCtl -> xlblocks [0 ].xrecoff =
4715
- ((EndOfLog .xrecoff - 1 ) / BLCKSZ + 1 ) * BLCKSZ ;
4724
+ ((EndOfLog .xrecoff - 1 ) / XLOG_BLCKSZ + 1 ) * XLOG_BLCKSZ ;
4716
4725
4717
4726
/*
4718
4727
* Tricky point here: readBuf contains the *last* block that the LastRec
4719
4728
* record spans, not the one it starts in. The last block is indeed the
4720
4729
* one we want to use.
4721
4730
*/
4722
- Assert (readOff == (XLogCtl -> xlblocks [0 ].xrecoff - BLCKSZ ) % XLogSegSize );
4723
- memcpy ((char * ) Insert -> currpage , readBuf , BLCKSZ );
4731
+ Assert (readOff == (XLogCtl -> xlblocks [0 ].xrecoff - XLOG_BLCKSZ ) % XLogSegSize );
4732
+ memcpy ((char * ) Insert -> currpage , readBuf , XLOG_BLCKSZ );
4724
4733
Insert -> currpos = (char * ) Insert -> currpage +
4725
- (EndOfLog .xrecoff + BLCKSZ - XLogCtl -> xlblocks [0 ].xrecoff );
4734
+ (EndOfLog .xrecoff + XLOG_BLCKSZ - XLogCtl -> xlblocks [0 ].xrecoff );
4726
4735
4727
4736
LogwrtResult .Write = LogwrtResult .Flush = EndOfLog ;
4728
4737
0 commit comments