@@ -244,6 +244,7 @@ static void WalSndKeepalive(bool requestReply);
244
244
static void WalSndKeepaliveIfNecessary (void );
245
245
static void WalSndCheckTimeOut (void );
246
246
static long WalSndComputeSleeptime (TimestampTz now );
247
+ static void WalSndWait (uint32 socket_events , long timeout , uint32 wait_event );
247
248
static void WalSndPrepareWrite (LogicalDecodingContext * ctx , XLogRecPtr lsn , TransactionId xid , bool last_write );
248
249
static void WalSndWriteData (LogicalDecodingContext * ctx , XLogRecPtr lsn , TransactionId xid , bool last_write );
249
250
static void WalSndUpdateProgress (LogicalDecodingContext * ctx , XLogRecPtr lsn , TransactionId xid );
@@ -1287,7 +1288,6 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
1287
1288
/* If we have pending write here, go to slow path */
1288
1289
for (;;)
1289
1290
{
1290
- int wakeEvents ;
1291
1291
long sleeptime ;
1292
1292
1293
1293
/* Check for input from the client */
@@ -1304,13 +1304,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
1304
1304
1305
1305
sleeptime = WalSndComputeSleeptime (GetCurrentTimestamp ());
1306
1306
1307
- wakeEvents = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH |
1308
- WL_SOCKET_WRITEABLE | WL_SOCKET_READABLE | WL_TIMEOUT ;
1309
-
1310
1307
/* Sleep until something happens or we time out */
1311
- (void ) WaitLatchOrSocket (MyLatch , wakeEvents ,
1312
- MyProcPort -> sock , sleeptime ,
1313
- WAIT_EVENT_WAL_SENDER_WRITE_DATA );
1308
+ WalSndWait (WL_SOCKET_WRITEABLE | WL_SOCKET_READABLE , sleeptime ,
1309
+ WAIT_EVENT_WAL_SENDER_WRITE_DATA );
1314
1310
1315
1311
/* Clear any already-pending wakeups */
1316
1312
ResetLatch (MyLatch );
@@ -1480,15 +1476,12 @@ WalSndWaitForWal(XLogRecPtr loc)
1480
1476
*/
1481
1477
sleeptime = WalSndComputeSleeptime (GetCurrentTimestamp ());
1482
1478
1483
- wakeEvents = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH |
1484
- WL_SOCKET_READABLE | WL_TIMEOUT ;
1479
+ wakeEvents = WL_SOCKET_READABLE ;
1485
1480
1486
1481
if (pq_is_send_pending ())
1487
1482
wakeEvents |= WL_SOCKET_WRITEABLE ;
1488
1483
1489
- (void ) WaitLatchOrSocket (MyLatch , wakeEvents ,
1490
- MyProcPort -> sock , sleeptime ,
1491
- WAIT_EVENT_WAL_SENDER_WAIT_WAL );
1484
+ WalSndWait (wakeEvents , sleeptime , WAIT_EVENT_WAL_SENDER_WAIT_WAL );
1492
1485
}
1493
1486
1494
1487
/* reactivate latch so WalSndLoop knows to continue */
@@ -2348,10 +2341,10 @@ WalSndLoop(WalSndSendDataCallback send_data)
2348
2341
long sleeptime ;
2349
2342
int wakeEvents ;
2350
2343
2351
- wakeEvents = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH | WL_TIMEOUT ;
2352
-
2353
2344
if (!streamingDoneReceiving )
2354
- wakeEvents |= WL_SOCKET_READABLE ;
2345
+ wakeEvents = WL_SOCKET_READABLE ;
2346
+ else
2347
+ wakeEvents = 0 ;
2355
2348
2356
2349
/*
2357
2350
* Use fresh timestamp, not last_processing, to reduce the chance
@@ -2363,9 +2356,7 @@ WalSndLoop(WalSndSendDataCallback send_data)
2363
2356
wakeEvents |= WL_SOCKET_WRITEABLE ;
2364
2357
2365
2358
/* Sleep until something happens or we time out */
2366
- (void ) WaitLatchOrSocket (MyLatch , wakeEvents ,
2367
- MyProcPort -> sock , sleeptime ,
2368
- WAIT_EVENT_WAL_SENDER_MAIN );
2359
+ WalSndWait (wakeEvents , sleeptime , WAIT_EVENT_WAL_SENDER_MAIN );
2369
2360
}
2370
2361
}
2371
2362
}
@@ -3121,6 +3112,22 @@ WalSndWakeup(void)
3121
3112
}
3122
3113
}
3123
3114
3115
+ /*
3116
+ * Wait for readiness on the FeBe socket, or a timeout. The mask should be
3117
+ * composed of optional WL_SOCKET_WRITEABLE and WL_SOCKET_READABLE flags. Exit
3118
+ * on postmaster death.
3119
+ */
3120
+ static void
3121
+ WalSndWait (uint32 socket_events , long timeout , uint32 wait_event )
3122
+ {
3123
+ WaitEvent event ;
3124
+
3125
+ ModifyWaitEvent (FeBeWaitSet , FeBeWaitSetSocketPos , socket_events , NULL );
3126
+ if (WaitEventSetWait (FeBeWaitSet , timeout , & event , 1 , wait_event ) == 1 &&
3127
+ (event .events & WL_POSTMASTER_DEATH ))
3128
+ proc_exit (1 );
3129
+ }
3130
+
3124
3131
/*
3125
3132
* Signal all walsenders to move to stopping state.
3126
3133
*
0 commit comments