pgsql: Use latch instead of select() in walreceiver

Lists: pgsql-committerspgsql-hackers
From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Use latch instead of select() in walreceiver
Date: 2016-12-02 01:29:49
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Use latch instead of select() in walreceiver

Replace use of poll()/select() by WaitLatchOrSocket(), which is more
portable and flexible.

Also change walreceiver to use its procLatch instead of a custom latch.

From: Petr Jelinek <petr(at)2ndquadrant(dot)com>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/597a87ccc9a6fa8af7f3cf280b1e24e41807d555

Modified Files
--------------
src/backend/postmaster/pgstat.c | 3 +
.../libpqwalreceiver/libpqwalreceiver.c | 101 +++++----------------
src/backend/replication/walreceiver.c | 18 ++--
src/backend/replication/walreceiverfuncs.c | 6 +-
src/include/pgstat.h | 1 +
src/include/replication/walreceiver.h | 3 +-
6 files changed, 43 insertions(+), 89 deletions(-)


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Use latch instead of select() in walreceiver
Date: 2016-12-02 01:50:30
Message-ID: CAB7nPqRA_cO_r_PLmRvFUtpvrTUeeBooXst1+oDecTPmTckp5A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Fri, Dec 2, 2016 at 10:29 AM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> Use latch instead of select() in walreceiver
>
> Replace use of poll()/select() by WaitLatchOrSocket(), which is more
> portable and flexible.
>
> Also change walreceiver to use its procLatch instead of a custom latch.
>
> From: Petr Jelinek <petr(at)2ndquadrant(dot)com>

+ ResetLatch(&MyProc->procLatch);
+ rc = WaitLatchOrSocket(&MyProc->procLatch,
+ WL_POSTMASTER_DEATH | WL_SOCKET_READABLE |
+ WL_LATCH_SET,
+ PQsocket(streamConn),
+ 0,
+ WAIT_EVENT_LIBPQWALRECEIVER_READ);
+ if (rc & WL_POSTMASTER_DEATH)
+ exit(1);
Hmm. We have always been very careful about not leaving immediately
from libpqwalreceiver.c which is an independent shared library so as
the WAL receiver can take cleanup actions. See here for more details:
https://www.postgresql.org/message-id/CAEepm=0hg_FX7kdUhosTpJ_kPsUZw6k-7nuQNy-dGAOaetn_tA@mail.gmail.com
--
Michael


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [COMMITTERS] pgsql: Use latch instead of select() in walreceiver
Date: 2016-12-04 01:16:12
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On 12/1/16 8:50 PM, Michael Paquier wrote:
> + if (rc & WL_POSTMASTER_DEATH)
> + exit(1);
> Hmm. We have always been very careful about not leaving immediately
> from libpqwalreceiver.c which is an independent shared library so as
> the WAL receiver can take cleanup actions. See here for more details:
> https://www.postgresql.org/message-id/CAEepm=0hg_FX7kdUhosTpJ_kPsUZw6k-7nuQNy-dGAOaetn_tA@mail.gmail.com

walreceiver.c does the same thing. The message you pointed out is not
exactly clear why that would be wrong.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services