Bedrock.DataPlane.Demux.Server (bedrock v0.5.3)
View SourceDemux coordinator that receives transactions from Log, slices by shard, and routes to ShardServers.
Responsibilities
- Receive transactions pushed from Log via
GenServer.cast - Walk transaction, slice mutations per shard using MutationSlicer
- Send
{:txn, version, slice}to each touched ShardServer - Spin up ShardServer on first touch (lazy)
- Track durability: receive reports from ShardServers
- Report min_durable_version to Log for WAL trimming
Durability Tracking
When a ShardServer flushes data to ObjectStorage, it sends
{:durable, shard_id, max_version} to this process. We track
the minimum durable version across all active shards using gb_sets.
Shard Activation
When the first transaction touches a shard, we:
- Start a ShardServer linked to this process
- Add the shard to durability tracking with initial version = last_seen_version
Failure Semantics
ShardServers are linked to this process. If any ShardServer crashes, this process crashes, which should crash the owning Log. Recovery replays from WAL with idempotent ObjectStorage writes.
Summary
Functions
Returns a specification to start this module under a supervisor.
Gets the ShardServer for a given shard.
Returns the current minimum durable version across all shards.
Pushes a committed transaction to the Demux for distribution.
Starts the Demux.Server linked to the calling process.
Types
@type shard_id() :: non_neg_integer()
@type version() :: Bedrock.version()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec get_shard_server(GenServer.server(), shard_id()) :: {:ok, pid()} | {:error, term()}
Gets the ShardServer for a given shard.
Called by materializers to discover their ShardServer for pulling. Creates the ShardServer if it doesn't exist yet.
@spec min_durable_version(GenServer.server()) :: version() | nil
Returns the current minimum durable version across all shards.
Returns nil if no shards are active.
@spec push(GenServer.server(), version(), binary()) :: :ok
Pushes a committed transaction to the Demux for distribution.
Called by Log after a transaction is committed. This is async (cast).
Parameters
server- Demux.Server pid or nameversion- Commit version (8-byte binary)transaction- Encoded transaction binary with SHARD_INDEX
@spec start_link(keyword()) :: GenServer.on_start()
Starts the Demux.Server linked to the calling process.
Options
:cluster- Required. Cluster name.:object_storage- Required. ObjectStorage backend.:log- Required. PID of the owning Log.