From cd004067742ee16ee63e55abfb4acbd5f09fbaab Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 17 Feb 2008 02:09:32 +0000 Subject: Replace time_t with pg_time_t (same values, but always int64) in on-disk data structures and backend internal APIs. This solves problems we've seen recently with inconsistent layout of pg_control between machines that have 32-bit time_t and those that have already migrated to 64-bit time_t. Also, we can get out from under the problem that Windows' Unix-API emulation is not consistent about the width of time_t. There are a few remaining places where local time_t variables are used to hold the current or recent result of time(NULL). I didn't bother changing these since they do not affect any cross-module APIs and surely all platforms will have 64-bit time_t before overflow becomes an actual risk. time_t should be avoided for anything visible to extension modules, however. --- src/backend/access/transam/xlog.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/backend/access/transam/xlog.c') diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index d2075018d96..f61af0ab4d5 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.292 2008/01/21 11:17:46 petere Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.293 2008/02/17 02:09:27 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -271,7 +271,7 @@ typedef struct XLogCtlWrite { XLogwrtResult LogwrtResult; /* current value of LogwrtResult */ int curridx; /* cache index of next block to write */ - time_t lastSegSwitchTime; /* time of last xlog segment switch */ + pg_time_t lastSegSwitchTime; /* time of last xlog segment switch */ } XLogCtlWrite; /* @@ -1553,7 +1553,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch) if (XLogArchivingActive()) XLogArchiveNotifySeg(openLogId, openLogSeg); - Write->lastSegSwitchTime = time(NULL); + Write->lastSegSwitchTime = (pg_time_t) time(NULL); /* * Signal bgwriter to start a checkpoint if we've consumed too @@ -4217,7 +4217,7 @@ BootStrapXLOG(void) checkPoint.nextOid = FirstBootstrapObjectId; checkPoint.nextMulti = FirstMultiXactId; checkPoint.nextMultiOffset = 0; - checkPoint.time = time(NULL); + checkPoint.time = (pg_time_t) time(NULL); ShmemVariableCache->nextXid = checkPoint.nextXid; ShmemVariableCache->nextOid = checkPoint.nextOid; @@ -4972,7 +4972,7 @@ StartupXLOG(void) ControlFile->checkPointCopy = checkPoint; if (minRecoveryLoc.xlogid != 0 || minRecoveryLoc.xrecoff != 0) ControlFile->minRecoveryPoint = minRecoveryLoc; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); /* @@ -5277,7 +5277,7 @@ StartupXLOG(void) InRecovery = false; ControlFile->state = DB_IN_PRODUCTION; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); /* start the archive_timeout timer running */ @@ -5496,10 +5496,10 @@ GetInsertRecPtr(void) /* * Get the time of the last xlog segment switch */ -time_t +pg_time_t GetLastSegSwitchTime(void) { - time_t result; + pg_time_t result; /* Need WALWriteLock, but shared lock is sufficient */ LWLockAcquire(WALWriteLock, LW_SHARED); @@ -5676,7 +5676,7 @@ CreateCheckPoint(int flags) if (shutdown) { ControlFile->state = DB_SHUTDOWNING; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); } @@ -5690,7 +5690,7 @@ CreateCheckPoint(int flags) /* Begin filling in the checkpoint WAL record */ MemSet(&checkPoint, 0, sizeof(checkPoint)); checkPoint.ThisTimeLineID = ThisTimeLineID; - checkPoint.time = time(NULL); + checkPoint.time = (pg_time_t) time(NULL); /* * We must hold WALInsertLock while examining insert state to determine @@ -5891,7 +5891,7 @@ CreateCheckPoint(int flags) ControlFile->prevCheckPoint = ControlFile->checkPoint; ControlFile->checkPoint = ProcLastRecPtr; ControlFile->checkPointCopy = checkPoint; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); LWLockRelease(ControlFileLock); @@ -5992,7 +5992,7 @@ RecoveryRestartPoint(const CheckPoint *checkPoint) * Checking true elapsed time keeps us from doing restartpoints too often * while rapidly scanning large amounts of WAL. */ - elapsed_secs = time(NULL) - ControlFile->time; + elapsed_secs = (pg_time_t) time(NULL) - ControlFile->time; if (elapsed_secs < CheckPointTimeout / 2) return; @@ -6028,7 +6028,7 @@ RecoveryRestartPoint(const CheckPoint *checkPoint) ControlFile->prevCheckPoint = ControlFile->checkPoint; ControlFile->checkPoint = ReadRecPtr; ControlFile->checkPointCopy = *checkPoint; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); ereport((recoveryLogRestartpoints ? LOG : DEBUG2), -- cgit v1.2.3