aarondb/command
command — deterministic replicated command-state-machine reference
This module deliberately has no transport, leader election, or local DB integration. A future consensus runtime supplies the committed index; this module deterministically applies the same command on every member.
Types
pub type Applied {
Applied(
idempotency_key: String,
fingerprint: String,
result: CommandResult,
)
}
Constructors
-
Applied( idempotency_key: String, fingerprint: String, result: CommandResult, )
pub type Command {
Put(key: String, value: String)
CompareAndSet(
key: String,
expected: option.Option(String),
replacement: String,
)
IssueFence(resource: String)
}
Constructors
-
Put(key: String, value: String) -
CompareAndSet( key: String, expected: option.Option(String), replacement: String, ) -
IssueFence(resource: String)
pub type CommandError {
IdempotencyPayloadMismatch(key: String)
InvalidCommittedIndex(index: Int, last_applied: Int)
}
Constructors
-
IdempotencyPayloadMismatch(key: String) -
InvalidCommittedIndex(index: Int, last_applied: Int)
pub type CommandResult {
Written(key: String, value: String)
CasApplied(
key: String,
previous: option.Option(String),
value: String,
)
CasRejected(key: String, actual: option.Option(String))
FenceIssued(resource: String, token: Int)
}
Constructors
-
Written(key: String, value: String) -
CasApplied( key: String, previous: option.Option(String), value: String, ) -
CasRejected(key: String, actual: option.Option(String)) -
FenceIssued(resource: String, token: Int)
pub type Consistency {
Local
LeaseRead
Linearizable
}
Constructors
-
Local -
LeaseRead -
Linearizable
pub type Value {
Value(key: String, value: String)
}
Constructors
-
Value(key: String, value: String)
Values
pub fn apply(
index: Int,
request: CommandRequest,
state: State,
) -> Result(#(State, CommandResult), CommandError)
The committed index must advance exactly once. Retried idempotency requests return their original result without applying another mutation.
pub fn last_applied(state: State) -> Int
pub fn read(
state: State,
key: String,
mode: Consistency,
) -> #(Consistency, option.Option(String))
pub fn replay_hash(state: State) -> String
The hash is intentionally constructed from closed, ordered data. It is an audit/replay fingerprint, not a cryptographic signature.