Skip to content

Commit 248913f

Browse files
committed
Use GetCurrentTimestamp instead of instr_time in GlobalSnapshotGenerate.
CLOCK_MONOTONIC is not ok because it is time since server start, which means values between nodes are totally uncorrelated. So resort to use usual real time clock GetCurrentTimestamp (gettimeofday); we should now ensure monotonicity on our own, but this was done previously anyway. Ideally, we should use clock_gettime with CLOCK_REALTIME which might provide nanosecond resolution.
1 parent 7c595b2 commit 248913f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/backend/access/transam/global_snapshot.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,23 +369,22 @@ GlobalSnapshotToXmin(GlobalCSN snapshot_global_csn)
369369
* GlobalSnapshotGenerate
370370
*
371371
* Generate GlobalCSN which is actually a local time. Also we are forcing
372-
* this time to be always increasing. Since now it is not uncommon to have
373-
* millions of read transactions per second we are trying to use nanoseconds
372+
* this time to be always increasing.
373+
* XXX since now it is not uncommon to have
374+
* millions of read transactions per second should use nanoseconds
374375
* if such time resolution is available.
375376
*/
376377
GlobalCSN
377378
GlobalSnapshotGenerate(bool locked)
378379
{
379-
instr_time current_time;
380380
GlobalCSN global_csn;
381381

382382
Assert(track_global_snapshots || global_snapshot_defer_time > 0);
383383

384384
/*
385385
* TODO: create some macro that add small random shift to current time.
386386
*/
387-
INSTR_TIME_SET_CURRENT(current_time);
388-
global_csn = (GlobalCSN) INSTR_TIME_GET_NANOSEC(current_time);
387+
global_csn = GetCurrentTimestamp() * 1000; /* nsec per usec */
389388

390389
/* TODO: change to atomics? */
391390
if (!locked)

0 commit comments

Comments
 (0)