Deterministic leases, fencing tokens and leader election primitives for MoonBit.
moon add dxh8888/moonleasekitlet acquired = @moonleasekit.LeaseState::new("jobs/leader").apply(
Acquire("worker-a", 10, None),
100,
)
guard acquired.lease is Some(lease) else { return }
let write = lease.fenced_write("commit-job-42", 101).unwrap()
let checked = @moonleasekit.FenceGuard::new().check(write)
assert_true(checked.accepted)moon check --target all
moon test --target wasm
moon test --target wasm-gc
moon test --target js
moon run cmd/main --target js
moon run bench/main --target jspub(all) struct AuditReport {
valid : Bool
checked_events : Int
findings : Array[AuditFinding]
} derive(Eq, Debug)pub(all) struct BatchResult {
table : LeaseTable
decisions : Array[LeaseDecision]
accepted : Int
rejected : Int
} derive(Eq, Debug)pub(all) struct FenceDecision {
next_guard : FenceGuard
accepted : Bool
highest_token : Int
message : String
} derive(Eq, Debug)pub(all) struct LeaseDecision {
state : LeaseState
accepted : Bool
kind : DecisionKind
lease : Lease?
event : LeaseEvent?
message : String
} derive(Eq, Debug)pub(all) struct LeaseEvent {
resource : String
kind : DecisionKind
at : Int
holder : String
token : Int
revision : Int
detail : String
} derive(Eq, Debug)pub(all) struct LeaseTable {
states : Array[LeaseState]
events : Array[LeaseEvent]
accepted_commands : Int
rejected_commands : Int
} derive(Eq, Debug)fn LeaseTable::acquire_leadership(self : LeaseTable, resource : String, certificate : QuorumCertificate, ttl : Int, now : Int) -> TableDecisionfn LeaseTable::apply(self : LeaseTable, resource : String, command : LeaseCommand, now : Int) -> TableDecisionfn quorum_size(cluster_size : Int) -> IntDeterministic leases, fencing tokens and leader election primitives for MoonBit.