Bedrock.DataPlane.CommitProxy.RoutingData (bedrock v0.5.2)

View Source

Manages routing data for the commit proxy.

Encapsulates all information needed to route mutations to logs:

  • shard_table - ETS ordered_set for key → tag ceiling search
  • log_map - Map of index → log_id for golden ratio routing
  • log_services - Map of log_id → {otp_name, node} for contacting logs
  • replication_factor - Number of logs per mutation

Lifecycle

  • new_empty/0 - Creates empty routing data for dynamic population
  • cleanup/1 - Deletes the ETS table when the commit proxy terminates

Shard Updates

Log Updates

Summary

Functions

Applies metadata mutations to update routing data.

Cleans up routing data by deleting the ETS table.

Removes a log service reference.

Deletes a shard entry from the routing table.

Adds a log to the log_map at the next available index.

Inserts or updates a shard entry in the routing table.

Creates empty routing data for dynamic population via metadata.

Adds or updates a log service reference.

Removes a log from the log_map and reindexes remaining entries.

Updates the replication factor.

Types

t()

@type t() :: %Bedrock.DataPlane.CommitProxy.RoutingData{
  log_map: %{required(non_neg_integer()) => Bedrock.DataPlane.Log.id()},
  log_services: %{required(Bedrock.DataPlane.Log.id()) => {atom(), node()}},
  replication_factor: pos_integer(),
  shard_table: :ets.table()
}

Functions

apply_mutations(routing_data, updates)

@spec apply_mutations(t(), [{term(), [term()]}]) :: t()

Applies metadata mutations to update routing data.

Handles shard_key and layout_log mutations:

  • shard_key: Updates ETS shard_table
  • layout_log: Updates both log_map and log_services

Parameters

  • routing_data - Current routing data
  • updates - List of {version, [mutations]} tuples from resolver

Returns

Updated routing data with applied mutations.

cleanup(arg1)

@spec cleanup(t() | nil) :: true

Cleans up routing data by deleting the ETS table.

Safe to call with nil or if the table has already been deleted.

delete_log_service(routing_data, log_id)

@spec delete_log_service(t(), Bedrock.DataPlane.Log.id()) :: t()

Removes a log service reference.

delete_shard(routing_data, end_key)

@spec delete_shard(t(), binary()) :: true

Deletes a shard entry from the routing table.

Called from apply_mutations/2 when processing shard_key clear mutations.

insert_log(routing_data, log_id)

@spec insert_log(t(), Bedrock.DataPlane.Log.id()) :: t()

Adds a log to the log_map at the next available index.

insert_shard(routing_data, end_key, tag)

@spec insert_shard(t(), binary(), term()) :: true

Inserts or updates a shard entry in the routing table.

Called from apply_mutations/2 when processing shard_key mutations.

new_empty()

@spec new_empty() :: t()

Creates empty routing data for dynamic population via metadata.

Starts with an empty shard table, no logs, and replication factor of 1. All fields are populated incrementally as metadata mutations arrive.

put_log_service(routing_data, log_id, service_ref)

@spec put_log_service(t(), Bedrock.DataPlane.Log.id(), {atom(), node()}) :: t()

Adds or updates a log service reference.

remove_log(routing_data, log_id)

@spec remove_log(t(), Bedrock.DataPlane.Log.id()) :: t()

Removes a log from the log_map and reindexes remaining entries.

Maintains contiguous indices starting from 0.

set_replication_factor(routing_data, factor)

@spec set_replication_factor(t(), pos_integer()) :: t()

Updates the replication factor.