Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f246ea3

Browse files
committed
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
1 parent 72a3dc3 commit f246ea3

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/backend/replication/walsender.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,8 +1428,10 @@ WalSndWaitForWal(XLogRecPtr loc)
14281428
/*
14291429
* We only send regular messages to the client for full decoded
14301430
* transactions, but a synchronous replication and walsender shutdown
1431-
* possibly are waiting for a later location. So we send pings
1432-
* containing the flush location every now and then.
1431+
* possibly are waiting for a later location. So, before sleeping, we
1432+
* send a ping containing the flush location. If the receiver is
1433+
* otherwise idle, this keepalive will trigger a reply. Processing the
1434+
* reply will update these MyWalSnd locations.
14331435
*/
14341436
if (MyWalSnd->flush < sentPtr &&
14351437
MyWalSnd->write < sentPtr &&
@@ -2314,14 +2316,14 @@ WalSndLoop(WalSndSendDataCallback send_data)
23142316
WalSndKeepaliveIfNecessary();
23152317

23162318
/*
2317-
* We don't block if not caught up, unless there is unsent data
2318-
* pending in which case we'd better block until the socket is
2319-
* write-ready. This test is only needed for the case where the
2320-
* send_data callback handled a subset of the available data but then
2321-
* pq_flush_if_writable flushed it all --- we should immediately try
2322-
* to send more.
2319+
* Block if we have unsent data. XXX For logical replication, let
2320+
* WalSndWaitForWal() handle any other blocking; idle receivers need
2321+
* its additional actions. For physical replication, also block if
2322+
* caught up; its send_data does not block.
23232323
*/
2324-
if ((WalSndCaughtUp && !streamingDoneSending) || pq_is_send_pending())
2324+
if ((WalSndCaughtUp && send_data != XLogSendLogical &&
2325+
!streamingDoneSending) ||
2326+
pq_is_send_pending())
23252327
{
23262328
long sleeptime;
23272329
int wakeEvents;

0 commit comments

Comments
 (0)