partid

package
v0.40.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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 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) 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