clock

package
v1.0.36-beta.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package clock implements a hybrid logical clock for CRDT mutation tags.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidReplicaID indicates that a clock was created without a usable
	// logical replica identifier.
	ErrInvalidReplicaID = errors.New("clock: invalid replica ID")
	// ErrInvalidRemoteTag indicates that Witness received an invalid tag.
	ErrInvalidRemoteTag = errors.New("clock: invalid remote tag")
	// ErrClockExhausted indicates that the complete tag space is exhausted.
	ErrClockExhausted = errors.New("clock: timestamp space exhausted")
)

Functions

This section is empty.

Types

type HLC

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

HLC generates monotonically ordered tags for one logical replica.

A caller that reuses its replica ID after a process restart must persist and restore the clock state. Otherwise it must use a fresh replica ID.

func NewHLC

func NewHLC(replicaID string) (*HLC, error)

NewHLC creates a clock for replicaID.

func NewHLCFromState

func NewHLCFromState(state State) (*HLC, error)

NewHLCFromState restores a clock that previously used State.ReplicaID.

func (*HLC) Now

func (h *HLC) Now() (crdt.Tag, error)

Now returns a fresh, monotonically ordered local tag.

func (*HLC) ReplicaID

func (h *HLC) ReplicaID() string

ReplicaID returns the logical replica ID associated with h.

func (*HLC) Snapshot

func (h *HLC) Snapshot() State

Snapshot returns the persistable state needed to safely reuse h's replica ID after restart.

func (*HLC) Witness

func (h *HLC) Witness(remote crdt.Tag) error

Witness incorporates remote into the local clock. It never returns remote as a local tag; subsequent calls to Now use h's replica ID.

type State

type State struct {
	ReplicaID string
	WallTime  uint64
	Logical   uint64
}

State is the persistable portion of an HLC. Persist it atomically after a successful Now call before reusing the same ReplicaID across a restart.

Jump to

Keyboard shortcuts

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