@@ -903,6 +903,7 @@ static void CheckRecoveryConsistency(void);
903903static XLogRecord * ReadCheckpointRecord (XLogReaderState * xlogreader ,
904904 XLogRecPtr RecPtr , int whichChkpt , bool report );
905905static bool rescanLatestTimeLine (void );
906+ static void InitControlFile (uint64 sysidentifier );
906907static void WriteControlFile (void );
907908static void ReadControlFile (void );
908909static char * str_time (pg_time_t tnow );
@@ -4486,12 +4487,49 @@ rescanLatestTimeLine(void)
44864487 * given a preloaded buffer, ReadControlFile() loads the buffer from
44874488 * the pg_control file (during postmaster or standalone-backend startup),
44884489 * and UpdateControlFile() rewrites pg_control after we modify xlog state.
4490+ * InitControlFile() fills the buffer with initial values.
44894491 *
44904492 * For simplicity, WriteControlFile() initializes the fields of pg_control
44914493 * that are related to checking backend/database compatibility, and
44924494 * ReadControlFile() verifies they are correct. We could split out the
44934495 * I/O and compatibility-check functions, but there seems no need currently.
44944496 */
4497+
4498+ static void
4499+ InitControlFile (uint64 sysidentifier )
4500+ {
4501+ char mock_auth_nonce [MOCK_AUTH_NONCE_LEN ];
4502+
4503+ /*
4504+ * Generate a random nonce. This is used for authentication requests that
4505+ * will fail because the user does not exist. The nonce is used to create
4506+ * a genuine-looking password challenge for the non-existent user, in lieu
4507+ * of an actual stored password.
4508+ */
4509+ if (!pg_strong_random (mock_auth_nonce , MOCK_AUTH_NONCE_LEN ))
4510+ ereport (PANIC ,
4511+ (errcode (ERRCODE_INTERNAL_ERROR ),
4512+ errmsg ("could not generate secret authorization token" )));
4513+
4514+ memset (ControlFile , 0 , sizeof (ControlFileData ));
4515+ /* Initialize pg_control status fields */
4516+ ControlFile -> system_identifier = sysidentifier ;
4517+ memcpy (ControlFile -> mock_authentication_nonce , mock_auth_nonce , MOCK_AUTH_NONCE_LEN );
4518+ ControlFile -> state = DB_SHUTDOWNED ;
4519+ ControlFile -> unloggedLSN = FirstNormalUnloggedLSN ;
4520+
4521+ /* Set important parameter values for use when replaying WAL */
4522+ ControlFile -> MaxConnections = MaxConnections ;
4523+ ControlFile -> max_worker_processes = max_worker_processes ;
4524+ ControlFile -> max_wal_senders = max_wal_senders ;
4525+ ControlFile -> max_prepared_xacts = max_prepared_xacts ;
4526+ ControlFile -> max_locks_per_xact = max_locks_per_xact ;
4527+ ControlFile -> wal_level = wal_level ;
4528+ ControlFile -> wal_log_hints = wal_log_hints ;
4529+ ControlFile -> track_commit_timestamp = track_commit_timestamp ;
4530+ ControlFile -> data_checksum_version = bootstrap_data_checksum_version ;
4531+ }
4532+
44954533static void
44964534WriteControlFile (void )
44974535{
@@ -5088,7 +5126,6 @@ BootStrapXLOG(void)
50885126 char * recptr ;
50895127 bool use_existent ;
50905128 uint64 sysidentifier ;
5091- char mock_auth_nonce [MOCK_AUTH_NONCE_LEN ];
50925129 struct timeval tv ;
50935130 pg_crc32c crc ;
50945131
@@ -5109,17 +5146,6 @@ BootStrapXLOG(void)
51095146 sysidentifier |= ((uint64 ) tv .tv_usec ) << 12 ;
51105147 sysidentifier |= getpid () & 0xFFF ;
51115148
5112- /*
5113- * Generate a random nonce. This is used for authentication requests that
5114- * will fail because the user does not exist. The nonce is used to create
5115- * a genuine-looking password challenge for the non-existent user, in lieu
5116- * of an actual stored password.
5117- */
5118- if (!pg_strong_random (mock_auth_nonce , MOCK_AUTH_NONCE_LEN ))
5119- ereport (PANIC ,
5120- (errcode (ERRCODE_INTERNAL_ERROR ),
5121- errmsg ("could not generate secret authorization token" )));
5122-
51235149 /* First timeline ID is always 1 */
51245150 ThisTimeLineID = 1 ;
51255151
@@ -5227,30 +5253,12 @@ BootStrapXLOG(void)
52275253 openLogFile = -1 ;
52285254
52295255 /* Now create pg_control */
5230-
5231- memset (ControlFile , 0 , sizeof (ControlFileData ));
5232- /* Initialize pg_control status fields */
5233- ControlFile -> system_identifier = sysidentifier ;
5234- memcpy (ControlFile -> mock_authentication_nonce , mock_auth_nonce , MOCK_AUTH_NONCE_LEN );
5235- ControlFile -> state = DB_SHUTDOWNED ;
5256+ InitControlFile (sysidentifier );
52365257 ControlFile -> time = checkPoint .time ;
52375258 ControlFile -> checkPoint = checkPoint .redo ;
52385259 ControlFile -> checkPointCopy = checkPoint ;
5239- ControlFile -> unloggedLSN = FirstNormalUnloggedLSN ;
5240-
5241- /* Set important parameter values for use when replaying WAL */
5242- ControlFile -> MaxConnections = MaxConnections ;
5243- ControlFile -> max_worker_processes = max_worker_processes ;
5244- ControlFile -> max_wal_senders = max_wal_senders ;
5245- ControlFile -> max_prepared_xacts = max_prepared_xacts ;
5246- ControlFile -> max_locks_per_xact = max_locks_per_xact ;
5247- ControlFile -> wal_level = wal_level ;
5248- ControlFile -> wal_log_hints = wal_log_hints ;
5249- ControlFile -> track_commit_timestamp = track_commit_timestamp ;
5250- ControlFile -> data_checksum_version = bootstrap_data_checksum_version ;
52515260
52525261 /* some additional ControlFile fields are set in WriteControlFile() */
5253-
52545262 WriteControlFile ();
52555263
52565264 /* Bootstrap the commit log, too */
0 commit comments