clock

package
v1.2.3-hotfix-20241101 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SkipClockUncertainityPeriodOnRestart

func SkipClockUncertainityPeriodOnRestart(ctx context.Context, clock Clock)

SkipClockUncertainityPeriodOnRestart will cause the current goroutine to sleep to skip clock uncertainty period. This function must be called during the restart of the node.

The system assumes that each node keeps synchronizing with accurate NTP servers to have the clock offset limited under HLCClock.maxOffset.

Types

type Clock

type Clock interface {
	// HasNetworkLatency returns a boolean value indicating whether there is network
	// latency involved when retrieving timestamps.
	HasNetworkLatency() bool
	// MaxOffset returns the max offset of the physical clocks in the cluster.
	MaxOffset() time.Duration
	// Now returns the current timestamp and the upper bound of the current time
	// caused by clock offset.
	Now() (timestamp.Timestamp, timestamp.Timestamp)
	// Update updates the clock based on the received timestamp.
	Update(ts timestamp.Timestamp)

	// SetNodeID set node id. Just used to compatible with TAE some constraint to guaranteed
	// unique timestamp.
	SetNodeID(id uint16)
}

Clock is the interface to the clock used in MatrixOne's timestamp ordering based transaction module.

type HLCClock

type HLCClock struct {
	// contains filtered or unexported fields
}

HLCClock is an implementation of the Hybrid Logical Clock as described in the paper titled -

Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases

func NewHLCClock

func NewHLCClock(clock func() int64, maxOffset time.Duration) *HLCClock

NewHLCClock returns a new HLCClock instance. The maxOffset parameter specifies the max allowed clock offset. The clock readings returned by clock must be within the maxOffset bound across the entire cluster.

func NewUnixNanoHLCClock

func NewUnixNanoHLCClock(ctx context.Context, maxOffset time.Duration) *HLCClock

NewUnixNanoHLCClock returns a new HLCClock instance backed by the local wall clock in Unix epoch nanoseconds. Nodes' clock must be periodically synchronized, e.g. via NTP, to ensure that wall time readings are within the maxOffset offset between any two nodes.

func NewUnixNanoHLCClockWithStopper added in v0.6.0

func NewUnixNanoHLCClockWithStopper(stopper *stopper.Stopper, maxOffset time.Duration) *HLCClock

NewUnixNanoHLCClockWithStopper is similar to NewUnixNanoHLCClock, but perform clock check use stopper

func (*HLCClock) HasNetworkLatency

func (c *HLCClock) HasNetworkLatency() bool

HasNetworkLatency returns a boolean value indicating whether there is network latency involved when retrieving timestamps. There is no such network latency in HLCClock.

func (*HLCClock) MaxOffset

func (c *HLCClock) MaxOffset() time.Duration

MaxOffset returns the max offset of the physical clocks in the cluster.

func (*HLCClock) Now

Now returns the current HLC timestamp and the upper bound timestamp of the current time in hlc.

func (*HLCClock) SetNodeID added in v0.6.0

func (c *HLCClock) SetNodeID(id uint16)

func (*HLCClock) Update

func (c *HLCClock) Update(m timestamp.Timestamp)

Update is called whenever messages are received from other nodes. HLC timestamp carried by those messages are used to update the local HLC clock to capture casual relationships.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL