Skip to content

Commit da7c364

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 3de100c commit da7c364

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
@@ -368,23 +368,22 @@ GlobalSnapshotToXmin(GlobalCSN snapshot_global_csn)
368368
* GlobalSnapshotGenerate
369369
*
370370
* Generate GlobalCSN which is actually a local time. Also we are forcing
371-
* this time to be always increasing. Since now it is not uncommon to have
372-
* millions of read transactions per second we are trying to use nanoseconds
371+
* this time to be always increasing.
372+
* XXX since now it is not uncommon to have
373+
* millions of read transactions per second should use nanoseconds
373374
* if such time resolution is available.
374375
*/
375376
GlobalCSN
376377
GlobalSnapshotGenerate(bool locked)
377378
{
378-
instr_time current_time;
379379
GlobalCSN global_csn;
380380

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

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

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

0 commit comments

Comments
 (0)