Documentation ¶
Overview ¶
Package vttime contains the definitions and implementations for the Vitess time library. This package is based on Google's TrueTime, as described in this Spanner paper for instance: http://static.googleusercontent.com/media/research.google.com/en//archive/spanner-osdi2012.pdf
The idea is that a timestamp is not enough, as clocks will drift apart between computers. However, it is usually possible to know how much drift happens. So instead of returning a timestamp that may be wrong, we return an interval [earliest, latest] with the following guarantees: - current time is greater or equal to 'earliest'. - current time is less or equal to 'latest'.
When comparing two intervals, we know one of them is smaller if there is no overlap and it is before:
[--------] [-----------]
If there is overlap, we can't say for sure:
[--------] [----------]
However, if the goal is to be sure we are producing events that clients will know are chonologically ordered, it is then possible to sleep for a few milliseconds and guarantee that. This becomes handy in Paxos-like algorithms, for instance. See the paper for more details.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetTestClockTime ¶
SetTestClockTime sets the 'test' implementation time to the provided value.
func SetTestClockUncertainty ¶
SetTestClockUncertainty sets the 'test' implementation uncertainty to the provided value.
func UseTestClock ¶
func UseTestClock()
UseTestClock is meant to be used in tests to start using the test clock.
Types ¶
type Clock ¶
type Clock interface { // Now returns the current time as Interval. // This method should be thread safe (i.e. multiple go routines can // safely call this at the same time). // The returned interval is guaranteed to have earliest <= latest, // and all implementations enforce it. Now() (Interval, error) }
Clock returns the current time.
type Interval ¶
type Interval struct {
// contains filtered or unexported fields
}
Interval describes a time interval
func NewInterval ¶
NewInterval creates a new Interval from the provided times. earliest has to be smaller or equal to latest, or an error is returned.
func (Interval) Earliest ¶
Earliest returns the earliest time in the interval. If Interval was from calling Now(), it is guaranteed the real time was greater or equal than Earliest().
func (Interval) IsValid ¶
IsValid returns true iff latest >= earliest, meaning the interval is actually a real valid interval.
type TestClock ¶
type TestClock struct {
// contains filtered or unexported fields
}
TestClock is an implementation of Clock for tests, where it is possible to set the current time and the uncertainty at any time.
To use it: vttime.UseTestClock() vttime.SetTestClockTime(now) vttime.SetTestClockUncertainty(dur)
func (*TestClock) SetUncertainty ¶
SetUncertainty lets the user set the uncertainty