reconcileLeases
Compare the engine's open leases with live, the leases whose work the caller still has running, as of now in the cost unit. Reports both directions and changes nothing.
Each orphan carries how long it ran, max(0, now − startedAt). Which orphans to settle, and at what cost, is the caller's policy; LeaseReconciliation.Orphan.defaultSettlement is the documented default. Work that will resume belongs in live, so it never becomes an orphan.
Throws
when now − startedAt is positive and does not fit in a Long.
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())
heddle.reconcileCapacity(totalSlots = 2L)
val queued = setOf(heavy, light)
val kept = (heddle.acquire(queued, queued, startedAt = 100L) as AcquireOutcome.Acquired).lease
val lost = (heddle.acquire(queued, queued, startedAt = 101L) as AcquireOutcome.Acquired).lease
// The executor came back running only `kept`, and one job the engine never leased.
val stranger = LeaseId(epoch = 7L, seq = 0L)
val found = heddle.reconcileLeases(live = setOf(kept.id, stranger), now = 110L)
check(found.unknown == listOf(stranger))
val orphan = found.orphaned.single()
check(orphan.lease == lost && orphan.elapsed == 9L && orphan.granted == 3L)
// It ran 9 units against the 3 it was granted, which a dead job cannot prove: charge 3.
check(heddle.complete(orphan.lease.id, orphan.defaultSettlement, waiting = queued) == LeaseOutcome.Done(charged = 3L, overrun = 0L, unrecorded = 0L))
check(heddle.reconcileLeases(live = setOf(kept.id), now = 110L).orphaned.isEmpty())Content copied to clipboard