@@ -903,6 +903,7 @@ static void CheckRecoveryConsistency(void);
903
903
static XLogRecord * ReadCheckpointRecord (XLogReaderState * xlogreader ,
904
904
XLogRecPtr RecPtr , int whichChkpt , bool report );
905
905
static bool rescanLatestTimeLine (void );
906
+ static void InitControlFile (uint64 sysidentifier );
906
907
static void WriteControlFile (void );
907
908
static void ReadControlFile (void );
908
909
static char * str_time (pg_time_t tnow );
@@ -4486,12 +4487,49 @@ rescanLatestTimeLine(void)
4486
4487
* given a preloaded buffer, ReadControlFile() loads the buffer from
4487
4488
* the pg_control file (during postmaster or standalone-backend startup),
4488
4489
* and UpdateControlFile() rewrites pg_control after we modify xlog state.
4490
+ * InitControlFile() fills the buffer with initial values.
4489
4491
*
4490
4492
* For simplicity, WriteControlFile() initializes the fields of pg_control
4491
4493
* that are related to checking backend/database compatibility, and
4492
4494
* ReadControlFile() verifies they are correct. We could split out the
4493
4495
* I/O and compatibility-check functions, but there seems no need currently.
4494
4496
*/
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
+
4495
4533
static void
4496
4534
WriteControlFile (void )
4497
4535
{
@@ -5088,7 +5126,6 @@ BootStrapXLOG(void)
5088
5126
char * recptr ;
5089
5127
bool use_existent ;
5090
5128
uint64 sysidentifier ;
5091
- char mock_auth_nonce [MOCK_AUTH_NONCE_LEN ];
5092
5129
struct timeval tv ;
5093
5130
pg_crc32c crc ;
5094
5131
@@ -5109,17 +5146,6 @@ BootStrapXLOG(void)
5109
5146
sysidentifier |= ((uint64 ) tv .tv_usec ) << 12 ;
5110
5147
sysidentifier |= getpid () & 0xFFF ;
5111
5148
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
-
5123
5149
/* First timeline ID is always 1 */
5124
5150
ThisTimeLineID = 1 ;
5125
5151
@@ -5227,30 +5253,12 @@ BootStrapXLOG(void)
5227
5253
openLogFile = -1 ;
5228
5254
5229
5255
/* 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 );
5236
5257
ControlFile -> time = checkPoint .time ;
5237
5258
ControlFile -> checkPoint = checkPoint .redo ;
5238
5259
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 ;
5251
5260
5252
5261
/* some additional ControlFile fields are set in WriteControlFile() */
5253
-
5254
5262
WriteControlFile ();
5255
5263
5256
5264
/* Bootstrap the commit log, too */
0 commit comments