Thread

Commits

  1. Revert "libpqwalreceiver: Convert to libpq-be-fe-helpers.h"

  1. [PATCH v4 1/5] Revert "Revert "libpqwalreceiver: Convert to libpq-be-fe-helpers.h""

    Heikki Linnakangas <heikki.linnakangas@iki.fi> — 2024-01-23T09:01:03Z

    This reverts commit 21ef4d4d897563adb2f7920ad53b734950f1e0a4.
    ---
     .../libpqwalreceiver/libpqwalreceiver.c       | 55 +++----------------
     1 file changed, 8 insertions(+), 47 deletions(-)
    
    diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
    index 2439733b55..dbee2f8f0e 100644
    --- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
    +++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
    @@ -24,6 +24,7 @@
     #include "common/connect.h"
     #include "funcapi.h"
     #include "libpq-fe.h"
    +#include "libpq/libpq-be-fe-helpers.h"
     #include "mb/pg_wchar.h"
     #include "miscadmin.h"
     #include "pgstat.h"
    @@ -136,7 +137,6 @@ libpqrcv_connect(const char *conninfo, bool logical, bool must_use_password,
     				 const char *appname, char **err)
     {
     	WalReceiverConn *conn;
    -	PostgresPollingStatusType status;
     	const char *keys[6];
     	const char *vals[6];
     	int			i = 0;
    @@ -192,56 +192,17 @@ libpqrcv_connect(const char *conninfo, bool logical, bool must_use_password,
     	Assert(i < sizeof(keys));
     
     	conn = palloc0(sizeof(WalReceiverConn));
    -	conn->streamConn = PQconnectStartParams(keys, vals,
    -											 /* expand_dbname = */ true);
    -	if (PQstatus(conn->streamConn) == CONNECTION_BAD)
    -		goto bad_connection_errmsg;
    -
    -	/*
    -	 * Poll connection until we have OK or FAILED status.
    -	 *
    -	 * Per spec for PQconnectPoll, first wait till socket is write-ready.
    -	 */
    -	status = PGRES_POLLING_WRITING;
    -	do
    -	{
    -		int			io_flag;
    -		int			rc;
    -
    -		if (status == PGRES_POLLING_READING)
    -			io_flag = WL_SOCKET_READABLE;
    -#ifdef WIN32
    -		/* Windows needs a different test while waiting for connection-made */
    -		else if (PQstatus(conn->streamConn) == CONNECTION_STARTED)
    -			io_flag = WL_SOCKET_CONNECTED;
    -#endif
    -		else
    -			io_flag = WL_SOCKET_WRITEABLE;
    -
    -		rc = WaitLatchOrSocket(MyLatch,
    -							   WL_EXIT_ON_PM_DEATH | WL_LATCH_SET | io_flag,
    -							   PQsocket(conn->streamConn),
    -							   0,
    -							   WAIT_EVENT_LIBPQWALRECEIVER_CONNECT);
    -
    -		/* Interrupted? */
    -		if (rc & WL_LATCH_SET)
    -		{
    -			ResetLatch(MyLatch);
    -			ProcessWalRcvInterrupts();
    -		}
    -
    -		/* If socket is ready, advance the libpq state machine */
    -		if (rc & io_flag)
    -			status = PQconnectPoll(conn->streamConn);
    -	} while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED);
    +	conn->streamConn =
    +		libpqsrv_connect_params(keys, vals,
    +								 /* expand_dbname = */ true,
    +								WAIT_EVENT_LIBPQWALRECEIVER_CONNECT);
     
     	if (PQstatus(conn->streamConn) != CONNECTION_OK)
     		goto bad_connection_errmsg;
     
     	if (must_use_password && !PQconnectionUsedPassword(conn->streamConn))
     	{
    -		PQfinish(conn->streamConn);
    +		libpqsrv_disconnect(conn->streamConn);
     		pfree(conn);
     
     		ereport(ERROR,
    @@ -277,7 +238,7 @@ bad_connection_errmsg:
     
     	/* error path, error already set */
     bad_connection:
    -	PQfinish(conn->streamConn);
    +	libpqsrv_disconnect(conn->streamConn);
     	pfree(conn);
     	return NULL;
     }
    @@ -813,7 +774,7 @@ libpqrcv_PQgetResult(PGconn *streamConn)
     static void
     libpqrcv_disconnect(WalReceiverConn *conn)
     {
    -	PQfinish(conn->streamConn);
    +	libpqsrv_disconnect(conn->streamConn);
     	PQfreemem(conn->recvBuf);
     	pfree(conn);
     }
    -- 
    2.39.3
    
    
    ----Next_Part(Mon_Jan_29_16_32_06_2024_387)--
    Content-Type: Text/X-Patch; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Content-Disposition: attachment;
     filename="v4-0002-Apply-walrcv_shutdown_deblocking_v2-2.patch.patch"