mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-23 06:09:59 +00:00
walproposer: refactor safekeeper::conninfo initialization
It is used both in WalProposerInit and ResetConnection. In the future the logic will become more complicated due to authentication with Safekeeper.
This commit is contained in:
committed by
Egor Suvorov
parent
2ce5d8137d
commit
10d554fcbb
@@ -509,11 +509,27 @@ WalProposerInit(XLogRecPtr flushRecPtr, uint64 systemId)
|
||||
safekeeper[n_safekeepers].state = SS_OFFLINE;
|
||||
safekeeper[n_safekeepers].conn = NULL;
|
||||
|
||||
/*
|
||||
* Set conninfo to empty. We'll fill it out once later, in
|
||||
* `ResetConnection` as needed
|
||||
*/
|
||||
safekeeper[n_safekeepers].conninfo[0] = '\0';
|
||||
{
|
||||
Safekeeper *sk = &safekeeper[n_safekeepers];
|
||||
int written = 0;
|
||||
|
||||
written = snprintf((char *) &sk->conninfo, MAXCONNINFO,
|
||||
"host=%s port=%s dbname=replication options='-c timeline_id=%s tenant_id=%s'",
|
||||
sk->host, sk->port, neon_timeline_walproposer, neon_tenant_walproposer);
|
||||
|
||||
/*
|
||||
* currently connection string is not that long, but once we pass
|
||||
* something like jwt we might overflow the buffer,
|
||||
*/
|
||||
|
||||
/*
|
||||
* so it is better to be defensive and check that everything aligns
|
||||
* well
|
||||
*/
|
||||
if (written > MAXCONNINFO || written < 0)
|
||||
elog(FATAL, "could not create connection string for safekeeper %s:%s", sk->host, sk->port);
|
||||
}
|
||||
|
||||
initStringInfo(&safekeeper[n_safekeepers].outbuf);
|
||||
safekeeper[n_safekeepers].xlogreader = XLogReaderAllocate(wal_segment_size, NULL, XL_ROUTINE(.segment_open = wal_segment_open,.segment_close = wal_segment_close), NULL);
|
||||
if (safekeeper[n_safekeepers].xlogreader == NULL)
|
||||
@@ -684,31 +700,7 @@ ResetConnection(Safekeeper *sk)
|
||||
|
||||
/*
|
||||
* Try to establish new connection
|
||||
*
|
||||
* If the connection information hasn't been filled out, we need to do
|
||||
* that here.
|
||||
*/
|
||||
if (sk->conninfo[0] == '\0')
|
||||
{
|
||||
int written = 0;
|
||||
|
||||
written = snprintf((char *) &sk->conninfo, MAXCONNINFO,
|
||||
"host=%s port=%s dbname=replication options='-c timeline_id=%s tenant_id=%s'",
|
||||
sk->host, sk->port, neon_timeline_walproposer, neon_tenant_walproposer);
|
||||
|
||||
/*
|
||||
* currently connection string is not that long, but once we pass
|
||||
* something like jwt we might overflow the buffer,
|
||||
*/
|
||||
|
||||
/*
|
||||
* so it is better to be defensive and check that everything aligns
|
||||
* well
|
||||
*/
|
||||
if (written > MAXCONNINFO || written < 0)
|
||||
elog(FATAL, "could not create connection string for safekeeper %s:%s", sk->host, sk->port);
|
||||
}
|
||||
|
||||
sk->conn = walprop_connect_start((char *) &sk->conninfo);
|
||||
|
||||
/*
|
||||
@@ -1403,14 +1395,11 @@ DetermineEpochStartLsn(void)
|
||||
static bool
|
||||
WalProposerRecovery(int donor, TimeLineID timeline, XLogRecPtr startpos, XLogRecPtr endpos)
|
||||
{
|
||||
char conninfo[MAXCONNINFO];
|
||||
char *err;
|
||||
WalReceiverConn *wrconn;
|
||||
WalRcvStreamOptions options;
|
||||
|
||||
sprintf(conninfo, "host=%s port=%s dbname=replication options='-c timeline_id=%s tenant_id=%s'",
|
||||
safekeeper[donor].host, safekeeper[donor].port, neon_timeline_walproposer, neon_tenant_walproposer);
|
||||
wrconn = walrcv_connect(conninfo, false, "wal_proposer_recovery", &err);
|
||||
wrconn = walrcv_connect(safekeeper[donor].conninfo, false, "wal_proposer_recovery", &err);
|
||||
if (!wrconn)
|
||||
{
|
||||
ereport(WARNING,
|
||||
|
||||
Reference in New Issue
Block a user