shareLine

fun shareLine(waiting: Set<GroupId>): ShareLine

What every group is owed of the whole pool while waiting holds still, read once and answered group by group: see ShareLine.share. Where entitlement answers for a leaf a pick can end at, a line answers for any group, the root and every group above a lane included.

A group competes exactly when entitlement would count it: when a leaf of waiting that a pick could end at lies beneath it, and that leaf is below every ceiling on its lineage. So on a leaf, share(leaf) is entitlement(leaf, waiting, 1), and on a group it is the sum of its competing leaves' entitlements of one slot.

A ceiling is binary here, as it is in entitlement. A group at its Topology.Node.maxConcurrent does not compete and is owed 0. One below it keeps its whole weight share, even when that share is more slots than the leases it has room for, so a share is not a capped GPS rate.

The line also says how far each competing group stands from its share, ShareLine.lag: read at its parent as a pick arriving there now would read it, with the seat and wake step that pick takes first. That step runs on a copy of the wake memory, so asking moves nothing.

Samples

val tree = draft("pool") {
    group("research", Weight.of(2)) {
        lane("gpu", Weight.of(3))
        lane("cpu")
    }
    lane("ops")
    lane("docs")
}
val pool = tree.groupId()
val research = tree.groupId("research")
val gpu = tree.groupId("research", "gpu")
val cpu = tree.groupId("research", "cpu")
val ops = tree.groupId("ops")
val docs = tree.groupId("docs")
val (heddle, booted) = LocalHeddle.fromTopology(tree, LocalPolicy(defaultReservation = 1L), epoch = 0L)
check(booted.refusals.isEmpty())

// Docs has nothing queued, so research (weight 2) and ops (weight 1) split the pool 2 : 1.
val queued = setOf(gpu, cpu, ops)
val line = heddle.shareLine(queued)
check(line.share(pool) == Rational.ONE)
check(line.share(research) == Rational.of(2L, 3L))
check(line.share(ops) == Rational.of(1L, 3L))
check(line.share(docs) == Rational.ZERO)
// Research's share is its lanes' entitlements of one slot, added up.
check(line.share(gpu) == heddle.entitlement(gpu, queued, totalSlots = 1L))
check(line.share(research) == heddle.entitlement(gpu, queued, 1L) + heddle.entitlement(cpu, queued, 1L))

// With nothing queued anywhere, nothing competes, and even the pool is owed nothing.
check(heddle.shareLine(emptySet()).share(pool) == Rational.ZERO)