Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79c2385

Browse files
committed
Factor out InitControlFile() from BootStrapXLOG()
Right now this only makes BootStrapXLOG() a bit more manageable, butin the future there may be external callers.Discussion:https://www.postgresql.org/message-id/e8f86ba5-48f1-a80a-7f1d-b76bcb9c5c47@2ndquadrant.com
1 parent9745f93 commit79c2385

File tree

1 file changed

+39
-31
lines changed
  • src/backend/access/transam

1 file changed

+39
-31
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ static void CheckRecoveryConsistency(void);
903903
staticXLogRecord*ReadCheckpointRecord(XLogReaderState*xlogreader,
904904
XLogRecPtrRecPtr,intwhichChkpt,boolreport);
905905
staticboolrescanLatestTimeLine(void);
906+
staticvoidInitControlFile(uint64sysidentifier);
906907
staticvoidWriteControlFile(void);
907908
staticvoidReadControlFile(void);
908909
staticchar*str_time(pg_time_ttnow);
@@ -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+
staticvoid
4499+
InitControlFile(uint64sysidentifier)
4500+
{
4501+
charmock_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+
44954533
staticvoid
44964534
WriteControlFile(void)
44974535
{
@@ -5088,7 +5126,6 @@ BootStrapXLOG(void)
50885126
char*recptr;
50895127
booluse_existent;
50905128
uint64sysidentifier;
5091-
charmock_auth_nonce[MOCK_AUTH_NONCE_LEN];
50925129
structtimevaltv;
50935130
pg_crc32ccrc;
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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp