Bedrock.SystemKeys.Values (bedrock v0.7.0)

View Source

Explicit value encodings for the \xFF/system keys Bedrock writes.

One codec per family, chosen deliberately: FDB tuple encoding for the scalar shapes here. Encoders are for trusted writers and raise on invalid input; decoders handle durable bytes and never raise. Decoding durable bytes must never create atoms.

The surface is exactly the written families - shard_keys/ entries (the routing boundary map) and materializers/ membership (the node as a string; consumers derive the callable {otp_name, node} ref from it and the worker id in the key, so the no-atoms rule holds through decode). Families return here when their readers do.

Summary

Functions

Decodes a value given its parsed system key (from Bedrock.SystemKeys.parse_key/1).

Decodes a distributor-lock UID; never raises, never creates atoms.

Decodes a materializer membership value to {:ok, node} (string).

Decodes a shard key entry to {:ok, {tag, start_key}}.

Encodes a distributor-lock UID: an opaque 16-byte token stored raw (there is nothing to structure; the value's only property is freshness-and-equality).

Encodes a materializer membership value: the member's node, a string.

Encodes a shard key entry: {tag, start_key}.

Types

decode_error()

@type decode_error() :: {:error, :invalid_encoding | :invalid_type | :unknown_family}

Functions

decode_for(arg1, value)

@spec decode_for(term(), binary()) :: {:ok, term()} | decode_error()

Decodes a value given its parsed system key (from Bedrock.SystemKeys.parse_key/1).

decode_lock_uid(uid)

@spec decode_lock_uid(binary()) :: {:ok, binary()} | decode_error()

Decodes a distributor-lock UID; never raises, never creates atoms.

decode_materializer_node(binary)

@spec decode_materializer_node(binary()) :: {:ok, String.t()} | decode_error()

Decodes a materializer membership value to {:ok, node} (string).

decode_shard_key_entry(binary)

@spec decode_shard_key_entry(binary()) ::
  {:ok, {Bedrock.range_tag(), Bedrock.key()}} | decode_error()

Decodes a shard key entry to {:ok, {tag, start_key}}.

encode_lock_uid(uid)

@spec encode_lock_uid(binary()) :: binary()

Encodes a distributor-lock UID: an opaque 16-byte token stored raw (there is nothing to structure; the value's only property is freshness-and-equality).

encode_materializer_node(node)

@spec encode_materializer_node(String.t()) :: binary()

Encodes a materializer membership value: the member's node, a string.

The worker id lives in the key (materializers/<tag>/<worker_id>), so the value carries only what a consumer cannot derive: the node. Both halves are string-encoded on purpose - never atoms or pids - so decoding durable bytes never creates atoms. The worker's OTP name is derivable from the id (cluster.otp_name_for_worker/1); conversion to a callable ref happens at the consumer.

encode_shard_key_entry(tag, start_key)

@spec encode_shard_key_entry(Bedrock.range_tag(), Bedrock.key()) :: binary()

Encodes a shard key entry: {tag, start_key}.

The key carries the shard's end_key; the value carries the tag and the range's start key, and readers consume the carried start key verbatim - a single entry is self-describing, no adjacency reconstruction.