mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-04 00:02:52 -05:00 
			
		
		
		
	Centralize timestamp computation of control file on updates
This commit moves the timestamp computation of the control file within the routine of src/common/ in charge of updating the backend's control file, which is shared by multiple frontend tools (pg_rewind, pg_checksums and pg_resetwal) and the backend itself. This change has as direct effect to update the control file's timestamp when writing the control file in pg_rewind and pg_checksums, something that is helpful to keep track of control file updates for those operations, something also tracked by the backend at startup within its logs. This part is arguably a bug, as ControlFileData->time should be updated each time a new version of the control file is written, but this is a behavior change so no backpatch is done. Author: Amul Sul Reviewed-by: Nathan Bossart, Michael Paquier, Bharath Rupireddy Discussion: https://postgr.es/m/CAAJ_b97nd_ghRpyFV9Djf9RLXkoTbOUqnocq11WGq9TisX09Fw@mail.gmail.com
This commit is contained in:
		
							parent
							
								
									3804539e48
								
							
						
					
					
						commit
						6fb7c5d67c
					
				@ -7339,7 +7339,7 @@ StartupXLOG(void)
 | 
				
			|||||||
				ControlFile->backupEndPoint = ControlFile->minRecoveryPoint;
 | 
									ControlFile->backupEndPoint = ControlFile->minRecoveryPoint;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ControlFile->time = (pg_time_t) time(NULL);
 | 
					
 | 
				
			||||||
		/* No need to hold ControlFileLock yet, we aren't up far enough */
 | 
							/* No need to hold ControlFileLock yet, we aren't up far enough */
 | 
				
			||||||
		UpdateControlFile();
 | 
							UpdateControlFile();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -8199,7 +8199,6 @@ StartupXLOG(void)
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
 | 
						LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
 | 
				
			||||||
	ControlFile->state = DB_IN_PRODUCTION;
 | 
						ControlFile->state = DB_IN_PRODUCTION;
 | 
				
			||||||
	ControlFile->time = (pg_time_t) time(NULL);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SpinLockAcquire(&XLogCtl->info_lck);
 | 
						SpinLockAcquire(&XLogCtl->info_lck);
 | 
				
			||||||
	XLogCtl->SharedRecoveryState = RECOVERY_STATE_DONE;
 | 
						XLogCtl->SharedRecoveryState = RECOVERY_STATE_DONE;
 | 
				
			||||||
@ -9142,7 +9141,6 @@ CreateCheckPoint(int flags)
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
 | 
							LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
 | 
				
			||||||
		ControlFile->state = DB_SHUTDOWNING;
 | 
							ControlFile->state = DB_SHUTDOWNING;
 | 
				
			||||||
		ControlFile->time = (pg_time_t) time(NULL);
 | 
					 | 
				
			||||||
		UpdateControlFile();
 | 
							UpdateControlFile();
 | 
				
			||||||
		LWLockRelease(ControlFileLock);
 | 
							LWLockRelease(ControlFileLock);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -9412,7 +9410,6 @@ CreateCheckPoint(int flags)
 | 
				
			|||||||
		ControlFile->state = DB_SHUTDOWNED;
 | 
							ControlFile->state = DB_SHUTDOWNED;
 | 
				
			||||||
	ControlFile->checkPoint = ProcLastRecPtr;
 | 
						ControlFile->checkPoint = ProcLastRecPtr;
 | 
				
			||||||
	ControlFile->checkPointCopy = checkPoint;
 | 
						ControlFile->checkPointCopy = checkPoint;
 | 
				
			||||||
	ControlFile->time = (pg_time_t) time(NULL);
 | 
					 | 
				
			||||||
	/* crash recovery should always recover to the end of WAL */
 | 
						/* crash recovery should always recover to the end of WAL */
 | 
				
			||||||
	ControlFile->minRecoveryPoint = InvalidXLogRecPtr;
 | 
						ControlFile->minRecoveryPoint = InvalidXLogRecPtr;
 | 
				
			||||||
	ControlFile->minRecoveryPointTLI = 0;
 | 
						ControlFile->minRecoveryPointTLI = 0;
 | 
				
			||||||
