advanceClock

fun advanceClock(replica: ReplicaId, lamport: Long, seq: Long): Rga<V>

This state with its lamport clock raised to at least lamport, and replica's seq to at least seq, so the next id minted as replica lies past both. Returns this when neither rises. No op is added, removed or changed, so the result equals this state.

For a replica that has lost sight of ops it minted. A log kept across several keys can come back with one key unreadable, and the ids in that key are still taken: minting from what was read hands one of them out again, and a later union keeps one record of the pair. Record lamport and seqHighWater somewhere that is read with the rest, and raise the rebuilt state to them before minting.

Neither counter is on the wire: a decode derives both from the ops and the floor it finds. So the raise does not outlive an encode, and the caller keeps the pair itself.

Only replica's seq moves. Another author's seq is that author's to mint, and nothing here reads it; lamport is the one clock all authors share.

A raised seq breaks RgaId.seq's density, and this state cannot repair it. RgaId.seq is dense per author; a raise past seqs this state does not hold leaves a hole at each of them. Two things key on density, and each stalls at the first hole:

  • dropWindow folds replica's drops into its floor only along an unbroken run up from the floor, so it stops below the first held-nowhere seq. Every later own drop above it is recorded as an explicit RgaOp.Compact instead, one pair per id. They accumulate until the missing ops are pieced back in, and the ones already recorded stay after that. If the ops never come back, the floor never moves again. dropWindowPastUnheld is the walk that crosses a hole, for a caller whose window drops oldest-minted first.

  • causalDots reports no dot for a hole, so a frontier folded from it stops below the hole, and compact never collects replica's ops past it, on this replica or on any peer that folds this frontier.

The raise lives in the derived caches alone, which otherwise always match a rebuild from the ops and the floor. A decode of this state is equal to it and holds the lower counters, so a raise lost that way re-mints the ids it was meant to protect.

So raise only past ops that exist somewhere a later piece can bring back, and only as far as they go. A caller that cannot promise that pays the first cost for as long as they are away.

Throws

Samples

val a = ReplicaId("A")

val (full, minted) = Rga.empty<String>().insertAllAfter(a, RgaId.HEAD, listOf("one", "two", "three"))
// Kept somewhere that is read with the rest, such as an index naming where the ops live.
val lamport = full.lamport
val seq = full.seqHighWater(a)

// Rebuilt from a part that holds only the first op: minting from it would reuse "two"'s id.
val partial = Rga.empty<String>().apply(minted.first())
check(partial.seqHighWater(a) == 1L)

val raised = partial.advanceClock(a, lamport, seq)
check(raised == partial) // no op added: the same state, with its counters raised

val (_, next) = raised.insertAllAfter(a, minted.first().id, listOf("four"))
check(next.single().id.seq == seq + 1)
check(next.single().id.lamport > lamport)