Re: 9.2 pg_upgrade regression tests on WIndows

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 9.2 pg_upgrade regression tests on WIndows
Date: 2012-09-06 02:41:08
Message-ID: 20120906024108.GH29484@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Sep 5, 2012 at 10:35:26PM -0400, Andrew Dunstan wrote:
> >>Icky. I wish there were some nice portable flock() mechanism we could use.
> >>
> >>I just re-ran the test on the same machine, same code, same
> >>everything as the reporte3d failure, and it passed, so it definitely
> >>looks like it's a timing issue.
> >>
> >>I'd be inclined to put a loop around that fopen() to try it once
> >>every second for, say, 5 seconds.
> >Yes, good idea.
> >
>
> Suggested patch attached.
>
> cheers
>
> andrew
>

> diff --git a/contrib/pg_upgrade/exec.c b/contrib/pg_upgrade/exec.c
> index 99f5006..f84d857 100644
> --- a/contrib/pg_upgrade/exec.c
> +++ b/contrib/pg_upgrade/exec.c
> @@ -63,7 +63,25 @@ exec_prog(const char *log_file, const char *opt_log_file,
> if (written >= MAXCMDLEN)
> pg_log(PG_FATAL, "command too long\n");
>
> - if ((log = fopen_priv(log_file, "a")) == NULL)
> +#ifdef WIN32
> + {
> + /*
> + * Try to open the log file a few times in case the
> + * server takes a bit longer than we'd like to release it.
> + */
> + int iter;
> + for (iter = 0; iter < 5; iter++)
> + {
> + log = fopen_priv(log_file, "a");
> + if (log != NULL || iter == 4)
> + break;
> + sleep(1);
> + }
> + }
> +#else
> + log = fopen_priv(log_file, "a");
> +#endif
> + if (log == NULL)
> pg_log(PG_FATAL, "cannot write to log file %s\n", log_file);
> #ifdef WIN32
> fprintf(log, "\n\n");

I would like to see a more verbose comment, so we don't forget why we
did this. I think my inability to quickly discover the cause of the
previous log write problem is that I didn't document which file
descriptors are kept open on Windows. I suggest for a comment:

/*
* "pg_ctl -w stop" might have reported that the server has
* stopped because the postmaster.pid file has been removed,
* but "pg_ctl -w start" might still be in the process of
* closing and might still be holding its stdout and -l log
* file descriptors open. Therefore, try to open the log
* file a few times.
*/

Anyway, we can easily adjust the comment post-9.2.0.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2012-09-06 02:45:48 Re: 9.2 pg_upgrade regression tests on WIndows
Previous Message Andrew Dunstan 2012-09-06 02:35:26 Re: 9.2 pg_upgrade regression tests on WIndows