On 2019-Nov-11, Amit Kapila wrote: > On Mon, Nov 11, 2019 at 7:53 AM Michael Paquier <mich...@paquier.xyz> wrote:
> > So your suggestion would be to call GetFlushRecPtr() before the first > > check on RecentFlushPtr and before entering the loop? > > No. What I meant was to keep the current code as-is and have an > additional check on RecentFlushPtr before entering the loop. I noticed that the "return" at the bottom of the function does a SetLatch(), but the other returns do not. Isn't that a bug? Also, what's up with those useless returns? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 7f5671504f..771fd353cd 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1298,22 +1298,31 @@ WalSndWaitForWal(XLogRecPtr loc) /* * Fast path to avoid acquiring the spinlock in case we already know we * have enough WAL available. This is particularly interesting if we're * far behind. */ if (RecentFlushPtr != InvalidXLogRecPtr && loc <= RecentFlushPtr) + { + SetLatch(MyLatch); return RecentFlushPtr; + } /* Get a more recent flush pointer. */ if (!RecoveryInProgress()) RecentFlushPtr = GetFlushRecPtr(); else RecentFlushPtr = GetXLogReplayRecPtr(NULL); + if (loc <= RecentFlushPtr) + { + SetLatch(MyLatch); + return RecentFlushPtr; + } + for (;;) { long sleeptime; /* Clear any already-pending wakeups */ ResetLatch(MyLatch); @@ -2267,15 +2276,14 @@ WalSndLoop(WalSndSendDataCallback send_data) /* Sleep until something happens or we time out */ (void) WaitLatchOrSocket(MyLatch, wakeEvents, MyProcPort->sock, sleeptime, WAIT_EVENT_WAL_SENDER_MAIN); } } - return; } /* Initialize a per-walsender data structure for this walsender process */ static void InitWalSenderSlot(void) { int i; @@ -2797,16 +2805,14 @@ XLogSendPhysical(void) { char activitymsg[50]; snprintf(activitymsg, sizeof(activitymsg), "streaming %X/%X", (uint32) (sentPtr >> 32), (uint32) sentPtr); set_ps_display(activitymsg, false); } - - return; } /* * Stream out logically decoded data. */ static void XLogSendLogical(void)