On Wed, Dec 12, 2018 at 02:55:17PM +0900, Michael Paquier wrote: > Well, the conninfo and slot name accessible to the user are the values > available only once the information of the WAL receiver in shared memory > is ready to be displayed. Relying more on the GUC context has the > advantage to never have in shared memory the original string and only > store the clobbered one, which actually simplifies what's stored in > shared memory because you can entirely remove ready_to_display (I forgot > to remove that in the patch actually). If those parameters become > reloadable, you actually rely only on what the param context has, and > not on what the shared memory context may have or not. > > Removing entirely ready_to_display is quite appealing actually..
I have been looking at that stuff this morning, and indeed ready_for_display can be entirely removed. I think that's quite an advantage as WalRcv->conninfo only stores the connection string cloberred to hide security-sensitive fields and it never has to save the initial state which could have sensitive data, simplifying how the WAL receiver data is filled. I am adding that to the next commit fest. -- Michael
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index c80b14ed97..9d664559e8 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -11848,8 +11848,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, tli, curFileTLI); } curFileTLI = tli; - RequestXLogStreaming(tli, ptr, PrimaryConnInfo, - PrimarySlotName); + RequestXLogStreaming(tli, ptr); receivedUpto = 0; } diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 9643c2ed7b..1b077c9a3d 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -188,9 +188,7 @@ DisableWalRcvImmediateExit(void) void WalReceiverMain(void) { - char conninfo[MAXCONNINFO]; char *tmp_conninfo; - char slotname[NAMEDATALEN]; XLogRecPtr startpoint; TimeLineID startpointTLI; TimeLineID primaryTLI; @@ -248,10 +246,6 @@ WalReceiverMain(void) walrcv->pid = MyProcPid; walrcv->walRcvState = WALRCV_STREAMING; - /* Fetch information required to start streaming */ - walrcv->ready_to_display = false; - strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO); - strlcpy(slotname, (char *) walrcv->slotname, NAMEDATALEN); startpoint = walrcv->receiveStart; startpointTLI = walrcv->receiveStartTLI; @@ -291,9 +285,14 @@ WalReceiverMain(void) /* Unblock signals (they were blocked when the postmaster forked us) */ PG_SETMASK(&UnBlockSig); + if (PrimaryConnInfo == NULL || PrimaryConnInfo[0] == '\0') + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("cannot connect to the primary server as \"primary_conninfo\" is not defined"))); + /* Establish the connection to the primary for XLOG streaming */ EnableWalRcvImmediateExit(); - wrconn = walrcv_connect(conninfo, false, "walreceiver", &err); + wrconn = walrcv_connect(PrimaryConnInfo, false, "walreceiver", &err); if (!wrconn) ereport(ERROR, (errmsg("could not connect to the primary server: %s", err))); @@ -311,12 +310,15 @@ WalReceiverMain(void) if (tmp_conninfo) strlcpy((char *) walrcv->conninfo, tmp_conninfo, MAXCONNINFO); + memset(walrcv->slotname, 0, NAMEDATALEN); + if (PrimarySlotName) + strlcpy((char *) walrcv->slotname, PrimarySlotName, NAMEDATALEN); + memset(walrcv->sender_host, 0, NI_MAXHOST); if (sender_host) strlcpy((char *) walrcv->sender_host, sender_host, NI_MAXHOST); walrcv->sender_port = sender_port; - walrcv->ready_to_display = true; SpinLockRelease(&walrcv->mutex); if (tmp_conninfo) @@ -387,7 +389,8 @@ WalReceiverMain(void) */ options.logical = false; options.startpoint = startpoint; - options.slotname = slotname[0] != '\0' ? slotname : NULL; + options.slotname = (PrimarySlotName && PrimarySlotName[0] != '\0') ? + PrimarySlotName : NULL; options.proto.physical.startpointTLI = startpointTLI; ThisTimeLineID = startpointTLI; if (walrcv_startstreaming(wrconn, &options)) @@ -776,7 +779,6 @@ WalRcvDie(int code, Datum arg) Assert(walrcv->pid == MyProcPid); walrcv->walRcvState = WALRCV_STOPPED; walrcv->pid = 0; - walrcv->ready_to_display = false; walrcv->latch = NULL; SpinLockRelease(&walrcv->mutex); @@ -1374,7 +1376,6 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) Datum *values; bool *nulls; int pid; - bool ready_to_display; WalRcvState state; XLogRecPtr receive_start_lsn; TimeLineID receive_start_tli; @@ -1392,7 +1393,6 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) /* Take a lock to ensure value consistency */ SpinLockAcquire(&WalRcv->mutex); pid = (int) WalRcv->pid; - ready_to_display = WalRcv->ready_to_display; state = WalRcv->walRcvState; receive_start_lsn = WalRcv->receiveStart; receive_start_tli = WalRcv->receiveStartTLI; @@ -1412,7 +1412,7 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) * No WAL receiver (or not ready yet), just return a tuple with NULL * values */ - if (pid == 0 || !ready_to_display) + if (pid == 0) PG_RETURN_NULL(); /* determine result type */ diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index 67b1a074cc..82dc128d10 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -220,8 +220,7 @@ ShutdownWalRcv(void) * of a replication slot to acquire. */ void -RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, - const char *slotname) +RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr) { WalRcvData *walrcv = WalRcv; bool launch = false; @@ -243,15 +242,8 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, Assert(walrcv->walRcvState == WALRCV_STOPPED || walrcv->walRcvState == WALRCV_WAITING); - if (conninfo != NULL) - strlcpy((char *) walrcv->conninfo, conninfo, MAXCONNINFO); - else - walrcv->conninfo[0] = '\0'; - - if (slotname != NULL) - strlcpy((char *) walrcv->slotname, slotname, NAMEDATALEN); - else - walrcv->slotname[0] = '\0'; + walrcv->conninfo[0] = '\0'; + walrcv->slotname[0] = '\0'; if (walrcv->walRcvState == WALRCV_STOPPED) { diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h index 5913b580c2..71a55903d9 100644 --- a/src/include/replication/walreceiver.h +++ b/src/include/replication/walreceiver.h @@ -104,8 +104,7 @@ typedef struct TimestampTz latestWalEndTime; /* - * connection string; initially set to connect to the primary, and later - * clobbered to hide security-sensitive fields. + * Connection string clobbered to hide security-sensitive fields. */ char conninfo[MAXCONNINFO]; @@ -122,9 +121,6 @@ typedef struct */ char slotname[NAMEDATALEN]; - /* set true once conninfo is ready to display (obfuscated pwds etc) */ - bool ready_to_display; - /* * Latch used by startup process to wake up walreceiver after telling it * where to start streaming (after setting receiveStart and @@ -306,8 +302,7 @@ extern void WalRcvShmemInit(void); extern void ShutdownWalRcv(void); extern bool WalRcvStreaming(void); extern bool WalRcvRunning(void); -extern void RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, - const char *conninfo, const char *slotname); +extern void RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr); extern XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI); extern int GetReplicationApplyDelay(void); extern int GetReplicationTransferLatency(void);
signature.asc
Description: PGP signature