Changelog
View SourceAll notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[Unreleased]
[0.3.1] - Current
Added
- Per-Server WAL Isolation: Each server (identified by its
:uid) now owns its own WAL file at<wal_data_dir>/<uid>/wal.dat, with an independent buffer, index range, file handle, and pending-write set. A single WAL process can serve every server in a system without interleaving their entries. The WAL APIs now take auid:append/4,append_async/3,truncate/4,info/2, andread/4;overview/1reports aggregate state across all files. - Deterministic Cluster UIDs:
RaftEx.new_uid/1now derives a stable UID from a SHA-256 digest of the source, so restarting or re-forming a cluster with the same name recovers its existing log instead of starting from an empty directory. - Leaderboard.forget_leader/1: Added a helper that clears a stopped server's cached leader entry while retaining the cluster's member list, so
find_leader/1can still query the remaining members.
Changed
- WAL Record Format v2: WAL records now include the entries-blob byte size in the header so each record can be read back exactly. Legacy v1 records (count-only header) can no longer be decoded reliably; recovery now stops cleanly instead of returning a partial log.
- Synchronous
last_appliedCheckpointing:RaftEx.Domain.Server.persist_last_applied/1now usesLogMeta.store_sync/4and is checkpointed immediately when committed entries are applied. This prevents a client-visible state change from being lost if the server is stopped in the same tick. - Cross-Node RPC Routing: Remote
safe_call/3now uses:erpcto invoke a local entry point on the target node, with structured error mapping (:noproc,:nodedown,:shutdown, timeouts).pid_to_server_id/1resolves registered names on remote nodes via:erpc. Remote sends now wrap messages with the sender pid so the receiver can deriverpc_from, matching the local send path. - WAL-Backed Leader Appends: Leader command and cluster-change entries now go through
Log.write/2(write-ahead) instead of in-memoryLog.append/2, with graceful{:not_appended, reason, ...}handling when the WAL is unavailable.
Fixed
- Server Stop/Delete Reliability:
stop_server/2anddelete_server/2now locate the server's supervisor child by walking theDynamicSupervisortree and delegate termination tostop_server_rpc/2, which also forgets the cached leader. Deleting an already-stopped server is now idempotent instead of raisingFunctionClauseError. - Recovery Fold Strategy:
RaftEx.Infra.Persistence.Log.fold/6now handles the:returnstrategy used when scanning entries above the commit index during recovery.
[0.3.0] - 2026-11-24
Added
- Commit Index Propagation via Heartbeats: Added a
:commit_indexfield toRaftEx.Domain.Types.HeartbeatRpc. Leader heartbeats now carry the current commit index; followers advance their own commit index from it and apply newly committed entries. Leaders rebroadcast commit advances to their peers, and followers handleHeartbeatRpcexplicitly viaRaftEx.Domain.Server.handle_follower/2. - Exposed
RaftEx.Domain.Server.apply_committed/2for applying committed log entries to the state machine.
Changed
- Follower Reply Ownership: Followers applying committed entries no longer emit client replies. Only the leader owns the caller's reply alias, preventing duplicate responses when the same entry is applied across the cluster.
- System Lifecycle Tracking:
RaftEx.Infra.Supervisor.SystemsSupervisornow records started system PIDs in:persistent_termand uses them instop_system/1to reliably terminate the correct child, falling back to child-ID lookup when no stored PID is available.
Fixed
- WAL Directory Config:
RaftEx.Infra.Persistence.LogWalnow reads the:dirkey (as built byLogWalSupervisorfrom:wal_data_dir), falling back to:data_dirfor callers passing the full system config directly. - RPC Sender Resolution:
RaftEx.App.ServerRuntime.pid_to_server_id/1now handles both the tuple and list forms returned byProcess.info(pid, :registered_name)and guards against non-atom names. - Metrics Safety:
RaftEx.key_metrics/1now normalizes non-map counter values (e.g.:undefinedfor unregistered servers) to an empty map instead of raisingBadMapError.
[0.2.0] - 2026-11-24
Added
- Clean Architecture Layout: Modules reorganized into four layers —
RaftEx.Domain.*(pure Raft logic),RaftEx.App.*(OTP orchestration),RaftEx.Infra.*(adapters), and the top-levelRaftExpublic facade. The Raft core can now be exercised without starting OTP. - Plug-style Middleware Pipelines: Added
RaftEx.Domain.Conn(Plug-compatible context withassign/3,halt/1,put_resp/2,get_assign/3), theRaftEx.Domain.Plugbehaviour (init/1,call/2), and theRaftEx.Domain.Pipelinerunner with halt semantics. Pipelines are pure and add no runtime dependency. - Configurable Command & RPC Pipelines: Added
:command_plugsand:rpc_plugskeys to system and server config. Plugs are initialized once at server startup and run around command handling and incoming AppendEntries/vote/snapshot RPCs; a halted pipeline short-circuits processing and replies from the conn. Default is an empty pipeline, so existing behavior is unchanged. - Shared Test Support: Added
RaftEx.TestSupportwith a temporary-directory helper and addedtest/supporttoelixirc_paths(:test).
Changed
- Module Namespace Migration (breaking): Public/internal modules moved to layered namespaces, e.g.
RaftEx.Server→RaftEx.Domain.Server,RaftEx.ServerProc→RaftEx.App.ServerRuntime,RaftEx.Log→RaftEx.Infra.Persistence.Log,RaftEx.Network→RaftEx.Infra.Network.Transport,RaftEx.Types→RaftEx.Domain.Types,RaftEx.Machine→RaftEx.Domain.Machine. README examples and the Mix task were updated accordingly. - OTP Application Callback: Renamed
RaftEx.ApplicationtoRaftEx.OTPApplicationand updatedmix.exs. - Naming Fixes: Corrected the
MachineSimplefilename typo (simpile→simple, nowRaftEx.Domain.Machine.Simple) and renamedRaftEx.Monitorsto the singularRaftEx.Infra.Observability.Monitor. - Test Suite Reorganization: Tests are now split by layer into
test/domain/,test/app/, andtest/infra/, with integration/facade tests undertest/integration/and new coverage for previously untested modules (Election, RpcHandler, network, persistence, supervisors, Mix task). Test count grew from 130 to 552 and overall line coverage from 37.7% to 82.4%.
Fixed
Seq.in_range/2Argument Order: Fixed reversed arguments passed throughfloor/2andlimit/2that raisedFunctionClauseError; now computeslimit(ending, floor(start, seq)).Cluster.update_peer/3Call Order: Fixed all fourRpcHandlercall sites that passedclusterfirst instead of(peer_id, update, cluster), which raisedFunctionClauseError.
Removed
RaftEx.Lib: The catch-all module was removed; its helpers were consolidated intoRaftEx.Domain.Utils(type coercions, UID generation, server-ID helpers, and miscellaneous utilities).
[0.0.2]
Critical Fixes
- Vote Attribution Bug: Fixed election vote counting - votes were incorrectly attributed to self instead of replying peer, making multi-node elections impossible to win
- Follower AppendEntries Stub: Replaced stub
handle_followerwith properRpcHandlerdelegation for term checking, log consistency verification, entry appending, and commit index advancement - Log Truncation No-Op: Implemented actual
truncate_log_fromto remove conflicting entries when leader sends entries with different terms at same index (Raft Log Matching Property) - Vote Term Ordering: Fixed election livelock risk - now checks log up-to-date BEFORE updating term/voted_for when candidate has higher term
- Write-Ahead Ordering: Fixed
Log.write/2to write to WAL before updating in-memory state, ensuring true write-ahead semantics - Segment Durability: Added
:file.sync/1calls after segment append and seal operations for crash safety
Important Fixes
- ETS Table Leak: Fixed
LogMetato delete ETS table on terminate, preventing resource leaks on restart - Election Reply Tracking: Added peer ID tracking in process dictionary for correlating election RPC replies with sender
- Snapshot Transfer: Implemented leader-side snapshot chunk sending with peer status tracking and completion handling
New Features
- Network Layer: Added
RaftEx.Networkmodule for unified local/remote RPC routing with node monitoring - Segment Files: Complete immutable segment file implementation with fsync, recovery, truncation, and deletion
- Server Process States: Full implementation of
candidateandpre_votestates with election timeout handling - Test Coverage: Added 11 new tests (96 → 107) covering segment writer, network layer, and cluster operations
Code Quality
- Added
excoveralls,dialyxir,credofor test coverage and static analysis - Added
qualityandquality.cialiases for running format, credo, and dialyzer
[0.0.1] - Initial Release
Features
- Initial experimental Elixir port of RabbitMQ RA Raft consensus algorithm
- Leader election with pre-vote support
- Write-ahead log (WAL) with batched writes
- Log replication and snapshotting
- Cluster membership management
- Pluggable state machine interface
- Effects system for reply routing and notifications
- 85 passing unit tests