Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdcd1131

Browse files
committed
Send keepalives from walsender even when busy sending WAL.
If walsender doesn't hear from the client for the time specified bywal_sender_timeout, it will conclude the connection or client is dead, anddisconnect. When half of wal_sender_timeout has elapsed, it sends a pingto the client, leaving it the remainig half of wal_sender_timeout torespond. However, it only checked if half of wal_sender_timeout had elapsedwhen it was about to sleep, so if it was busy sending WAL to the client forlong enough, it would not send the ping request in time. Then the clientwould not know it needs to send a reply, and the walsender will disconnecteven though the client is still alive. Fix that.Andres Freund, reviewed by Robert Haas, and some further changes by me.Backpatch to 9.3. Earlier versions relied on the client to send thekeepalives on its own, and hence didn't have this problem.
1 parent3973034 commitdcd1131

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

‎src/backend/replication/walsender.c‎

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,27 @@ WalSndLoop(void)
10671067
}
10681068
}
10691069

1070+
/*
1071+
* If half of wal_sender_timeout has lapsed without receiving any
1072+
* reply from standby, send a keep-alive message requesting an
1073+
* immediate reply.
1074+
*/
1075+
if (wal_sender_timeout>0&& !ping_sent)
1076+
{
1077+
TimestampTztimeout;
1078+
1079+
timeout=TimestampTzPlusMilliseconds(last_reply_timestamp,
1080+
wal_sender_timeout /2);
1081+
if (GetCurrentTimestamp() >=timeout)
1082+
{
1083+
WalSndKeepalive(true);
1084+
ping_sent= true;
1085+
/* Try to flush pending output to the client */
1086+
if (pq_flush_if_writable()!=0)
1087+
gotosend_failure;
1088+
}
1089+
}
1090+
10701091
/*
10711092
* We don't block if not caught up, unless there is unsent data
10721093
* pending in which case we'd better block until the socket is
@@ -1076,7 +1097,7 @@ WalSndLoop(void)
10761097
*/
10771098
if ((caughtup&& !streamingDoneSending)||pq_is_send_pending())
10781099
{
1079-
TimestampTztimeout=0;
1100+
TimestampTztimeout;
10801101
longsleeptime=10000;/* 10 s */
10811102
intwakeEvents;
10821103

@@ -1085,32 +1106,14 @@ WalSndLoop(void)
10851106

10861107
if (pq_is_send_pending())
10871108
wakeEvents |=WL_SOCKET_WRITEABLE;
1088-
elseif (wal_sender_timeout>0&& !ping_sent)
1089-
{
1090-
/*
1091-
* If half of wal_sender_timeout has lapsed without receiving
1092-
* any reply from standby, send a keep-alive message to
1093-
* standby requesting an immediate reply.
1094-
*/
1095-
timeout=TimestampTzPlusMilliseconds(last_reply_timestamp,
1096-
wal_sender_timeout /2);
1097-
if (GetCurrentTimestamp() >=timeout)
1098-
{
1099-
WalSndKeepalive(true);
1100-
ping_sent= true;
1101-
/* Try to flush pending output to the client */
1102-
if (pq_flush_if_writable()!=0)
1103-
gotosend_failure;
1104-
}
1105-
}
11061109

1107-
/* Determine time until replication timeout */
1110+
/*
1111+
* If wal_sender_timeout is active, sleep in smaller increments
1112+
* to not go over the timeout too much. XXX: Why not just sleep
1113+
* until the timeout has elapsed?
1114+
*/
11081115
if (wal_sender_timeout>0)
1109-
{
1110-
timeout=TimestampTzPlusMilliseconds(last_reply_timestamp,
1111-
wal_sender_timeout);
11121116
sleeptime=1+ (wal_sender_timeout /10);
1113-
}
11141117

11151118
/* Sleep until something happens or we time out */
11161119
ImmediateInterruptOK= true;
@@ -1124,6 +1127,8 @@ WalSndLoop(void)
11241127
* possibility that the client replied just as we reached the
11251128
* timeout ... he's supposed to reply *before* that.
11261129
*/
1130+
timeout=TimestampTzPlusMilliseconds(last_reply_timestamp,
1131+
wal_sender_timeout);
11271132
if (wal_sender_timeout>0&&GetCurrentTimestamp() >=timeout)
11281133
{
11291134
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp