insertAllAfter

fun insertAllAfter(replica: ReplicaId, after: RgaId, values: List<V>): Pair<Rga<V>, List<RgaOp.Insert<V>>>

Append values as a chain starting immediately after after, minting one RgaOp.Insert per element on behalf of replica.

The bulk sibling of insertAfter, and indistinguishable from calling it in a loop below the clock ceiling: the same ids, the same after links, the same Lamport clock, the same op-set. At the ceiling they part (#3417): a loop whose clock would pass Long.MAX_VALUE part-way mints the prefix that fits and then throws, while this refuses the whole run and mints nothing. Otherwise what differs is the cost. insertAfter rebuilds ops and insertsById on every call, so appending k elements to an N-op log is k copies of N — Θ(k·N). This pays one ops + newOps and one cache build for the whole run, so it is Θ(N + k).

That is the amortisation WarpLogRecordExporter needs to stop paying a Θ(N) append per log record (#2194), and it needs no persistent data structure and no new dependency on this deliberately lean module. It does not remove the Θ(N) term — one ops copy per run remains, which is #2193's Phase 3A.

When this really is an append — after is the last element of the full sequence — and this instance is already holding that order, the order is extended instead of being recomputed (#2193's Phase 3B). Any other after, or an instance holding no order, passes nothing on and the next read rebuilds once.

"Already holding" means either half: an order threaded in from the producing mutation, or one an earlier plain read forced (#2225). What it never means is computing one — see rule 2 of RgaCache.sequence.

An empty values returns this — the same instance, not a copy.

Return

the new state, and the ops to broadcast in append order.

Throws

if the run would carry the Lamport clock or replica's seq past Long.MAX_VALUE (#3417). The whole run is refused; no prefix of it is minted.