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.6.0] - 2026-11-26
Added
- Pipelined AppendEntries: leader now tracks in-flight AppendEntries per follower, handles out-of-order acknowledgements, applies bounded backpressure, and processes deferred
:pipeline_rpcsevents. - Expanded test coverage: the suite now exceeds 1,100 tests, including a generated decision-table suite for election/quorum, range and sequence boundaries, a distributed suite covering partitions, leader changes and node joins/removals across real BEAM peers, and focused coverage for
Cluster,Distribution,Counters,MetricNames,Metrics,SharedWaland the publicRaftEx.ObservabilityAPI. Overall line coverage is ~94%;Counters,MetricNamesandRaftEx.Observabilityare at 100%.
Changed
- Performance: optimized WAL append/recovery (reversed buffer, group commit, single serialization, linear recovery),
Log.fold/6range lookups, batched mem-table inserts,Log.truncate/2viaMap.drop/2, batchedRpcHandler.append_entries/3, atomic metrics counters, group-committedLogMeta, lazy segment loading, and reversed segment index accumulator. - Benchmarks: added a dependency-free benchmark suite (
scripts/bench.exs,bench/) with JSON output,--record/--compare/--threshold, anddocs/performance.mdwith before/after numbers.
Fixed
- RPC error mapping:
RaftEx.App.ServerRuntime.safe_call/3now converts:erpcexceptions such as{:erpc, :noconnection}into{:error, reason}instead of letting a bareErlangErrorescape to callers. - Cluster formation and joins:
Cluster.form_cluster/4no longer waits for local servers before starting them, removing a timeout that only passed when leftovers from earlier tests were still running.Cluster.join_cluster/5treats a missing seed server as a fresh cluster and no longer fails when the joining node hosts no servers. - Distribution handshake: cookie changes are no longer applied to an already-running node (which broke EPMD handshakes for later peers), and network test helpers now adapt peer names to short/long-name mode so
--snamedistributed runs work.
[0.5.1]
Fixed
- Distributed vote correlation:
RaftEx.Domain.Server.Election.handle_vote_reply/4andhandle_pre_vote_reply/4now resolve the peer id from the sender pid when no local tracking entry exists (remote peers), instead of usingnil. Stale replies whose term no longer matches are ignored instead of falling through to a non-matching clause. This prevents remote votes from being collapsed into a singlenilvoter and stops term-escalation livelocks in multi-node clusters.
[0.5.0] - 2026-11-26
Added
- Full metrics integration: new
RaftEx.Infra.Observability.MetricNamescatalogue covering WAL, replication, election, quorum, snapshots, and leadership transfer; metrics wired into all code paths; ETS-backedMetrics.get/1now reads gauges/histograms;RaftEx.Observability.server_metrics/1andcluster_metrics/1. - Documentation guides:
guides/with getting-started, architecture, state machine, persistence, membership, consistent queries, leadership transfer, observability, configuration, troubleshooting; ExDoc extras + groups;mix docs --warnings-as-errorsinquality.ci. - Doctests:
RaftEx.new_uid/1example andtest/doctests_test.exs. - Jepsen harness: fixed CLI invocation so
lein run testworks; hardened DB startup; updated README.
Changed
- Removed
:seshatdependency:Countersis now a thin compatibility layer over the ETS-backedMetricsstore;MetricsEtsno longer initialises seshat. - Metrics store is primary:
Counters.overview/0returnsMetrics.all().
Fixed
- Election timeout effects:
RaftEx.App.ServerRuntime.handle_election_timeoutnow converts the domain effects returned byElection.start_election/2throughhandle_effects/5before returning gen_statem actions. Previously{:store_meta, ...}effects leaked into the:pre_voteand:candidatestate functions as raw actions, crashing the server with{:bad_action_from_state_function, ...}whenever an election timed out.
[0.4.0]
Added
- Multi-server elections: Pre-vote and request-vote RPCs are now dispatched through the server state machine. Peer state carries
voter_status, so only voters count toward quorums and receive vote requests. Terms and votes are persisted before replies are sent, and election timeouts use the configured min/max values. - Leader no-op entry: New leaders append a no-op entry in their own term so prior-term entries can commit and cluster changes become permitted only after the entry commits.
- Local, leader and consistent queries: Query and auxiliary command paths now reply instead of timing out. Consistent queries confirm leadership with a voter quorum before returning, and aux commands are dispatched in every server state for both 5- and 6-arity machine handlers.
- Leadership transfer:
RaftEx.transfer_leadership/3now sends aTimeoutNowRpcto a caught-up voter, which starts an immediate election; the old leader steps down on the higher term. - Role-aware membership:
RaftEx.add_member/4,RaftEx.promote_member/3andRaftEx.demote_member/3carry voter/promotable/non-voter roles, with catch-up and last-voter safety checks. - Snapshot checkpointing: Machine release cursors and log compaction now write snapshots, compact the log, and recover state from disk on startup.
- Three-server integration tests: New coverage for elections, replication, queries, leadership transfer, and membership roles.
- Five- and seven-server cluster tests: New integration coverage for full replication, re-election after leader loss, duplicate/unknown-member errors, tolerated follower failures, and quorum-loss write rejection.
- Expanded edge-case coverage: The suite grew from 107 to 821 tests and line coverage from ~82% to 98.2%, including error paths across the app, domain, network, persistence and supervisor layers.
- Capability specifications: Behavioural specs for
cluster-membership,leader-election,log-replication,raft-queries,raft-startupandsnapshotswere synced intoopenspec/specs/. mix precommitalias: Runscompile --warnings-as-errors,format --check-formatted,credo --strict, and the full test suite in the:testenvironment.coveralls.json: Configures ExCoveralls to treat modules with no executable lines (typespecs, structs, behaviours) as covered instead of reporting a misleading 0.0%.
Changed
- Credo upgraded to 1.7.19 and cleaned up: Resolves a Credo 1.7.17 crash on Elixir 1.20. All 312 strict-mode findings were fixed in code — aliases, module docs, nesting/complexity extractions, implicit
tryconversions, and convention fixes — somix credo --strictnow reports no issues. Dialyzer retains pre-existing type-annotation warnings. - Predicate helpers renamed (breaking):
Filesystem.is_dir/1,is_file/1andis_any_file/1are nowdir?/1,file?/1andany_file?/1;Machine.is_versioned/1is nowversioned?/1;Server.is_new?/1andis_fully_persisted?/1are nownew?/1andfully_persisted?/1. All internal call sites were updated. - Snapshot chunk persistence returns errors:
LogSnapshot.accept_chunk/2andcomplete_accept/2now return{:error, reason}on file failures instead of raising, andRpcHandlerreports those failures through the normal snapshot-failure path. - Election result evaluation:
evaluate_election_result/1now records denied votes inelection_context.votes_rejected, so the:lostresult is reachable instead of being dead code.can_still_win?/3accounts for denied votes;can_still_win?/2keeps its previous behaviour. - Removed dead snapshot-effect handler:
handle_effect(:leader, {:send_snapshot_chunk, ...})was unreachable — chunks are sent via:infoactions — and was deleted. - Startup uses
:raft_ex:RaftEx.start/1andRaftEx.start_in/1stop and restart only the default system, configure the:raft_exapplication environment, and return a real success or error result. The:radata directory remains as a one-release fallback.
Fixed
- WAL recovery clause grouping: Moved the v1 fallback clause of
do_recover_records/4next to its sibling clause socompile --warnings-as-errorspasses. - README accuracy: Corrected the state-machine
@impltarget, install version, Git URL, plug configuration example, architecture diagram label, and obsolete test/status counts.
[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/1 resolves 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 via RaftEx.Domain.Server.handle_follower/2. - Exposed RaftEx.Domain.Server.apply_committed/2 for 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/1 now handles both the tuple and list forms returned by
Process.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.Applicationto RaftEx.OTPApplication and 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 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