reconcileCapacity

fun reconcileCapacity(totalSlots: Long)

Tell the engine how many slots the caller runs at once, totalSlots. It sizes the supply watermarks of LocalPolicy.supply and nothing else: it mints nothing and changes no lease, and calling it again with the same value changes nothing. Until it is called with a positive value no supply is minted ahead, and an acquire or extend the root cannot fund is refused.

Throws

when totalSlots is negative, or the target it sizes, totalSlots × defaultReservation × targetSlots, is above Long.MAX_VALUE / 4.

Samples

val tree = twoLanes()
val heavy = tree.groupId("heavy")
val light = tree.groupId("light")
val (heddle, booted) = LocalHeddle.fromTopology(tree, LocalPolicy(defaultReservation = 3L), epoch = 0L)
check(booted.refusals.isEmpty())
// Four slots: the engine mints its own supply ahead of them.
heddle.reconcileCapacity(totalSlots = 4L)

// Both groups have work queued, and this slot can run either.
val queued = setOf(heavy, light)
val first = heddle.acquire(waiting = queued, eligible = queued, startedAt = 100L)
check(first is AcquireOutcome.Acquired)

// The job overran its 3-unit estimate: all 5 units are charged, 2 of them as overrun.
check(heddle.complete(first.lease.id, actualCost = 5L, waiting = queued) == LeaseOutcome.Done(charged = 5L, overrun = 2L, unrecorded = 0L))

// Over many slots the shares follow the weights, 2 : 1.
val picks = (0 until 30).map {
    val lease = (heddle.acquire(queued, queued, startedAt = it.toLong()) as AcquireOutcome.Acquired).lease
    heddle.complete(lease.id, actualCost = 3L, waiting = queued)
    lease.leaf
}
check(picks.count { it == heavy } in 19..21)