Raxol.Core.Session.SessionReplicator (Raxol v2.0.1)

View Source

Handles session replication and synchronization across nodes in a distributed cluster.

The SessionReplicator ensures session data consistency across multiple nodes by managing replication, conflict resolution, and synchronization of session state.

Features

  • Asynchronous session replication across replica nodes
  • Conflict-free replicated data types (CRDTs) for session merging
  • Vector clocks for ordering and conflict detection
  • Configurable replication factor and consistency levels
  • Anti-entropy mechanisms for drift correction
  • Partition tolerance with eventual consistency

Replication Strategies

  • Immediate: Synchronous replication to all replicas
  • Eventual: Asynchronous replication with eventual consistency
  • Quorum: Write to majority of replicas before confirming
  • Best Effort: Fire-and-forget replication

Usage

# Start replicator
{:ok, pid} = SessionReplicator.start_link(
  replication_factor: 3,
  consistency_level: :quorum
)

# Replicate session data
SessionReplicator.replicate_session(pid, session_id, session_data, replica_nodes)

# Sync session across replicas
SessionReplicator.sync_session(pid, session_id)

Summary

Types

consistency_level()

@type consistency_level() :: :strong | :eventual | :quorum | :weak

replication_strategy()

@type replication_strategy() :: :immediate | :eventual | :quorum | :best_effort

session_version()

@type session_version() :: {vector_clock(), term()}

vector_clock()

@type vector_clock() :: %{required(node()) => non_neg_integer()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_replication_status(pid)

@spec get_replication_status(pid()) :: %{
  pending_replications: non_neg_integer(),
  replica_health: %{required(node()) => :healthy | :degraded | :failed},
  sync_conflicts: non_neg_integer()
}

get_session_replicas(pid, session_id)

@spec get_session_replicas(pid(), binary()) :: {:ok, [node()]} | {:error, term()}

handle_manager_call(request, from, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_call/3.

handle_manager_cast(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.

handle_manager_info(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_info/2.

replicate_session(pid, session_id, session_data, replica_nodes, strategy)

@spec replicate_session(
  pid(),
  binary(),
  term(),
  [node()],
  replication_strategy()
) :: {:ok, term()} | {:error, term()}

resolve_conflicts(pid, session_id)

@spec resolve_conflicts(pid(), binary()) :: {:ok, term()} | {:error, term()}

start_link(init_opts \\ [])

sync_session(pid, session_id)

@spec sync_session(pid(), binary()) :: {:ok, term()} | {:error, term()}