Documentation
¶
Overview ¶
Package partid mints the globally unique identifiers that name a part on a backend.
A part's backend key must be unique across every writer that can ever touch a prefix, not just within one process: two engines over one shared prefix (an ownership handoff, a restore from a stale index, a rejoin after a lease loss) would otherwise mint the same key for different content and overwrite each other's objects. A local counter cannot provide that, so the id is minted from a timestamp plus randomness instead of derived from what a node happens to hold.
Index ¶
Constants ¶
const DefaultOrphanGrace = time.Hour
DefaultOrphanGrace is the ID.Settled grace used when the caller configures none.
const EncodedLen = 26
EncodedLen is the length of an ID in its textual form.
const Len = 16
Len is the size of an ID in bytes.
Variables ¶
var ErrInvalid = errors.New("invalid part id")
ErrInvalid is returned by Parse for anything that is not a canonical id.
Functions ¶
Types ¶
type ID ¶
ID identifies a part: a 48-bit big-endian unix-millisecond timestamp followed by 80 random bits, the ULID layout. Its ID.String form is base32, so lexicographic order over part prefixes still matches creation order — the engine relies on that for stable part ordering.
func New ¶
func New() ID
New mints a fresh ID. Safe for concurrent use.
Ids minted by one process are strictly increasing even within a millisecond: the entropy is incremented rather than redrawn, which keeps ordering total without weakening uniqueness against other writers (each millisecond still starts from a fresh random draw).
func Parse ¶
Parse decodes the canonical textual form. It is strict: only uppercase alphabet characters are accepted, and the leading digit must not overflow 128 bits, so encoding a parsed id reproduces the input byte for byte.
func (ID) AppendText ¶
AppendText implements encoding.TextAppender.
func (ID) Settled ¶ added in v0.49.0
Settled reports whether id was minted more than grace before now (grace ≤ 0 ⇒ DefaultOrphanGrace): old enough that no writer can still be between writing the part's objects and committing the index that names it. An id dated after now, minted by a writer whose clock runs ahead, is never settled.
type Sequence ¶ added in v0.55.0
type Sequence struct {
// contains filtered or unexported fields
}
Sequence mints ordered IDs within a reserved logical millisecond. It is safe for concurrent use.
func NewSequence ¶ added in v0.55.0
func NewSequence() *Sequence
NewSequence reserves a timestamp before subsequent IDs without reducing the random entropy.