Expand description
Core HeeRanjID types.
HeeRanjID is designed to let a project start on a single Postgres node with
a compact 8-byte integer primary key, and migrate to distributed writers
later without rewriting a single ID or schema. HeerId — a 64-bit
time-ordered integer whose layout already carries a node_id field —
is the primary type you reach for on day one. Going from one writer to
many later is a config change (allocate more node_id values, bind each
service’s session); existing IDs stay valid.
RanjId is the natural extension when HeerId’s capacity isn’t enough
(more than 511 nodes, more than 8,191 IDs per node per millisecond, or
sub-millisecond timestamp precision). It’s a UUIDv8-compatible 128-bit
identifier stored as uuid, and conversion from HeerId is lossless.
HeerIdDesc and RanjIdDesc are reverse-chronologically-sorted
siblings: their raw-bit ordering matches a DESC scan, so newest-first
ORDER BY id is served directly by the primary key index without a
secondary descending index or a reverse scan. See the asc-to-desc
migration playbook at docs/migrations/asc-to-desc.md for the workflow
that flips an existing column under live writes.
§Sentinel values
Each of the four ID types exposes a pub const ZERO for use as a
placeholder before persistence (e.g., when constructing a row
in-memory before INSERT ... RETURNING id assigns the real ID):
let id = HeerId::ZERO;
assert!(id.is_zero());The sentinel is the wire-zero bit pattern. For HeerId /
HeerIdDesc this is provably outside the image of generate_id()
because production timestamps are always non-zero. For RanjId /
RanjIdDesc this is the RFC 4122 §4.1.7 nil UUID, which is
structurally invalid as UUIDv8 — see each type’s documentation for
the sentinel-only contract.
For desc-encoded variants, the wire-zero bit pattern does not
correspond to logical-zero components; see each type’s ZERO
documentation for the decoded component values.
Modules§
- mssql_
schema - MSSQL schema helpers for the v0.3.0 descending-sort variants.
- reverse_
order - Bulk cross-direction conversion for
HeerId↔HeerIdDescandRanjId↔RanjIdDesc. O(n) time, O(1) extra memory — the inputVec’s allocation is reused for the output. See spec §4.6. - schema_
shared - Vendor-neutral primitives shared between
postgres_schemaandmssql_schema.
Structs§
- Conversion
Conflict - HeerId
- 64-bit time-ordered identifier with ascending raw-bit order.
- Heer
IdDesc - 64-bit time-ordered identifier with descending raw-bit order; the
reverse-chronologically-sorted sibling of
HeerId. - Heer
IdParts - RanjId
- 128-bit UUIDv8 time-ordered identifier with ascending raw-bit order.
- Ranj
IdDesc - 128-bit UUIDv8 time-ordered identifier with descending raw-bit
order; the reverse-chronologically-sorted sibling of
RanjId. - Ranj
IdParts
Enums§
Constants§
- HEER_
NODE_ ID_ BITS - HEER_
SEQUENCE_ BITS - HEER_
TIMESTAMP_ BITS - RANJ_
NODE_ ID_ BITS - RANJ_
PRECISION_ BITS - RANJ_
SEQUENCE_ BITS - RANJ_
TIMESTAMP_ BITS
Functions§
- generation_
precision - Return the configured generation precision.
- try_
generation_ precision - Parse
RANJID_PRECISIONwithout panicking.