diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/access/common/reloptions.c | 2 | ||||
-rw-r--r-- | src/backend/access/transam/xlog.c | 1 | ||||
-rw-r--r-- | src/backend/commands/prepare.c | 2 | ||||
-rw-r--r-- | src/backend/executor/nodeBitmapHeapscan.c | 2 | ||||
-rw-r--r-- | src/backend/replication/basebackup.c | 12 | ||||
-rw-r--r-- | src/backend/replication/logical/worker.c | 14 | ||||
-rw-r--r-- | src/backend/replication/walreceiver.c | 10 | ||||
-rw-r--r-- | src/backend/replication/walsender.c | 9 | ||||
-rw-r--r-- | src/backend/tcop/pquery.c | 2 | ||||
-rw-r--r-- | src/backend/utils/adt/nabstime.c | 1 | ||||
-rw-r--r-- | src/backend/utils/cache/inval.c | 2 | ||||
-rw-r--r-- | src/backend/utils/time/snapmgr.c | 45 |
12 files changed, 57 insertions, 45 deletions
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c index 816483ef8b0..42b4ea410f6 100644 --- a/src/backend/access/common/reloptions.c +++ b/src/backend/access/common/reloptions.c @@ -15,6 +15,8 @@ #include "postgres.h" +#include <float.h> + #include "access/gist_private.h" #include "access/hash.h" #include "access/htup_details.h" diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index ebae9da0f85..50162739f8e 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -15,6 +15,7 @@ #include "postgres.h" #include <ctype.h> +#include <math.h> #include <time.h> #include <fcntl.h> #include <sys/stat.h> diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 7b61da3ef00..116ed67547e 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -16,6 +16,8 @@ */ #include "postgres.h" +#include <limits.h> + #include "access/xact.h" #include "catalog/pg_type.h" #include "commands/createas.h" diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c index f18827de0bd..c871aa03482 100644 --- a/src/backend/executor/nodeBitmapHeapscan.c +++ b/src/backend/executor/nodeBitmapHeapscan.c @@ -35,6 +35,8 @@ */ #include "postgres.h" +#include <math.h> + #include "access/relscan.h" #include "access/transam.h" #include "executor/execdebug.h" diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 09ecc153656..643a17943af 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -92,10 +92,10 @@ static uint64 throttling_sample; static int64 throttling_counter; /* The minimum time required to transfer throttling_sample bytes. */ -static int64 elapsed_min_unit; +static TimeOffset elapsed_min_unit; /* The last check of the transfer rate. */ -static int64 throttled_last; +static TimestampTz throttled_last; /* * The contents of these directories are removed or recreated during server @@ -254,7 +254,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) throttling_counter = 0; /* The 'real data' starts now (header was ignored). */ - throttled_last = GetCurrentIntegerTimestamp(); + throttled_last = GetCurrentTimestamp(); } else { @@ -1333,7 +1333,7 @@ _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf, static void throttle(size_t increment) { - int64 elapsed, + TimeOffset elapsed, elapsed_min, sleep; int wait_result; @@ -1346,7 +1346,7 @@ throttle(size_t increment) return; /* Time elapsed since the last measurement (and possible wake up). */ - elapsed = GetCurrentIntegerTimestamp() - throttled_last; + elapsed = GetCurrentTimestamp() - throttled_last; /* How much should have elapsed at minimum? */ elapsed_min = elapsed_min_unit * (throttling_counter / throttling_sample); sleep = elapsed_min - elapsed; @@ -1381,5 +1381,5 @@ throttle(size_t increment) * Time interval for the remaining amount and possible next increments * starts now. */ - throttled_last = GetCurrentIntegerTimestamp(); + throttled_last = GetCurrentTimestamp(); } diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 563886b7b50..f73bdcd673f 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -981,12 +981,11 @@ ApplyLoop(void) { XLogRecPtr start_lsn; XLogRecPtr end_lsn; - TimestampTz send_time; + TimestampTz send_time; start_lsn = pq_getmsgint64(&s); end_lsn = pq_getmsgint64(&s); - send_time = - IntegerTimestampToTimestampTz(pq_getmsgint64(&s)); + send_time = pq_getmsgint64(&s); if (last_received < start_lsn) last_received = start_lsn; @@ -1000,13 +999,12 @@ ApplyLoop(void) } else if (c == 'k') { - XLogRecPtr endpos; - TimestampTz timestamp; - bool reply_requested; + XLogRecPtr endpos; + TimestampTz timestamp; + bool reply_requested; endpos = pq_getmsgint64(&s); - timestamp = - IntegerTimestampToTimestampTz(pq_getmsgint64(&s)); + timestamp = pq_getmsgint64(&s); reply_requested = pq_getmsgbyte(&s); send_feedback(endpos, reply_requested, false); diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 5c2e72ba9b9..18d9d7e4ec2 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -892,8 +892,7 @@ XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len) /* read the fields */ dataStart = pq_getmsgint64(&incoming_message); walEnd = pq_getmsgint64(&incoming_message); - sendTime = IntegerTimestampToTimestampTz( - pq_getmsgint64(&incoming_message)); + sendTime = pq_getmsgint64(&incoming_message); ProcessWalSndrMessage(walEnd, sendTime); buf += hdrlen; @@ -913,8 +912,7 @@ XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len) /* read the fields */ walEnd = pq_getmsgint64(&incoming_message); - sendTime = IntegerTimestampToTimestampTz( - pq_getmsgint64(&incoming_message)); + sendTime = pq_getmsgint64(&incoming_message); replyRequested = pq_getmsgbyte(&incoming_message); ProcessWalSndrMessage(walEnd, sendTime); @@ -1149,7 +1147,7 @@ XLogWalRcvSendReply(bool force, bool requestReply) pq_sendint64(&reply_message, writePtr); pq_sendint64(&reply_message, flushPtr); pq_sendint64(&reply_message, applyPtr); - pq_sendint64(&reply_message, GetCurrentIntegerTimestamp()); + pq_sendint64(&reply_message, GetCurrentTimestamp()); pq_sendbyte(&reply_message, requestReply ? 1 : 0); /* Send it */ @@ -1241,7 +1239,7 @@ XLogWalRcvSendHSFeedback(bool immed) /* Construct the message and send it. */ resetStringInfo(&reply_message); pq_sendbyte(&reply_message, 'h'); - pq_sendint64(&reply_message, GetCurrentIntegerTimestamp()); + pq_sendint64(&reply_message, GetCurrentTimestamp()); pq_sendint(&reply_message, xmin, 4); pq_sendint(&reply_message, nextEpoch, 4); walrcv_send(wrconn, reply_message.data, reply_message.len); diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 7a40863384f..9cf9eb0e4cb 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -823,12 +823,13 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd) dest = CreateDestReceiver(DestRemoteSimple); MemSet(nulls, false, sizeof(nulls)); - /* + /*---------- * Need a tuple descriptor representing four columns: * - first field: the slot name * - second field: LSN at which we became consistent * - third field: exported snapshot's name * - fourth field: output plugin + *---------- */ tupdesc = CreateTemplateTupleDesc(4, false); TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 1, "slot_name", @@ -1014,7 +1015,7 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid, * several releases by streaming physical replication. */ resetStringInfo(&tmpbuf); - pq_sendint64(&tmpbuf, GetCurrentIntegerTimestamp()); + pq_sendint64(&tmpbuf, GetCurrentTimestamp()); memcpy(&ctx->out->data[1 + sizeof(int64) + sizeof(int64)], tmpbuf.data, sizeof(int64)); @@ -2334,7 +2335,7 @@ XLogSendPhysical(void) * Fill the send timestamp last, so that it is taken as late as possible. */ resetStringInfo(&tmpbuf); - pq_sendint64(&tmpbuf, GetCurrentIntegerTimestamp()); + pq_sendint64(&tmpbuf, GetCurrentTimestamp()); memcpy(&output_message.data[1 + sizeof(int64) + sizeof(int64)], tmpbuf.data, sizeof(int64)); @@ -2842,7 +2843,7 @@ WalSndKeepalive(bool requestReply) resetStringInfo(&output_message); pq_sendbyte(&output_message, 'k'); pq_sendint64(&output_message, sentPtr); - pq_sendint64(&output_message, GetCurrentIntegerTimestamp()); + pq_sendint64(&output_message, GetCurrentTimestamp()); pq_sendbyte(&output_message, requestReply ? 1 : 0); /* ... and send it wrapped in CopyData */ diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index e64ea2ed767..371d7350b7a 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -15,6 +15,8 @@ #include "postgres.h" +#include <limits.h> + #include "access/xact.h" #include "commands/prepare.h" #include "executor/tstoreReceiver.h" diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c index 6da769e562c..3f6a9d3b828 100644 --- a/src/backend/utils/adt/nabstime.c +++ b/src/backend/utils/adt/nabstime.c @@ -19,6 +19,7 @@ #include <ctype.h> #include <float.h> #include <limits.h> +#include <math.h> #include <time.h> #include <sys/time.h> diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index 11f9218f664..8159ab340d8 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -95,6 +95,8 @@ */ #include "postgres.h" +#include <limits.h> + #include "access/htup_details.h" #include "access/xact.h" #include "catalog/catalog.h" diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index 92afc325095..f232c8448c2 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -83,13 +83,13 @@ typedef struct OldSnapshotControlData * only allowed to move forward. */ slock_t mutex_current; /* protect current_timestamp */ - int64 current_timestamp; /* latest snapshot timestamp */ + TimestampTz current_timestamp; /* latest snapshot timestamp */ slock_t mutex_latest_xmin; /* protect latest_xmin and * next_map_update */ TransactionId latest_xmin; /* latest snapshot xmin */ - int64 next_map_update; /* latest snapshot valid up to */ + TimestampTz next_map_update; /* latest snapshot valid up to */ slock_t mutex_threshold; /* protect threshold fields */ - int64 threshold_timestamp; /* earlier snapshot is old */ + TimestampTz threshold_timestamp; /* earlier snapshot is old */ TransactionId threshold_xid; /* earlier xid may be gone */ /* @@ -121,7 +121,7 @@ typedef struct OldSnapshotControlData * Persistence is not needed. */ int head_offset; /* subscript of oldest tracked time */ - int64 head_timestamp; /* time corresponding to head xid */ + TimestampTz head_timestamp; /* time corresponding to head xid */ int count_used; /* how many slots are in use */ TransactionId xid_by_minute[FLEXIBLE_ARRAY_MEMBER]; } OldSnapshotControlData; @@ -219,7 +219,7 @@ static Snapshot FirstXactSnapshot = NULL; static List *exportedSnapshots = NIL; /* Prototypes for local functions */ -static int64 AlignTimestampToMinuteBoundary(int64 ts); +static TimestampTz AlignTimestampToMinuteBoundary(TimestampTz ts); static Snapshot CopySnapshot(Snapshot snapshot); static void FreeSnapshot(Snapshot snapshot); static void SnapshotResetXmin(void); @@ -239,7 +239,7 @@ typedef struct SerializedSnapshotData bool suboverflowed; bool takenDuringRecovery; CommandId curcid; - int64 whenTaken; + TimestampTz whenTaken; XLogRecPtr lsn; } SerializedSnapshotData; @@ -1611,26 +1611,29 @@ ThereAreNoPriorRegisteredSnapshots(void) /* - * Return an int64 timestamp which is exactly on a minute boundary. + * Return a timestamp that is exactly on a minute boundary. * * If the argument is already aligned, return that value, otherwise move to * the next minute boundary following the given time. */ -static int64 -AlignTimestampToMinuteBoundary(int64 ts) +static TimestampTz +AlignTimestampToMinuteBoundary(TimestampTz ts) { - int64 retval = ts + (USECS_PER_MINUTE - 1); + TimestampTz retval = ts + (USECS_PER_MINUTE - 1); return retval - (retval % USECS_PER_MINUTE); } /* - * Get current timestamp for snapshots as int64 that never moves backward. + * Get current timestamp for snapshots + * + * This is basically GetCurrentTimestamp(), but with a guarantee that + * the result never moves backward. */ -int64 +TimestampTz GetSnapshotCurrentTimestamp(void) { - int64 now = GetCurrentIntegerTimestamp(); + TimestampTz now = GetCurrentTimestamp(); /* * Don't let time move backward; if it hasn't advanced, use the old value. @@ -1652,10 +1655,10 @@ GetSnapshotCurrentTimestamp(void) * XXX: So far, we never trust that a 64-bit value can be read atomically; if * that ever changes, we could get rid of the spinlock here. */ -int64 +TimestampTz GetOldSnapshotThresholdTimestamp(void) { - int64 threshold_timestamp; + TimestampTz threshold_timestamp; SpinLockAcquire(&oldSnapshotControl->mutex_threshold); threshold_timestamp = oldSnapshotControl->threshold_timestamp; @@ -1665,7 +1668,7 @@ GetOldSnapshotThresholdTimestamp(void) } static void -SetOldSnapshotThresholdTimestamp(int64 ts, TransactionId xlimit) +SetOldSnapshotThresholdTimestamp(TimestampTz ts, TransactionId xlimit) { SpinLockAcquire(&oldSnapshotControl->mutex_threshold); oldSnapshotControl->threshold_timestamp = ts; @@ -1690,10 +1693,10 @@ TransactionIdLimitedForOldSnapshots(TransactionId recentXmin, && old_snapshot_threshold >= 0 && RelationAllowsEarlyPruning(relation)) { - int64 ts = GetSnapshotCurrentTimestamp(); + TimestampTz ts = GetSnapshotCurrentTimestamp(); TransactionId xlimit = recentXmin; TransactionId latest_xmin; - int64 update_ts; + TimestampTz update_ts; bool same_ts_as_threshold = false; SpinLockAcquire(&oldSnapshotControl->mutex_latest_xmin); @@ -1790,11 +1793,11 @@ TransactionIdLimitedForOldSnapshots(TransactionId recentXmin, * Take care of the circular buffer that maps time to xid. */ void -MaintainOldSnapshotTimeMapping(int64 whenTaken, TransactionId xmin) +MaintainOldSnapshotTimeMapping(TimestampTz whenTaken, TransactionId xmin) { - int64 ts; + TimestampTz ts; TransactionId latest_xmin; - int64 update_ts; + TimestampTz update_ts; bool map_update_required = false; /* Never call this function when old snapshot checking is disabled. */ |