pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Fix race conditions and missed wakeups in syncrep worker signali
Date: Fri, 30 Jun 2017 18:57:24 +0000
Message-ID: <E1dR16a-0005zy-Gr@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Fix race conditions and missed wakeups in syncrep worker signaling.

When a sync worker is waiting for the associated apply worker to notice
that it's in SYNCWAIT state, wait_for_worker_state_change() would just
patiently wait for that to happen.  This generally required waiting for
the 1-second timeout in LogicalRepApplyLoop to elapse.  Kicking the worker
via its latch makes things significantly snappier.

While at it, fix race conditions that could potentially result in crashes:
we can *not* call logicalrep_worker_wakeup_ptr() once we've released the
LogicalRepWorkerLock, because worker->proc might've been reset to NULL
after we do that (indeed, there's no really solid reason to believe that
the LogicalRepWorker slot even belongs to the same worker anymore).
In logicalrep_worker_wakeup(), we can just move the wakeup inside the
lock scope.  In process_syncing_tables_for_apply(), a bit more code
rearrangement is needed.

Also improve some nearby comments.

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1f201a818a5910a37530cc929bd345688f827942

Modified Files
--------------
src/backend/replication/logical/launcher.c  |  12 ++-
src/backend/replication/logical/tablesync.c | 156 ++++++++++++++++------------
2 files changed, 100 insertions(+), 68 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


Message-ID: <E1dR16a-0005zy-Gr@gemulon.postgresql.org>
Permalink:  ../E1dR16a-0005zy-Gr@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1dR16a-0005zy-Gr@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix race conditions and missed wakeups in syncrep worker signali
  In-Reply-To: <E1dR16a-0005zy-Gr@gemulon.postgresql.org>
  References: <E1dR16a-0005zy-Gr@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox