Re: Latch implementation that wakes on postmaster death on both win32 and Unix - Mailing list pgsql-hackers

From Fujii Masao
Subject Re: Latch implementation that wakes on postmaster death on both win32 and Unix
Date
Msg-id BANLkTikY=+dOLQgjtQtYB-01K7QUs0Cvjg@mail.gmail.com
Whole thread Raw
In response to Re: Latch implementation that wakes on postmaster death on both win32 and Unix  (Peter Geoghegan <peter@2ndquadrant.com>)
Responses Re: Latch implementation that wakes on postmaster death on both win32 and Unix
List pgsql-hackers
On Wed, Jun 22, 2011 at 9:11 PM, Peter Geoghegan <peter@2ndquadrant.com> wrote:
>>                rc = WaitForMultipleObjects(numevents, events, FALSE,
>>                                                           (timeout >= 0) ? (timeout / 1000) : INFINITE);
>> -               if (rc == WAIT_FAILED)
>> +               if ( (wakeEvents & WL_POSTMASTER_DEATH) &&
>> +                        !PostmasterIsAlive(true))
>>
>> After WaitForMultipleObjects() detects the death of postmaster,
>> WaitForSingleObject()
>> is called in PostmasterIsAlive(). In this case, what code does
>> WaitForSingleObject() return?
>> I wonder if WaitForSingleObject() returns the code other than
>> WAIT_TIMEOUT and really
>> can detect the death of postmaster.
>
> As noted up-thread, the fact that the archiver does wake and finish on
> Postmaster death can be clearly observed on Windows. I'm not sure why
> you wonder that, as this is fairly standard use of
> PostmasterIsAlive().

Because, if PostmasterHandle is an auto-reset event object, its event state
would be automatically reset just after WaitForMultipleObjects() detects
the postmaster death event, I was afraid. But your observation proved that
my concern was not right.

I have another comments:

+#ifndef WIN32
+    /*
+     * Initialise mechanism that allows waiting latch clients
+     * to wake on postmaster death, to finish their
+     * remaining business
+     */
+    InitPostmasterDeathWatchHandle();
+#endif

Calling this function before creating TopMemoryContext looks unsafe. What if
the function calls ereport(FATAL)?

That ereport() can be called before postgresql.conf is read, i.e., before GUCs
for error reporting are set. Is this OK? If not,
InitPostmasterDeathWatchHandle()
should be moved after SelectConfigFiles().

+#ifndef WIN32
+int postmaster_alive_fds[2];
+#endif

postmaster_alive_fds[] should be initialized to "{-1, -1}"?

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center


pgsql-hackers by date:

Previous
From: Noah Misch
Date:
Subject: Re: Another issue with invalid XML values
Next
From: Peter Geoghegan
Date:
Subject: Re: Latch implementation that wakes on postmaster death on both win32 and Unix