aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2020-04-25 10:18:12 -0700
committerNoah Misch <noah@leadboat.com>2020-04-25 10:18:12 -0700
commitf246ea3b2a5e0b75e44f0f18157c4b5e10b5547f (patch)
tree3570f7790e1244103ce570bbfc8f2171a22f8875 /src
parent72a3dc321d76c93842d502793f93b9dc2d2305b2 (diff)
downloadpostgresql-f246ea3b2a5e0b75e44f0f18157c4b5e10b5547f.tar.gz
postgresql-f246ea3b2a5e0b75e44f0f18157c4b5e10b5547f.zip
In caught-up logical walsender, sleep only in WalSndWaitForWal().
Before sleeping, WalSndWaitForWal() sends a keepalive if MyWalSnd->write < sentPtr. When the latest physical LSN yields no logical replication messages (a common case), that keepalive elicits a reply. Processing the reply updates pg_stat_replication.replay_lsn. WalSndLoop() lacks that; when WalSndLoop() slept, replay_lsn advancement could stall until wal_receiver_status_interval elapsed. This sometimes stalled src/test/subscription/t/001_rep_changes.pl for up to 10s. Reviewed by Fujii Masao and Michael Paquier. Discussion: https://postgr.es/m/20200418070142.GA1075445@rfd.leadboat.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/replication/walsender.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 0813c830269..6c87f6087ce 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1428,8 +1428,10 @@ WalSndWaitForWal(XLogRecPtr loc)
/*
* We only send regular messages to the client for full decoded
* transactions, but a synchronous replication and walsender shutdown
- * possibly are waiting for a later location. So we send pings
- * containing the flush location every now and then.
+ * possibly are waiting for a later location. So, before sleeping, we
+ * send a ping containing the flush location. If the receiver is
+ * otherwise idle, this keepalive will trigger a reply. Processing the
+ * reply will update these MyWalSnd locations.
*/
if (MyWalSnd->flush < sentPtr &&
MyWalSnd->write < sentPtr &&
@@ -2314,14 +2316,14 @@ WalSndLoop(WalSndSendDataCallback send_data)
WalSndKeepaliveIfNecessary();
/*
- * We don't block if not caught up, unless there is unsent data
- * pending in which case we'd better block until the socket is
- * write-ready. This test is only needed for the case where the
- * send_data callback handled a subset of the available data but then
- * pq_flush_if_writable flushed it all --- we should immediately try
- * to send more.
+ * Block if we have unsent data. XXX For logical replication, let
+ * WalSndWaitForWal() handle any other blocking; idle receivers need
+ * its additional actions. For physical replication, also block if
+ * caught up; its send_data does not block.
*/
- if ((WalSndCaughtUp && !streamingDoneSending) || pq_is_send_pending())
+ if ((WalSndCaughtUp && send_data != XLogSendLogical &&
+ !streamingDoneSending) ||
+ pq_is_send_pending())
{
long sleeptime;
int wakeEvents;