Skip to content

Commit e6140d9

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 difference for likely values of BLCKSZ, but it makes the intent clearer. Simon Riggs, minor editorialization by Tom Lane.
1 parent 147d4bf commit e6140d9

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
int fd;
3394-
char buffer[BLCKSZ]; /* need not be aligned */
3394+
char buffer[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 out BLCKSZ 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 out PG_CONTROL_SIZE bytes into pg_control, zero-padding the
3441+
* excess over sizeof(ControlFileData). This reduces the odds of
3442+
* premature-EOF errors when reading pg_control. We'll still fail when we
3443+
* check the contents of the file, but hopefully with a more specific
3444+
* error than "couldn't read 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
int fd;
549-
char buffer[BLCKSZ]; /* need not be aligned */
549+
char buffer[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 out BLCKSZ 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 out PG_CONTROL_SIZE bytes into pg_control, zero-padding the
591+
* excess over sizeof(ControlFileData). This reduces the odds of
592+
* premature-EOF errors when reading pg_control. We'll still fail when we
593+
* check the contents of the file, but hopefully with a more specific
594+
* error than "couldn't read 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 ... fix xlog.c\n"),
599+
_("%s: internal error -- sizeof(ControlFileData) is too large ... fix PG_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_crc32 crc;
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+
#define PG_CONTROL_SIZE 8192
158+
150159
#endif /* PG_CONTROL_H */

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