On Tue, 2006-04-04 at 11:13 -0400, Tom Lane wrote:
> Simon Riggs <[EMAIL PROTECTED]> writes:
> > I see you've changed the control file back from XLOG_BLCKSZ to BLCKSZ; I
> > wasn't sure which one of those to choose.
> 
> Hm.  The entire point of having a BLCKSZ-sized control file is to have
> it *not* change in size across format revisions (see the comments) ...
> which I suppose means that we really ought to have a hard-wired separate
> constant, rather than depending on something that someone might want to
> twiddle.

Patch enclosed. 

Tests with make check and this sequence of actions works fine also...
initdb b512
pg_controldata b512
pg_resetxlog b512
pg_controldata b512

Best Regards, Simon Riggs
Index: src/backend/access/transam/xlog.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/xlog.c,v
retrieving revision 1.232
diff -c -r1.232 xlog.c
*** src/backend/access/transam/xlog.c	3 Apr 2006 23:35:03 -0000	1.232
--- src/backend/access/transam/xlog.c	4 Apr 2006 16:16:55 -0000
***************
*** 3391,3397 ****
  WriteControlFile(void)
  {
  	int			fd;
! 	char		buffer[BLCKSZ]; /* need not be aligned */
  	char	   *localeptr;
  
  	/*
--- 3391,3397 ----
  WriteControlFile(void)
  {
  	int			fd;
! 	char		buffer[XLOG_CONTROL_BLCKSZ]; /* need not be aligned */
  	char	   *localeptr;
  
  	/*
***************
*** 3437,3453 ****
  	FIN_CRC32(ControlFile->crc);
  
  	/*
! 	 * We write out BLCKSZ bytes into pg_control, zero-padding the excess over
! 	 * sizeof(ControlFileData).  This reduces the odds of premature-EOF errors
! 	 * when reading pg_control.  We'll still fail when we check the contents
! 	 * of the file, but hopefully with a more specific error than "couldn't
! 	 * read pg_control".
  	 */
! 	if (sizeof(ControlFileData) > BLCKSZ)
  		ereport(PANIC,
! 				(errmsg("sizeof(ControlFileData) is larger than BLCKSZ; fix either one")));
  
! 	memset(buffer, 0, BLCKSZ);
  	memcpy(buffer, ControlFile, sizeof(ControlFileData));
  
  	fd = BasicOpenFile(XLOG_CONTROL_FILE,
--- 3437,3453 ----
  	FIN_CRC32(ControlFile->crc);
  
  	/*
! 	 * We write out XLOG_CONTROL_BLCKSZ bytes into pg_control, zero-padding the 
!      * excess over sizeof(ControlFileData).  This reduces the odds of 
!      * premature-EOF errors when reading pg_control.  We'll still fail when we
!      * check the contents of the file, but hopefully with a more specific error 
!      * than "couldn't read pg_control".
  	 */
! 	if (sizeof(ControlFileData) > XLOG_CONTROL_BLCKSZ)
  		ereport(PANIC,
! 				(errmsg("sizeof(ControlFileData) is larger than XLOG_CONTROL_BLCKSZ; fix either one")));
  
! 	memset(buffer, 0, XLOG_CONTROL_BLCKSZ);
  	memcpy(buffer, ControlFile, sizeof(ControlFileData));
  
  	fd = BasicOpenFile(XLOG_CONTROL_FILE,
***************
*** 3460,3466 ****
  						XLOG_CONTROL_FILE)));
  
  	errno = 0;
! 	if (write(fd, buffer, BLCKSZ) != BLCKSZ)
  	{
  		/* if write didn't set errno, assume problem is no disk space */
  		if (errno == 0)
--- 3460,3466 ----
  						XLOG_CONTROL_FILE)));
  
  	errno = 0;
! 	if (write(fd, buffer, XLOG_CONTROL_BLCKSZ) != XLOG_CONTROL_BLCKSZ)
  	{
  		/* if write didn't set errno, assume problem is no disk space */
  		if (errno == 0)
Index: src/bin/pg_resetxlog/pg_resetxlog.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v
retrieving revision 1.41
diff -c -r1.41 pg_resetxlog.c
*** src/bin/pg_resetxlog/pg_resetxlog.c	3 Apr 2006 23:35:04 -0000	1.41
--- src/bin/pg_resetxlog/pg_resetxlog.c	4 Apr 2006 16:16:57 -0000
***************
*** 365,373 ****
  	}
  
  	/* Use malloc to ensure we have a maxaligned buffer */
