summaryrefslogtreecommitdiff
path: root/src/backend/utils/time/snapmgr.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-02-23 15:57:08 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2017-02-23 15:57:08 -0500
commitc29aff959dc64f7321062e7f33d8c6ec23db53d3 (patch)
tree4c3efa167e01805b2e4fcd6eead2e1a320a2c420 /src/backend/utils/time/snapmgr.c
parentb9d092c962ea3262930e3c31a8c3d79b66ce9d43 (diff)
Consistently declare timestamp variables as TimestampTz.
Twiddle the replication-related code so that its timestamp variables are declared TimestampTz, rather than the uninformative "int64" that was previously used for meant-to-be-always-integer timestamps. This resolves the int64-vs-TimestampTz declaration inconsistencies introduced by commit 7c030783a, though in the opposite direction to what was originally suggested. This required including datatype/timestamp.h in a couple more places than before. I decided it would be a good idea to slim down that header by not having it pull in <float.h> etc, as those headers are no longer at all relevant to its purpose. Unsurprisingly, a small number of .c files turn out to have been depending on those inclusions, so add them back in the .c files as needed. Discussion: https://postgr.es/m/26788.1487455319@sss.pgh.pa.us Discussion: https://postgr.es/m/27694.1487456324@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/time/snapmgr.c')
-rw-r--r--src/backend/utils/time/snapmgr.c45
1 files changed, 24 insertions, 21 deletions
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. */