|
52 | 52 |
|
53 | 53 | #include "postmaster/bgworker.h"
|
54 | 54 | #include "postmaster/postmaster.h"
|
| 55 | +#include "postmaster/walwriter.h" |
55 | 56 |
|
56 | 57 | #include "replication/decode.h"
|
57 | 58 | #include "replication/logical.h"
|
@@ -1027,6 +1028,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
|
1027 | 1028 | bool endofstream = false;
|
1028 | 1029 | TimestampTz last_recv_timestamp = GetCurrentTimestamp();
|
1029 | 1030 | bool ping_sent = false;
|
| 1031 | + long wait_time; |
1030 | 1032 |
|
1031 | 1033 | CHECK_FOR_INTERRUPTS();
|
1032 | 1034 |
|
@@ -1114,11 +1116,11 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
|
1114 | 1116 |
|
1115 | 1117 | len = walrcv_receive(wrconn, &buf, &fd);
|
1116 | 1118 | }
|
1117 |
| - |
1118 |
| - /* confirm all writes at once */ |
1119 |
| - send_feedback(last_received, false, false); |
1120 | 1119 | }
|
1121 | 1120 |
|
| 1121 | + /* confirm all writes so far */ |
| 1122 | + send_feedback(last_received, false, false); |
| 1123 | + |
1122 | 1124 | if (!in_remote_transaction)
|
1123 | 1125 | {
|
1124 | 1126 | /*
|
@@ -1147,12 +1149,21 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
|
1147 | 1149 | }
|
1148 | 1150 |
|
1149 | 1151 | /*
|
1150 |
| - * Wait for more data or latch. |
| 1152 | + * Wait for more data or latch. If we have unflushed transactions, |
| 1153 | + * wake up after WalWriterDelay to see if they've been flushed yet (in |
| 1154 | + * which case we should send a feedback message). Otherwise, there's |
| 1155 | + * no particular urgency about waking up unless we get data or a |
| 1156 | + * signal. |
1151 | 1157 | */
|
| 1158 | + if (!dlist_is_empty(&lsn_mapping)) |
| 1159 | + wait_time = WalWriterDelay; |
| 1160 | + else |
| 1161 | + wait_time = NAPTIME_PER_CYCLE; |
| 1162 | + |
1152 | 1163 | rc = WaitLatchOrSocket(MyLatch,
|
1153 | 1164 | WL_SOCKET_READABLE | WL_LATCH_SET |
|
1154 | 1165 | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
1155 |
| - fd, NAPTIME_PER_CYCLE, |
| 1166 | + fd, wait_time, |
1156 | 1167 | WAIT_EVENT_LOGICAL_APPLY_MAIN);
|
1157 | 1168 |
|
1158 | 1169 | /* Emergency bailout if postmaster has died */
|
|
0 commit comments