aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c84
1 files changed, 32 insertions, 52 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index af57d77554e..2a79c2e3586 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6005,8 +6005,7 @@ recoveryApplyDelay(XLogReaderState *record)
{
uint8 xact_info;
TimestampTz xtime;
- long secs;
- int microsecs;
+ long msecs;
/* nothing to do if no delay configured */
if (recovery_min_apply_delay <= 0)
@@ -6047,9 +6046,9 @@ recoveryApplyDelay(XLogReaderState *record)
* Exit without arming the latch if it's already past time to apply this
* record
*/
- TimestampDifference(GetCurrentTimestamp(), recoveryDelayUntilTime,
- &secs, &microsecs);
- if (secs <= 0 && microsecs <= 0)
+ msecs = TimestampDifferenceMilliseconds(GetCurrentTimestamp(),
+ recoveryDelayUntilTime);
+ if (msecs <= 0)
return false;
while (true)
@@ -6066,19 +6065,17 @@ recoveryApplyDelay(XLogReaderState *record)
* Wait for difference between GetCurrentTimestamp() and
* recoveryDelayUntilTime
*/
- TimestampDifference(GetCurrentTimestamp(), recoveryDelayUntilTime,
- &secs, &microsecs);
+ msecs = TimestampDifferenceMilliseconds(GetCurrentTimestamp(),
+ recoveryDelayUntilTime);
- /* NB: We're ignoring waits below min_apply_delay's resolution. */
- if (secs <= 0 && microsecs / 1000 <= 0)
+ if (msecs <= 0)
break;
- elog(DEBUG2, "recovery apply delay %ld seconds, %d milliseconds",
- secs, microsecs / 1000);
+ elog(DEBUG2, "recovery apply delay %ld milliseconds", msecs);
(void) WaitLatch(&XLogCtl->recoveryWakeupLatch,
WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
- secs * 1000L + microsecs / 1000,
+ msecs,
WAIT_EVENT_RECOVERY_APPLY_DELAY);
}
return true;
@@ -8448,33 +8445,24 @@ LogCheckpointStart(int flags, bool restartpoint)
static void
LogCheckpointEnd(bool restartpoint)
{
- long write_secs,
- sync_secs,
- total_secs,
- longest_secs,
- average_secs;
- int write_usecs,
- sync_usecs,
- total_usecs,
- longest_usecs,
- average_usecs;
+ long write_msecs,
+ sync_msecs,
+ total_msecs,
+ longest_msecs,
+ average_msecs;
uint64 average_sync_time;
CheckpointStats.ckpt_end_t = GetCurrentTimestamp();
- TimestampDifference(CheckpointStats.ckpt_write_t,
- CheckpointStats.ckpt_sync_t,
- &write_secs, &write_usecs);
+ write_msecs = TimestampDifferenceMilliseconds(CheckpointStats.ckpt_write_t,
+ CheckpointStats.ckpt_sync_t);
- TimestampDifference(CheckpointStats.ckpt_sync_t,
- CheckpointStats.ckpt_sync_end_t,
- &sync_secs, &sync_usecs);
+ sync_msecs = TimestampDifferenceMilliseconds(CheckpointStats.ckpt_sync_t,
+ CheckpointStats.ckpt_sync_end_t);
/* Accumulate checkpoint timing summary data, in milliseconds. */
- BgWriterStats.m_checkpoint_write_time +=
- write_secs * 1000 + write_usecs / 1000;
- BgWriterStats.m_checkpoint_sync_time +=
- sync_secs * 1000 + sync_usecs / 1000;
+ BgWriterStats.m_checkpoint_write_time += write_msecs;
+ BgWriterStats.m_checkpoint_sync_time += sync_msecs;
/*
* All of the published timing statistics are accounted for. Only
@@ -8483,25 +8471,20 @@ LogCheckpointEnd(bool restartpoint)
if (!log_checkpoints)
return;
- TimestampDifference(CheckpointStats.ckpt_start_t,
- CheckpointStats.ckpt_end_t,
- &total_secs, &total_usecs);
+ total_msecs = TimestampDifferenceMilliseconds(CheckpointStats.ckpt_start_t,
+ CheckpointStats.ckpt_end_t);
/*
* Timing values returned from CheckpointStats are in microseconds.
- * Convert to the second plus microsecond form that TimestampDifference
- * returns for homogeneous printing.
+ * Convert to milliseconds for consistent printing.
*/
- longest_secs = (long) (CheckpointStats.ckpt_longest_sync / 1000000);
- longest_usecs = CheckpointStats.ckpt_longest_sync -
- (uint64) longest_secs * 1000000;
+ longest_msecs = (long) ((CheckpointStats.ckpt_longest_sync + 999) / 1000);
average_sync_time = 0;
if (CheckpointStats.ckpt_sync_rels > 0)
average_sync_time = CheckpointStats.ckpt_agg_sync_time /
CheckpointStats.ckpt_sync_rels;
- average_secs = (long) (average_sync_time / 1000000);
- average_usecs = average_sync_time - (uint64) average_secs * 1000000;
+ average_msecs = (long) ((average_sync_time + 999) / 1000);
elog(LOG, "%s complete: wrote %d buffers (%.1f%%); "
"%d WAL file(s) added, %d removed, %d recycled; "
@@ -8514,12 +8497,12 @@ LogCheckpointEnd(bool restartpoint)
CheckpointStats.ckpt_segs_added,
CheckpointStats.ckpt_segs_removed,
CheckpointStats.ckpt_segs_recycled,
- write_secs, write_usecs / 1000,
- sync_secs, sync_usecs / 1000,
- total_secs, total_usecs / 1000,
+ write_msecs / 1000, (int) (write_msecs % 1000),
+ sync_msecs / 1000, (int) (sync_msecs % 1000),
+ total_msecs / 1000, (int) (total_msecs % 1000),
CheckpointStats.ckpt_sync_rels,
- longest_secs, longest_usecs / 1000,
- average_secs, average_usecs / 1000,
+ longest_msecs / 1000, (int) (longest_msecs % 1000),
+ average_msecs / 1000, (int) (average_msecs % 1000),
(int) (PrevCheckPointDistance / 1024.0),
(int) (CheckPointDistanceEstimate / 1024.0));
}
@@ -12024,13 +12007,10 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
if (!TimestampDifferenceExceeds(last_fail_time, now,
wal_retrieve_retry_interval))
{
- long secs,
- wait_time;
- int usecs;
+ long wait_time;
- TimestampDifference(last_fail_time, now, &secs, &usecs);
wait_time = wal_retrieve_retry_interval -
- (secs * 1000 + usecs / 1000);
+ TimestampDifferenceMilliseconds(last_fail_time, now);
(void) WaitLatch(&XLogCtl->recoveryWakeupLatch,
WL_LATCH_SET | WL_TIMEOUT |