Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite6140d9

Browse files
committed
Don't use BLCKSZ for the physical length of the pg_control file, but
instead a dedicated symbol. This probably makes no functional differencefor likely values of BLCKSZ, but it makes the intent clearer.Simon Riggs, minor editorialization by Tom Lane.
1 parent147d4bf commite6140d9

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, 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.232 2006/04/03 23:35:03 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.233 2006/04/04 22:39:59 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -3391,7 +3391,7 @@ static void
33913391
WriteControlFile(void)
33923392
{
33933393
intfd;
3394-
charbuffer[BLCKSZ];/* need not be aligned */
3394+
charbuffer[PG_CONTROL_SIZE];/* need not be aligned */
33953395
char*localeptr;
33963396

33973397
/*
@@ -3437,17 +3437,16 @@ WriteControlFile(void)
34373437
FIN_CRC32(ControlFile->crc);
34383438

34393439
/*
3440-
* We write outBLCKSZ bytes into pg_control, zero-padding the excess over
3441-
* sizeof(ControlFileData). This reduces the odds of premature-EOF errors
3442-
* when reading pg_control. We'll still fail when we check the contents
3443-
* of the file, but hopefully with a more specific error than "couldn't
3444-
* read pg_control".
3440+
* We write outPG_CONTROL_SIZE bytes into pg_control, zero-padding the
3441+
*excess oversizeof(ControlFileData). This reduces the odds of
3442+
*premature-EOF errorswhen reading pg_control. We'll still fail when we
3443+
*check the contentsof the file, but hopefully with a more specific
3444+
*error than "couldn'tread pg_control".
34453445
*/
3446-
if (sizeof(ControlFileData)>BLCKSZ)
3447-
ereport(PANIC,
3448-
(errmsg("sizeof(ControlFileData) is larger than BLCKSZ; fix either one")));
3446+
if (sizeof(ControlFileData)>PG_CONTROL_SIZE)
3447+
elog(PANIC,"sizeof(ControlFileData) is larger than PG_CONTROL_SIZE; fix either one");
34493448

3450-
memset(buffer,0,BLCKSZ);
3449+
memset(buffer,0,PG_CONTROL_SIZE);
34513450
memcpy(buffer,ControlFile,sizeof(ControlFileData));
34523451

34533452
fd=BasicOpenFile(XLOG_CONTROL_FILE,
@@ -3460,7 +3459,7 @@ WriteControlFile(void)
34603459
XLOG_CONTROL_FILE)));
34613460

34623461
errno=0;
3463-
if (write(fd,buffer,BLCKSZ)!=BLCKSZ)
3462+
if (write(fd,buffer,PG_CONTROL_SIZE)!=PG_CONTROL_SIZE)
34643463
{
34653464
/* if write didn't set errno, assume problem is no disk space */
34663465
if (errno==0)

‎src/bin/pg_resetxlog/pg_resetxlog.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
26-
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.41 2006/04/03 23:35:04 tgl Exp $
26+
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.42 2006/04/04 22:39:59 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -365,9 +365,9 @@ ReadControlFile(void)
365365
}
366366

367367
/* Use malloc to ensure we have a maxaligned buffer */
368-
buffer= (char*)malloc(BLCKSZ);
368+
buffer= (char*)malloc(PG_CONTROL_SIZE);
369369

370-
len=read(fd,buffer,BLCKSZ);
370+
len=read(fd,buffer,PG_CONTROL_SIZE);
371371
if (len<0)
372372
{
373373
fprintf(stderr,_("%s: could not read file \"%s\": %s\n"),
@@ -546,7 +546,7 @@ static void
546546
RewriteControlFile(void)
547547
{
548548
intfd;
549-
charbuffer[BLCKSZ];/* need not be aligned */
549+
charbuffer[PG_CONTROL_SIZE];/* need not be aligned */
550550

551551
/*
552552
* Adjust fields as needed to force an empty XLOG starting at the next
@@ -587,21 +587,21 @@ RewriteControlFile(void)
587587
FIN_CRC32(ControlFile.crc);
588588

589589
/*
590-
* We write outBLCKSZ bytes into pg_control, zero-padding the excess over
591-
* sizeof(ControlFileData). This reduces the odds of premature-EOF errors
592-
* when reading pg_control. We'll still fail when we check the contents
593-
* of the file, but hopefully with a more specific error than "couldn't
594-
* read pg_control".
590+
* We write outPG_CONTROL_SIZE bytes into pg_control, zero-padding the
591+
*excess oversizeof(ControlFileData). This reduces the odds of
592+
*premature-EOF errorswhen reading pg_control. We'll still fail when we
593+
*check the contentsof the file, but hopefully with a more specific
594+
*error than "couldn'tread pg_control".
595595
*/
596-
if (sizeof(ControlFileData)>BLCKSZ)
596+
if (sizeof(ControlFileData)>PG_CONTROL_SIZE)
597597
{
598598
fprintf(stderr,
599-
_("%s: internal error -- sizeof(ControlFileData) is too large ... fixxlog.c\n"),
599+
_("%s: internal error -- sizeof(ControlFileData) is too large ... fixPG_CONTROL_SIZE\n"),
600600
progname);
601601
exit(1);
602602
}
603603

604-
memset(buffer,0,BLCKSZ);
604+
memset(buffer,0,PG_CONTROL_SIZE);
605605
memcpy(buffer,&ControlFile,sizeof(ControlFileData));
606606

607607
unlink(XLOG_CONTROL_FILE);
@@ -617,7 +617,7 @@ RewriteControlFile(void)
617617
}
618618

619619
errno=0;
620-
if (write(fd,buffer,BLCKSZ)!=BLCKSZ)
620+
if (write(fd,buffer,PG_CONTROL_SIZE)!=PG_CONTROL_SIZE)
621621
{
622622
/* if write didn't set errno, assume problem is no disk space */
623623
if (errno==0)

‎src/include/catalog/pg_control.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.28 2006/04/03 23:35:05 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.29 2006/04/04 22:39:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -147,4 +147,13 @@ typedef struct ControlFileData
147147
pg_crc32crc;
148148
}ControlFileData;
149149

150+
/*
151+
* Physical size of the pg_control file. Note that this is considerably
152+
* bigger than the actually used size (ie, sizeof(ControlFileData)).
153+
* The idea is to keep the physical size constant independent of format
154+
* changes, so that ReadControlFile will deliver a suitable wrong-version
155+
* message instead of a read error if it's looking at an incompatible file.
156+
*/
157+
#definePG_CONTROL_SIZE8192
158+
150159
#endif/* PG_CONTROL_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp