Raxol.Core.Session.DistributedSessionStorage (Raxol v2.0.1)
View SourcePersistent storage layer for distributed session data.
The DistributedSessionStorage provides a fault-tolerant, consistent storage backend for distributed sessions with automatic sharding, replication, and data integrity guarantees.
Features
- Persistent session storage with configurable backends
- Automatic data sharding and partitioning
- Write-ahead logging for durability
- Snapshot and incremental backup support
- Data compression and encryption at rest
- Automatic cleanup of expired sessions
- Transaction support for atomic operations
Storage Backends
- ETS: In-memory storage with optional persistence
- DETS: Disk-based storage for single-node persistence
- Mnesia: Distributed database with replication
- External: Plugin interface for external databases
Usage
# Start storage with Mnesia backend
{:ok, pid} = DistributedSessionStorage.start_link(
backend: :mnesia,
replication_nodes: [:node1, :node2, :node3],
storage_options: %{
disc_copies: [:node1, :node2],
ram_copies: [:node3]
}
)
# Store session data
DistributedSessionStorage.store(pid, session_id, session_data, metadata)
# Retrieve session data
{:ok, data} = DistributedSessionStorage.get(pid, session_id)
Summary
Functions
Returns a specification to start this module under a supervisor.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_call/3.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_info/2.
Types
@type backend_type() :: :ets | :dets | :mnesia | :external
@type session_metadata() :: %{ created_at: DateTime.t(), last_accessed: DateTime.t(), expires_at: DateTime.t() | nil, size_bytes: non_neg_integer(), access_count: non_neg_integer() }
@type shard_id() :: non_neg_integer()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec cleanup_expired_sessions(pid()) :: {:ok, non_neg_integer()} | {:error, term()}
@spec get_metadata(pid(), binary()) :: {:ok, session_metadata()} | {:error, term()}
@spec get_storage_stats(pid()) :: %{ total_sessions: non_neg_integer(), total_size_bytes: non_neg_integer(), shard_distribution: %{required(shard_id()) => non_neg_integer()}, backend_stats: term() }
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_call/3.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.
Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_info/2.
@spec restore_sessions(pid(), binary()) :: {:ok, non_neg_integer()} | {:error, term()}