awaitRead

suspend fun RaftNode.awaitRead(applied: StateFlow<Long>): Long

Linearizable read barrier: confirms the read index via RaftNode.readIndex, then suspends until applied reaches it, returning that index. applied is the caller's own monotonic applied-index flow, advanced as it consumes RaftNode.committed.

applied must advance on every Committed value, not only Committed.Entry. The read index is a commit index and counts entries raft withholds the contents of (the §5.4.2 election no-op, §6 config entries); those arrive as Committed.Internal markers precisely so the applied prefix can cross them. An applied fed only by application entries can sit legitimately below the read index after an election or a membership change, and this call then blocks until unrelated traffic commits past the gap (#1718):

val applied = MutableStateFlow(0L)
scope.launch {
node.committed.collect { c ->
when (c) {
is Committed.Entry -> { apply(c.entry.command); applied.value = c.entry.index }
is Committed.Internal -> applied.value = c.index // nothing to apply
is Committed.Install -> { reset(c.snapshot.state); applied.value = c.snapshot.throughIndex }
}
}
}
val fenced = node.awaitRead(applied)

Throws

if not the leader.

if leadership is lost before the round confirms.