Skip to content

Commit 4c92e75

Browse files
committed
Use a hook for getting the walreceiver password
The hook will be defined in the neon extension. Using a hook limits the amount of Postgres changes. Signed-off-by: Tristan Partin <tristan.partin@databricks.com>
1 parent cc53982 commit 4c92e75

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
128128
WalReceiverConn *conn;
129129
PostgresPollingStatusType status;
130130
/* BEGIN_NEON */
131+
char *password = NULL;
131132
const char *keys[7];
132133
const char *vals[7];
133134
/* END_NEON */
@@ -142,16 +143,17 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
142143

143144
/* BEGIN_NEON */
144145
/*
145-
* We use neon_storage_token for the password because conninfo strings are
146-
* limited to MAXCONNINFO in length. Our tokens encode Unity Catalog
147-
* permissions, so they can be quite lengthy.
146+
* We use the output GetWalRcvPassword_hook for the password because
147+
* conninfo strings are limited to MAXCONNINFO in length. Our tokens can
148+
* make the connection info larger than the limit.
148149
*/
149-
if (pg_strcasecmp(appname, "walreceiver") == 0)
150+
if (pg_strcasecmp(appname, "walreceiver") == 0 && GetWalRcvPassword_hook)
150151
{
151-
if (neon_storage_token && neon_storage_token[0] != '\0')
152+
password = GetWalRcvPassword_hook();
153+
if (password && password[0] != '\0')
152154
{
153155
keys[++i] = "password";
154-
vals[i] = neon_storage_token;
156+
vals[i] = password;
155157
}
156158
}
157159
/* END_NEON */
@@ -182,6 +184,8 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
182184
conn = palloc0(sizeof(WalReceiverConn));
183185
conn->streamConn = PQconnectStartParams(keys, vals,
184186
/* expand_dbname = */ true);
187+
if (password)
188+
pfree(password);
185189
if (PQstatus(conn->streamConn) == CONNECTION_BAD)
186190
goto bad_connection_errmsg;
187191

src/backend/replication/walreceiver.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@
8989
int wal_receiver_status_interval;
9090
int wal_receiver_timeout;
9191
bool hot_standby_feedback;
92-
char *neon_storage_token;
9392

9493
/* libpqwalreceiver connection */
9594
static WalReceiverConn *wrconn = NULL;
9695
WalReceiverFunctionsType *WalReceiverFunctions = NULL;
9796

97+
GetWalRcvPassword_hook_type GetWalRcvPassword_hook = NULL;
98+
9899
#define NAPTIME_PER_CYCLE 100 /* max sleep time between cycles (100ms) */
99100

100101
/*

src/include/replication/walreceiver.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
#include "storage/spin.h"
2525
#include "utils/tuplestore.h"
2626

27+
typedef char *(*GetWalRcvPassword_hook_type) (void);
28+
extern PGDLLIMPORT GetWalRcvPassword_hook_type GetWalRcvPassword_hook;
29+
2730
/* user-settable parameters */
2831
extern int wal_receiver_status_interval;
2932
extern int wal_receiver_timeout;
3033
extern bool hot_standby_feedback;
31-
extern PGDLLIMPORT char *neon_storage_token;
3234

3335
/*
3436
* MAXCONNINFO: maximum size of a connection string.

0 commit comments

Comments
 (0)