partid

package
v0.49.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const DefaultOrphanGrace = time.Hour

DefaultOrphanGrace is the ID.Settled grace used when the caller configures none.

View Source
const EncodedLen = 26

EncodedLen is the length of an ID in its textual form.

View Source
const Len = 16

Len is the size of an ID in bytes.

Variables

View Source
var ErrInvalid = errors.New("invalid part id")

ErrInvalid is returned by Parse for anything that is not a canonical id.

Functions

func Valid

func Valid(s string) bool

Valid reports whether s is a canonical part id, which is what tells a part directory apart from an engine-level object on a backend listing.

Types

type ID

type ID [Len]byte

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

func Parse(s string) (ID, error)

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

func (id ID) AppendText(dst []byte) ([]byte, error)

AppendText implements encoding.TextAppender.

func (ID) Settled added in v0.49.0

func (id ID) Settled(now time.Time, grace time.Duration) bool

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.

func (ID) String

func (id ID) String() string

String returns the canonical 26-character textual form.

func (ID) Time

func (id ID) Time() time.Time

Time returns the millisecond timestamp the id was minted at.

Jump to

Keyboard shortcuts

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