Skip to content

Timestamps

disksing edited this page Dec 13, 2021 · 1 revision

Timestamps

TiKV uses timestamps to determine the order in which transactions are run. All timestamps are assigned from PD. Normally, each transaction needs to be bound to 2 timestamps, called StartTS and CommitTS.

The timestamp is a 64-bit unsigned integer, which is devided into a physical part and a login part. The physical part occupies the high 18 bits and takes to unix ephoch with millisecond precision, while the logical part is a counter starting from 0.

oracle package provides some tool functions for generating timestamps or parsing timestamps. For example, you can use these functions to infer the physical time of a transaction, or to construct a new timestamp using the physical time as GC safetime.

Example:

physical := oracle.ExtarctPhysical(ts)
logical := oracle.ExtractLogical(ts)
t := oracle.GetTimeFromTS(ts)
ts := oracle.GoTimeToTS(time.Now()-24*time.Hour)
Clone this wiki locally