! 	buffer = (char *) malloc(BLCKSZ);
  
! 	len = read(fd, buffer, BLCKSZ);
  	if (len < 0)
  	{
  		fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
--- 365,373 ----
  	}
  
  	/* Use malloc to ensure we have a maxaligned buffer */
! 	buffer = (char *) malloc(XLOG_CONTROL_BLCKSZ);
  
! 	len = read(fd, buffer, XLOG_CONTROL_BLCKSZ);
  	if (len < 0)
  	{
  		fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
***************
*** 546,552 ****
  RewriteControlFile(void)
  {
  	int			fd;
! 	char		buffer[BLCKSZ]; /* need not be aligned */
  
  	/*
  	 * Adjust fields as needed to force an empty XLOG starting at the next
--- 546,552 ----
  RewriteControlFile(void)
  {
  	int			fd;
! 	char		buffer[XLOG_CONTROL_BLCKSZ]; /* need not be aligned */
  
  	/*
  	 * Adjust fields as needed to force an empty XLOG starting at the next
***************
*** 587,607 ****
  	FIN_CRC32(ControlFile.crc);
  
  	/*
! 	 * We write out BLCKSZ bytes into pg_control, zero-padding the excess over
! 	 * sizeof(ControlFileData).  This reduces the odds of premature-EOF errors
! 	 * when reading pg_control.  We'll still fail when we check the contents
! 	 * of the file, but hopefully with a more specific error than "couldn't
! 	 * read pg_control".
  	 */
! 	if (sizeof(ControlFileData) > BLCKSZ)
  	{
  		fprintf(stderr,
! 				_("%s: internal error -- sizeof(ControlFileData) is too large ... fix xlog.c\n"),
  				progname);
  		exit(1);
  	}
  
! 	memset(buffer, 0, BLCKSZ);
  	memcpy(buffer, &ControlFile, sizeof(ControlFileData));
  
  	unlink(XLOG_CONTROL_FILE);
--- 587,607 ----
  	FIN_CRC32(ControlFile.crc);
  
  	/*
! 	 * We write out XLOG_CONTROL_BLCKSZ bytes into pg_control, zero-padding the 
!      * excess over sizeof(ControlFileData).  This reduces the odds of 
!      * premature-EOF errors when reading pg_control.  We'll still fail when we
!      * check the contents of the file, but hopefully with a more specific error 
!      * than "couldn't read pg_control".
  	 */
! 	if (sizeof(ControlFileData) > XLOG_CONTROL_BLCKSZ)
  	{
  		fprintf(stderr,
! 				_("%s: internal error -- sizeof(ControlFileData) is too large ... fix XLOG_CONTROL_BLCKSZ\n"),
  				progname);
  		exit(1);
  	}
  
! 	memset(buffer, 0, XLOG_CONTROL_BLCKSZ);
  	memcpy(buffer, &ControlFile, sizeof(ControlFileData));
  
  	unlink(XLOG_CONTROL_FILE);
***************
*** 617,623 ****
  	}
  
  	errno = 0;
! 	if (write(fd, buffer, BLCKSZ) != BLCKSZ)
  	{
  		/* if write didn't set errno, assume problem is no disk space */
  		if (errno == 0)
--- 617,623 ----
  	}
  
  	errno = 0;
! 	if (write(fd, buffer, XLOG_CONTROL_BLCKSZ) != XLOG_CONTROL_BLCKSZ)
  	{
  		/* if write didn't set errno, assume problem is no disk space */
  		if (errno == 0)
Index: src/include/access/xlog_internal.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/access/xlog_internal.h,v
retrieving revision 1.12
diff -c -r1.12 xlog_internal.h
*** src/include/access/xlog_internal.h	3 Apr 2006 23:35:04 -0000	1.12
--- src/include/access/xlog_internal.h	4 Apr 2006 16:16:58 -0000
***************
*** 190,195 ****
--- 190,196 ----
   */
  #define XLOGDIR				"pg_xlog"
  #define XLOG_CONTROL_FILE	"global/pg_control"
+ #define XLOG_CONTROL_BLCKSZ 512
  
  /*
   * These macros encapsulate knowledge about the exact layout of XLog file
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to