@ -9539,7 +9536,6 @@ CreateEndOfRecoveryRecord(void)
 | 
				
			|||||||
	 * changes to this point.
 | 
						 * changes to this point.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
 | 
						LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
 | 
				
			||||||
	ControlFile->time = (pg_time_t) time(NULL);
 | 
					 | 
				
			||||||
	ControlFile->minRecoveryPoint = recptr;
 | 
						ControlFile->minRecoveryPoint = recptr;
 | 
				
			||||||
	ControlFile->minRecoveryPointTLI = xlrec.ThisTimeLineID;
 | 
						ControlFile->minRecoveryPointTLI = xlrec.ThisTimeLineID;
 | 
				
			||||||
	UpdateControlFile();
 | 
						UpdateControlFile();
 | 
				
			||||||
@ -9740,7 +9736,6 @@ CreateRestartPoint(int flags)
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
 | 
								LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
 | 
				
			||||||
			ControlFile->state = DB_SHUTDOWNED_IN_RECOVERY;
 | 
								ControlFile->state = DB_SHUTDOWNED_IN_RECOVERY;
 | 
				
			||||||
			ControlFile->time = (pg_time_t) time(NULL);
 | 
					 | 
				
			||||||
			UpdateControlFile();
 | 
								UpdateControlFile();
 | 
				
			||||||
			LWLockRelease(ControlFileLock);
 | 
								LWLockRelease(ControlFileLock);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -9801,7 +9796,6 @@ CreateRestartPoint(int flags)
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		ControlFile->checkPoint = lastCheckPointRecPtr;
 | 
							ControlFile->checkPoint = lastCheckPointRecPtr;
 | 
				
			||||||
		ControlFile->checkPointCopy = lastCheckPoint;
 | 
							ControlFile->checkPointCopy = lastCheckPoint;
 | 
				
			||||||
		ControlFile->time = (pg_time_t) time(NULL);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Ensure minRecoveryPoint is past the checkpoint record.  Normally,
 | 
							 * Ensure minRecoveryPoint is past the checkpoint record.  Normally,
 | 
				
			||||||
 | 
				
			|||||||
@ -911,7 +911,6 @@ RewriteControlFile(void)
 | 
				
			|||||||
	ControlFile.checkPointCopy.time = (pg_time_t) time(NULL);
 | 
						ControlFile.checkPointCopy.time = (pg_time_t) time(NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ControlFile.state = DB_SHUTDOWNED;
 | 
						ControlFile.state = DB_SHUTDOWNED;
 | 
				
			||||||
	ControlFile.time = (pg_time_t) time(NULL);
 | 
					 | 
				
			||||||
	ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
 | 
						ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
 | 
				
			||||||
	ControlFile.minRecoveryPoint = 0;
 | 
						ControlFile.minRecoveryPoint = 0;
 | 
				
			||||||
	ControlFile.minRecoveryPointTLI = 0;
 | 
						ControlFile.minRecoveryPointTLI = 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -23,6 +23,7 @@
 | 
				
			|||||||
#include <unistd.h>
 | 
					#include <unistd.h>
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h>
 | 
				
			||||||
#include <fcntl.h>
 | 
					#include <fcntl.h>
 | 
				
			||||||
 | 
					#include <time.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "access/xlog_internal.h"
 | 
					#include "access/xlog_internal.h"
 | 
				
			||||||
#include "catalog/pg_control.h"
 | 
					#include "catalog/pg_control.h"
 | 
				
			||||||
@ -168,6 +169,9 @@ update_controlfile(const char *DataDir,
 | 
				
			|||||||
	StaticAssertStmt(sizeof(ControlFileData) <= PG_CONTROL_FILE_SIZE,
 | 
						StaticAssertStmt(sizeof(ControlFileData) <= PG_CONTROL_FILE_SIZE,
 | 
				
			||||||
					 "sizeof(ControlFileData) exceeds PG_CONTROL_FILE_SIZE");
 | 
										 "sizeof(ControlFileData) exceeds PG_CONTROL_FILE_SIZE");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Update timestamp  */
 | 
				
			||||||
 | 
						ControlFile->time = (pg_time_t) time(NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Recalculate CRC of control file */
 | 
						/* Recalculate CRC of control file */
 | 
				
			||||||
	INIT_CRC32C(ControlFile->crc);
 | 
						INIT_CRC32C(ControlFile->crc);
 | 
				
			||||||
	COMP_CRC32C(ControlFile->crc,
 | 
						COMP_CRC32C(ControlFile->crc,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user