Skip to content

Commit b5f7cff

Browse files
committed
Clean up the rather historically encumbered interface to now() and
current time: provide a GetCurrentTimestamp() function that returns current time in the form of a TimestampTz, instead of separate time_t and microseconds fields. This is what all the callers really want anyway, and it eliminates low-level dependencies on AbsoluteTime, which is a deprecated datatype that will have to disappear eventually.
1 parent c33d575 commit b5f7cff

File tree

19 files changed

+135
-213
lines changed

19 files changed

+135
-213
lines changed

contrib/btree_gist/btree_ts.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "btree_gist.h"
22
#include "btree_utils_num.h"
33

4+
#include "utils/datetime.h"
5+
6+
47
typedef struct
58
{
69
Timestamp lower;

contrib/spi/timetravel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "executor/spi.h" /* this is what you need to work with SPI */
99
#include "commands/trigger.h" /* -"- and triggers */
1010
#include "miscadmin.h" /* for GetPgUserName() */
11+
#include "utils/nabstime.h"
12+
1113
#include <ctype.h> /* tolower () */
1214

1315
#define ABSTIMEOID 702 /* it should be in pg_type.h */

src/backend/access/transam/xact.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.208 2005/06/28 05:08:51 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.209 2005/06/29 22:51:53 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -168,12 +168,11 @@ static SubTransactionId currentSubTransactionId;
168168
static CommandId currentCommandId;
169169

170170
/*
171-
* These vars hold the value of now(), ie, the transaction start time.
171+
* This is the value of now(), ie, the transaction start time.
172172
* This does not change as we enter and exit subtransactions, so we don't
173173
* keep it inside the TransactionState stack.
174174
*/
175-
static AbsoluteTime xactStartTime; /* integer part */
176-
static int xactStartTimeUsec; /* microsecond part */
175+
static TimestampTz xactStartTimestamp;
177176

178177
/*
179178
* GID to be used for preparing the current transaction. This is also
@@ -420,28 +419,15 @@ GetCurrentCommandId(void)
420419
return currentCommandId;
421420
}
422421

423-
424-
/*
425-
* GetCurrentTransactionStartTime
426-
*/
427-
AbsoluteTime
428-
GetCurrentTransactionStartTime(void)
429-
{
430-
return xactStartTime;
431-
}
432-
433-
434422
/*
435-
* GetCurrentTransactionStartTimeUsec
423+
* GetCurrentTransactionStartTimestamp
436424
*/
437-
AbsoluteTime
438-
GetCurrentTransactionStartTimeUsec(int *msec)
425+
TimestampTz
426+
GetCurrentTransactionStartTimestamp(void)
439427
{
440-
*msec = xactStartTimeUsec;
441-
return xactStartTime;
428+
return xactStartTimestamp;
442429
}
443430

444-
445431
/*
446432
* GetCurrentTransactionNestLevel
447433
*
@@ -1391,7 +1377,7 @@ StartTransaction(void)
13911377
/*
13921378
* set now()
13931379
*/
1394-
xactStartTime = GetCurrentAbsoluteTimeUsec(&(xactStartTimeUsec));
1380+
xactStartTimestamp = GetCurrentTimestamp();
13951381

13961382
/*
13971383
* initialize current transaction state fields
@@ -1633,8 +1619,6 @@ PrepareTransaction(void)
16331619
TransactionId xid = GetCurrentTransactionId();
16341620
GlobalTransaction gxact;
16351621
TimestampTz prepared_at;
1636-
AbsoluteTime PreparedSec; /* integer part */
1637-
int PreparedUSec; /* microsecond part */
16381622

16391623
ShowTransactionState("PrepareTransaction");
16401624

@@ -1697,8 +1681,7 @@ PrepareTransaction(void)
16971681
*/
16981682
s->state = TRANS_PREPARE;
16991683

1700-
PreparedSec = GetCurrentAbsoluteTimeUsec(&PreparedUSec);
1701-
prepared_at = AbsoluteTimeUsecToTimestampTz(PreparedSec, PreparedUSec);
1684+
prepared_at = GetCurrentTimestamp();
17021685

17031686
/* Tell bufmgr and smgr to prepare for commit */
17041687
BufmgrCommit();

src/backend/access/transam/xlog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.203 2005/06/19 21:34:01 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.204 2005/06/29 22:51:53 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -43,6 +43,7 @@
4343
#include "storage/spin.h"
4444
#include "utils/builtins.h"
4545
#include "utils/guc.h"
46+
#include "utils/nabstime.h"
4647
#include "utils/relcache.h"
4748

4849

src/backend/bootstrap/bootparse.y

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.76 2005/04/14 01:38:15 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.77 2005/06/29 22:51:54 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -47,7 +47,6 @@
4747
#include "storage/off.h"
4848
#include "storage/smgr.h"
4949
#include "tcop/dest.h"
50-
#include "utils/nabstime.h"
5150
#include "utils/rel.h"
5251

5352
#define atooid(x) ((Oid) strtoul((x), NULL, 10))

src/backend/bootstrap/bootscanner.l

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.39 2005/03/11 19:13:42 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.40 2005/06/29 22:51:54 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -34,7 +34,6 @@
3434
#include "storage/fd.h"
3535
#include "storage/itemptr.h"
3636
#include "storage/off.h"
37-
#include "utils/nabstime.h"
3837
#include "utils/rel.h"
3938

4039
/* Not needed now that this file is compiled as part of bootparse. */

src/backend/libpq/crypt.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.63 2005/06/28 05:08:56 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.64 2005/06/29 22:51:54 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -25,7 +25,7 @@
2525
#include "miscadmin.h"
2626
#include "storage/fd.h"
2727
#include "nodes/pg_list.h"
28-
#include "utils/nabstime.h"
28+
#include "utils/timestamp.h"
2929

3030

3131
int
@@ -149,19 +149,13 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass)
149149
else
150150
{
151151
TimestampTz vuntil;
152-
AbsoluteTime sec;
153-
int usec;
154-
TimestampTz curtime;
155152

156153
vuntil = DatumGetTimestampTz(DirectFunctionCall3(timestamptz_in,
157154
CStringGetDatum(valuntil),
158155
ObjectIdGetDatum(InvalidOid),
159156
Int32GetDatum(-1)));
160157

161-
sec = GetCurrentAbsoluteTimeUsec(&usec);
162-
curtime = AbsoluteTimeUsecToTimestampTz(sec, usec);
163-
164-
if (vuntil < curtime)
158+
if (vuntil < GetCurrentTimestamp())
165159
retval = STATUS_ERROR;
166160
else
167161
retval = STATUS_OK;

src/backend/postmaster/pgstat.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
1515
*
16-
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.97 2005/06/28 05:08:59 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.98 2005/06/29 22:51:55 tgl Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -2026,10 +2026,8 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
20262026

20272027
/* Put this new backend into the slot */
20282028
beentry->procpid = msg->m_procpid;
2029-
beentry->start_sec =
2030-
GetCurrentAbsoluteTimeUsec(&beentry->start_usec);
2031-
beentry->activity_start_sec = 0;
2032-
beentry->activity_start_usec = 0;
2029+
beentry->start_timestamp = GetCurrentTimestamp();
2030+
beentry->activity_start_timestamp = 0;
20332031
beentry->activity[0] = '\0';
20342032

20352033
/*
@@ -2665,8 +2663,7 @@ pgstat_recv_activity(PgStat_MsgActivity *msg, int len)
26652663

26662664
StrNCpy(entry->activity, msg->m_what, PGSTAT_ACTIVITY_SIZE);
26672665

2668-
entry->activity_start_sec =
2669-
GetCurrentAbsoluteTimeUsec(&entry->activity_start_usec);
2666+
entry->activity_start_timestamp = GetCurrentTimestamp();
26702667
}
26712668

26722669

src/backend/postmaster/postmaster.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.455 2005/06/28 05:08:59 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.456 2005/06/29 22:51:55 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -118,6 +118,7 @@
118118
#include "storage/proc.h"
119119
#include "tcop/tcopprot.h"
120120
#include "utils/builtins.h"
121+
#include "utils/datetime.h"
121122
#include "utils/guc.h"
122123
#include "utils/memutils.h"
123124
#include "utils/ps_status.h"
@@ -222,9 +223,6 @@ static bool FatalError = false; /* T if recovering from backend crash */
222223
bool ClientAuthInProgress = false; /* T during new-client
223224
* authentication */
224225

225-
/* Backend startup time */
226-
TimestampTz StartTime;
227-
228226
/*
229227
* State for assigning random salts and cancel keys.
230228
* Also, the global MyCancelKey passes the cancel key assigned to a given
@@ -333,7 +331,7 @@ typedef struct
333331
InheritableSocket pgStatPipe0;
334332
InheritableSocket pgStatPipe1;
335333
pid_t PostmasterPid;
336-
TimestampTz StartTime;
334+
TimestampTz PgStartTime;
337335
#ifdef WIN32
338336
HANDLE PostmasterHandle;
339337
HANDLE initial_signal_pipe;
@@ -376,9 +374,6 @@ PostmasterMain(int argc, char *argv[])
376374
char *userDoption = NULL;
377375
int i;
378376

379-
AbsoluteTime StartTimeSec; /* integer part */
380-
int StartTimeUSec; /* microsecond part */
381-
382377
/* This will call exit() if strdup() fails. */
383378
progname = get_progname(argv[0]);
384379

@@ -922,10 +917,9 @@ PostmasterMain(int argc, char *argv[])
922917
StartupPID = StartupDataBase();
923918

924919
/*
925-
* Get start up time
920+
* Remember postmaster startup time
926921
*/
927-
StartTimeSec = GetCurrentAbsoluteTimeUsec(&StartTimeUSec);
928-
StartTime = AbsoluteTimeUsecToTimestampTz(StartTimeSec, StartTimeUSec);
922+
PgStartTime = GetCurrentTimestamp();
929923

930924
status = ServerLoop();
931925

@@ -3613,7 +3607,7 @@ save_backend_variables(BackendParameters *param, Port *port,
36133607
write_inheritable_socket(&param->pgStatPipe1, pgStatPipe[1], childPid);
36143608

36153609
param->PostmasterPid = PostmasterPid;
3616-
param->StartTime = StartTime;
3610+
param->PgStartTime = PgStartTime;
36173611

36183612
#ifdef WIN32
36193613
param->PostmasterHandle = PostmasterHandle;
@@ -3816,7 +3810,7 @@ restore_backend_variables(BackendParameters *param, Port *port)
38163810
read_inheritable_socket(&pgStatPipe[1], &param->pgStatPipe1);
38173811

38183812
PostmasterPid = param->PostmasterPid;
3819-
StartTime = param->StartTime;
3813+
PgStartTime = param->PgStartTime;
38203814

38213815
#ifdef WIN32
38223816
PostmasterHandle = param->PostmasterHandle;

src/backend/tcop/postgres.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.450 2005/06/22 17:45:45 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.451 2005/06/29 22:51:55 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -149,9 +149,6 @@ static int UseNewLine = 0; /* Use EOF as query delimiters */
149149
#endif /* TCOP_DONTUSENEWLINE */
150150

151151

152-
/* Backend startup time */
153-
TimestampTz StartTime;
154-
155152
/* ----------------------------------------------------------------
156153
* decls for routines only used in this file
157154
* ----------------------------------------------------------------
@@ -2373,9 +2370,6 @@ PostgresMain(int argc, char *argv[], const char *username)
23732370
sigjmp_buf local_sigjmp_buf;
23742371
volatile bool send_rfq = true;
23752372

2376-
AbsoluteTime StartTimeSec; /* integer part */
2377-
int StartTimeUSec; /* microsecond part */
2378-
23792373
#define PendingConfigOption(name,val) \
23802374
(guc_names = lappend(guc_names, pstrdup(name)), \
23812375
guc_values = lappend(guc_values, pstrdup(val)))
@@ -2966,13 +2960,10 @@ PostgresMain(int argc, char *argv[], const char *username)
29662960
pgstat_bestart();
29672961

29682962
/*
2969-
* Get stand-alone backend startup time
2963+
* Remember stand-alone backend startup time
29702964
*/
29712965
if (!IsUnderPostmaster)
2972-
{
2973-
StartTimeSec = GetCurrentAbsoluteTimeUsec(&StartTimeUSec);
2974-
StartTime = AbsoluteTimeUsecToTimestampTz(StartTimeSec, StartTimeUSec);
2975-
}
2966+
PgStartTime = GetCurrentTimestamp();
29762967

29772968
/*
29782969
* POSTGRES main processing loop begins here

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy