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

Commit21ef4d4

Browse files
committed
Revert "libpqwalreceiver: Convert to libpq-be-fe-helpers.h"
This reverts commit728f86f.The signal handling was a few bricks shy of a load in that commit,which made the walreceiver non-responsive to SIGTERM while it waswaiting for the connection to be established. That prevented a standbyfrom being promoted.Since it was non-essential refactoring, let's revert it to make v16work the same as earlier releases. I reverted it in 'master' too, tokeep the branches in sync. The refactoring was a good idea as such,but it needs a bit more work. Once we have developed a complete patchwith this issue fixed, let's re-apply that to 'master'.Reported-by: Kyotaro HoriguchiBackpatch-through: 16Discussion:https://www.postgresql.org/message-id/20231231.200741.1078989336605759878.horikyota.ntt@gmail.com
1 parent9b1a6f5 commit21ef4d4

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

‎src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include"common/connect.h"
2525
#include"funcapi.h"
2626
#include"libpq-fe.h"
27-
#include"libpq/libpq-be-fe-helpers.h"
2827
#include"mb/pg_wchar.h"
2928
#include"miscadmin.h"
3029
#include"pgstat.h"
@@ -133,6 +132,7 @@ libpqrcv_connect(const char *conninfo, bool logical, bool must_use_password,
133132
constchar*appname,char**err)
134133
{
135134
WalReceiverConn*conn;
135+
PostgresPollingStatusTypestatus;
136136
constchar*keys[6];
137137
constchar*vals[6];
138138
inti=0;
@@ -188,17 +188,56 @@ libpqrcv_connect(const char *conninfo, bool logical, bool must_use_password,
188188
Assert(i<sizeof(keys));
189189

190190
conn=palloc0(sizeof(WalReceiverConn));
191-
conn->streamConn=
192-
libpqsrv_connect_params(keys,vals,
193-
/* expand_dbname = */ true,
194-
WAIT_EVENT_LIBPQWALRECEIVER_CONNECT);
191+
conn->streamConn=PQconnectStartParams(keys,vals,
192+
/* expand_dbname = */ true);
193+
if (PQstatus(conn->streamConn)==CONNECTION_BAD)
194+
gotobad_connection_errmsg;
195+
196+
/*
197+
* Poll connection until we have OK or FAILED status.
198+
*
199+
* Per spec for PQconnectPoll, first wait till socket is write-ready.
200+
*/
201+
status=PGRES_POLLING_WRITING;
202+
do
203+
{
204+
intio_flag;
205+
intrc;
206+
207+
if (status==PGRES_POLLING_READING)
208+
io_flag=WL_SOCKET_READABLE;
209+
#ifdefWIN32
210+
/* Windows needs a different test while waiting for connection-made */
211+
elseif (PQstatus(conn->streamConn)==CONNECTION_STARTED)
212+
io_flag=WL_SOCKET_CONNECTED;
213+
#endif
214+
else
215+
io_flag=WL_SOCKET_WRITEABLE;
216+
217+
rc=WaitLatchOrSocket(MyLatch,
218+
WL_EXIT_ON_PM_DEATH |WL_LATCH_SET |io_flag,
219+
PQsocket(conn->streamConn),
220+
0,
221+
WAIT_EVENT_LIBPQWALRECEIVER_CONNECT);
222+
223+
/* Interrupted? */
224+
if (rc&WL_LATCH_SET)
225+
{
226+
ResetLatch(MyLatch);
227+
ProcessWalRcvInterrupts();
228+
}
229+
230+
/* If socket is ready, advance the libpq state machine */
231+
if (rc&io_flag)
232+
status=PQconnectPoll(conn->streamConn);
233+
}while (status!=PGRES_POLLING_OK&&status!=PGRES_POLLING_FAILED);
195234

196235
if (PQstatus(conn->streamConn)!=CONNECTION_OK)
197236
gotobad_connection_errmsg;
198237

199238
if (must_use_password&& !PQconnectionUsedPassword(conn->streamConn))
200239
{
201-
libpqsrv_disconnect(conn->streamConn);
240+
PQfinish(conn->streamConn);
202241
pfree(conn);
203242

204243
ereport(ERROR,
@@ -234,7 +273,7 @@ libpqrcv_connect(const char *conninfo, bool logical, bool must_use_password,
234273

235274
/* error path, error already set */
236275
bad_connection:
237-
libpqsrv_disconnect(conn->streamConn);
276+
PQfinish(conn->streamConn);
238277
pfree(conn);
239278
returnNULL;
240279
}
@@ -770,7 +809,7 @@ libpqrcv_PQgetResult(PGconn *streamConn)
770809
staticvoid
771810
libpqrcv_disconnect(WalReceiverConn*conn)
772811
{
773-
libpqsrv_disconnect(conn->streamConn);
812+
PQfinish(conn->streamConn);
774813
PQfreemem(conn->recvBuf);
775814
pfree(conn);
776815
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp