Bedrock.ControlPlane.Config.Persistence (bedrock v0.5.2)

View Source

Handles encoding/decoding of cluster configuration for persistent storage.

Converts between runtime PIDs and serializable {otp_name, node} tuples to enable cluster configuration persistence across restarts. This module provides a clean separation between runtime efficiency (using PIDs) and storage requirements (using serializable references).

Summary

Functions

Decodes a cluster configuration from persistent storage.

Decodes a transaction system layout from persistent storage.

Encodes a cluster configuration for persistent storage.

Encodes a transaction system layout for persistent storage.

Types

encoded_config()

@type encoded_config() :: map()

encoded_service_status()

@type encoded_service_status() :: :down | {:up, otp_reference()}

otp_reference()

@type otp_reference() :: {atom(), node()}

service_status()

@type service_status() :: :down | {:up, pid()} | {:up, otp_reference()}

Functions

decode_from_storage(encoded_config, cluster)

@spec decode_from_storage(encoded_config(), module()) ::
  Bedrock.ControlPlane.Config.t()

Decodes a cluster configuration from persistent storage.

Converts {otp_name, node} tuples back to PIDs for runtime use.

Parameters

  • encoded_config: The configuration read from storage
  • cluster: The cluster module for OTP name resolution

Returns

  • Runtime configuration with PIDs restored

decode_transaction_system_layout_from_storage(encoded_layout, cluster)

@spec decode_transaction_system_layout_from_storage(map(), module()) ::
  Bedrock.ControlPlane.Config.TransactionSystemLayout.t()

Decodes a transaction system layout from persistent storage.

Converts {otp_name, node} tuples back to PIDs for runtime use.

Parameters

  • encoded_layout: The layout read from storage
  • cluster: The cluster module for OTP name resolution

Returns

  • Runtime layout with PIDs restored

encode_for_storage(config, cluster)

@spec encode_for_storage(Bedrock.ControlPlane.Config.t(), module()) ::
  encoded_config()

Encodes a cluster configuration for persistent storage.

Converts all PIDs to {otp_name, node} tuples that can be safely serialized with BERT encoding. Removes ephemeral state that shouldn't be persisted.

Parameters

  • config: The runtime cluster configuration
  • cluster: The cluster module for OTP name resolution

Returns

  • Sanitized configuration suitable for BERT encoding

encode_transaction_system_layout_for_storage(layout, cluster)

@spec encode_transaction_system_layout_for_storage(
  Bedrock.ControlPlane.Config.TransactionSystemLayout.t(),
  module()
) :: map()

Encodes a transaction system layout for persistent storage.

Converts all PIDs to {otp_name, node} tuples that can be safely serialized with BERT encoding.

Parameters

  • layout: The runtime transaction system layout
  • cluster: The cluster module for OTP name resolution

Returns

  • Sanitized layout suitable for BERT encoding