Bedrock.DataPlane.Demux.MutationSlicer (bedrock v0.5.2)
View SourceSlices a transaction's mutations by shard using the SHARD_INDEX section.
Given a transaction with mutations sorted by shard and a SHARD_INDEX section indicating how many mutations belong to each shard, this module produces per-shard "slices" - mini-transactions containing only that shard's mutations.
Slice Format
Each slice is a valid BRDT (transaction) binary containing:
- Transaction header
- MUTATIONS section with just that shard's mutations
- COMMIT_VERSION section
This format allows materializers to decode slices using standard Transaction functions.
Summary
Types
@type shard_id() :: non_neg_integer()
@type slice() :: binary()
@type version() :: Bedrock.version()
Functions
Slices a transaction by shard, returning a list of {shard_id, slice} tuples.
The transaction must have a SHARD_INDEX section indicating how mutations are distributed across shards. Each slice is a valid transaction binary containing only the mutations for that shard.
Parameters
transaction- Encoded transaction binary with SHARD_INDEXcommit_version- The commit version to include in each slice (8-byte binary)
Returns
{:ok, [{shard_id, slice}]}- List of shard slices, one per shard touched{:error, reason}- If transaction is invalid or missing SHARD_INDEX
Example
{:ok, slices} = MutationSlicer.slice(encoded_txn, commit_version)
# slices = [{0, slice_binary_0}, {2, slice_binary_2}, ...]
Same as slice/2 but raises on error.
Extracts shard IDs from a transaction without full slicing.
Useful for determining which shards a transaction touches without creating the full slice binaries.
Returns
{:ok, [shard_id]}- List of shard IDs touched by the transaction{:error, reason}- If SHARD_INDEX is missing or invalid