complete
Close lease and charge its leaf actualCost. Beyond the reservation, the shortfall is extended inline first (minted at the root if the root is short) and reported as the overrun; below it, the unused remainder is handed back up the path. Never refused.
Work that held its slot settles here, whether it finished, failed or was abandoned part-way: actualCost is what it cost, by convention the time it held the slot, and the charge is always the cost the caller reported. cancel is only for work that never ran.
waiting is every leaf with work queued once this lease's work is done, as for acquire. An overrun is a charge, so where there is one waiting is observed at every group the overrun crosses before it lands, as extend observes it (#3471). The overrun is the running work's own charge, so the lease's leaf counts as waiting for it whatever waiting says, as in extend, even when this was its last job. A completion within the reservation charges nothing new, so it observes nothing.
When an edge of the lease's path is no longer ACTIVE, an overrun cannot be delegated across it. The reservation is still charged at the leaf, and the overrun is charged at the deepest group of the path that ACTIVE edges still reach from the root (see "A draining path" in the class KDoc). An edge with no room for the whole overrun within Long stops it the same way (see "The lifetime limit"). Where no group below the root is reached, the overrun is above MAX_RECORDED_OVERRUN, or the root cannot fund it in whole, it is recorded nowhere and reported in LeaseOutcome.Done.unrecorded, with LeaseOutcome.Done.charged the cost less that. The reservation is charged at the leaf either way, and nothing else changes.
Throws
when actualCost is negative.
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)