Raft::StateMachine(T)
Abstract base for application state machines. Subclasses implement
apply, snapshot, and restore.
The generic parameter T is the application's command type. It must
implement three methods that together form the on-disk/wire serialization
contract for log entries:
def to_io(io : IO, format : IO::ByteFormat) : Nil— write self to iodef self.from_io(io : IO, format : IO::ByteFormat) : T— read from iodef bytesize : Int32— number of bytesto_iowill write
bytesize must return exactly the byte count to_io writes. The library
uses bytesize to:
- predict serialized size for segment-rotation decisions in
Log#append - emit the size prefix in
LogEntry#to_iowithout an intermediate buffer
A bytesize that disagrees with to_io will silently corrupt the log:
offsets drift from actual byte positions, and subsequent reads return
garbage or fail.
Instance methods
apply(entry : T)
Source