RaftConfig

constructor(electionTimeoutMin: Duration = 150.milliseconds, electionTimeoutMax: Duration = 300.milliseconds, heartbeatInterval: Duration = 50.milliseconds, strictTestGuard: Boolean = false, expectVirtualTime: Boolean = false, slowProposeThreshold: Duration = 100.milliseconds, snapshotChunkCeiling: Int = 16 * 1024, random: Random = Random.Default)

Parameters

electionTimeoutMin

Lower bound of the randomised election timeout window.

electionTimeoutMax

Upper bound of the randomised election timeout window.

heartbeatInterval

How often the leader sends a heartbeat. Must be less than electionTimeoutMin.

strictTestGuard

When true, throw IllegalStateException at construction time if the owning kotlinx.coroutines.CoroutineScope contains a kotlinx.coroutines.test.TestDispatcher. When false (the default), emit a warning to stdout instead. Set to true in tests that want to assert the guard fires. Leave false in production — the guard is informational there.

expectVirtualTime

Suppresses the TestDispatcher warning (see strictTestGuard) for tests that intentionally run a real RaftNode under a TestDispatcher (both StandardTestDispatcher and UnconfinedTestDispatcher are supported). Under any TestDispatcher, delay() is virtual — the engine's election/heartbeat loops tick via the test scheduler. Has no effect in production. Default false: warn as usual.

The :kuilt-raft suite uses StandardTestDispatcher (see RaftTestFixtures). Set true in any config used by a test that constructs a real RaftNode. NEVER set in production code.

slowProposeThreshold

Wall-time threshold for a propose round-trip (from accepted to applied). When the elapsed time exceeds this threshold, the engine logs at warn level. Below this threshold, the log entry is at debug level. Set to Duration.ZERO to treat every propose as slow (useful in tests that want to assert the warn path fires). Default 100ms — appropriate for LAN clusters.

snapshotChunkCeiling

Upper bound on the bytes carried in a single §7 InstallSnapshot chunk. The actual chunk size is the lesser of this and the transport's RaftTransport.maxPayloadBytes (minus a small header budget), so a fabric with a tighter framing limit shrinks chunks automatically.

random

Source of randomness for the election-timeout draw. Randomness is a dependency, like time: under virtual time a kotlinx.coroutines.test.TestDispatcher makes scheduling deterministic, but an unseeded RNG still injects non-determinism into the durations the engine waits. Production default is Random.Default. Tests that run under virtual time should inject a seeded Random(<fixed seed>) so every run draws identical election timeouts — making the whole engine deterministic. Multi-node tests must use distinct seeds per node so nodes draw different timeouts and symmetry-break into a leader; use MultiNodeRaftSim from :kuilt-raft-test which handles this automatically. NEVER seed in production: a fixed seed defeats the split-vote avoidance that timeout randomisation exists for.