Topology
The tree you write in a config file: who shares the pool, and in what proportions.
A Topology names a root group and nests Groups and Lanes beneath it, each with a Weight relative to its siblings — acme gets three parts to hobby's one, and inside acme the interactive lane gets three halves of the batch lane's share. Lanes are where work is charged; groups only divide their slice between their children.
A Topology that exists is valid. Every construction path — the constructor, copy, and a decode through the generated serializer — runs the same check, and throws TopologyException naming every problem at once. Because the tree is nested, it cannot express a cycle or a child with two parents. What remains to check is that every name is non-empty and unique among its siblings, that every group has a child to give its share to, and that no ceiling is negative.
The check runs once, at construction, against the lists you pass. Pass lists you will not mutate afterwards: a list changed after the check is a tree nothing has checked.
When the tree comes from an admin, decode a TopologyDocument instead and call from: that path never throws, and returns every problem with an address a config page can point at.
A rename or a move is a delete plus an add. A child is identified by its name and its place in the tree, so renaming one, or moving it under another group, retires the old child and starts a new one. The new child begins with no fairness history.
The same name may appear at different depths: acme/batch and hobby/batch are different children.
Its encoded shape, Node and ChildTemplate included, is part of LocalHeddleSnapshot's format 1, which stores the topology an engine last applied: a field added here takes a default, and any other change needs a frozen surrogate there first. Group.template is stored as template, the key a config uses too (#3454 review); v0.7.4 stored runtimeChildren, in its own layout this release does not read.
Samples
// As decoded from the file: names and weight text, nothing checked yet.
val written = TopologyDocument(
root = "pool",
children = listOf(
TopologyDocument.Group(
name = "acme",
weight = "3",
children = listOf(
TopologyDocument.Lane("interactive", weight = "3/2"),
TopologyDocument.Lane("batch"),
),
),
// A template: the app attaches children here while running, each at weight 1.
TopologyDocument.Group(name = "tenants", template = TopologyDocument.ChildTemplate()),
),
)
val parsed = Topology.from(written)
check(parsed is TopologyParse.Valid)
check(parsed.topology.children.first().weight == Weight.of(3))
// A typo is reported, not thrown: the second child of `acme` reuses a name.
val typo = written.copy(
children = listOf(
TopologyDocument.Group("acme", children = listOf(TopologyDocument.Lane("batch"), TopologyDocument.Lane("batch"))),
),
)
val problem = (Topology.from(typo) as TopologyParse.Invalid).problems.single()
// Addressed by child indices: the root's first child, then that child's second.
check(problem.path == listOf(0, 1) && problem.names == listOf("pool", "acme", "batch"))
check(problem.kind == TopologyProblem.Kind.DUPLICATE_NAME)Types
A group's template for the children the consumer attaches to it while running (LocalHeddle.attach). Every attached child gets weight and maxConcurrent. Its name is an opaque string the consumer chooses: heddle attaches no meaning to it.
A group of children that divide its slice between them.
A leaf of the tree: work is charged here.
Properties
Functions
The steps that attach the child at path, read from root down, at the weight the template it is attached under gives, and every attached group above it that is not attached yet, in the same list: [Prepare, Activate] for a new child of an attached group, the prepares top-down and then the activations top-down when its ancestors are new too, [Activate] when only the prepare landed, and [] when the whole path is attached. Each name is opaque and lives in its own namespace, so it never collides with a declared child, however it is spelt.
The ledger id of the attached child name of the group at group, read from root down. A child attached beneath an attached one has no form here: read its id with findGroupId and a GroupPath.Nested.
Every TopologyChange that turns this tree into after, in document order: walking the tree from the root down, a node's own changes come before its children's, and within a group the children of after come in the order written, followed by the children it no longer has, in the order they were written before. Empty exactly when the two trees differ in nothing but the order of siblings.
The steps that detach the child at path, and every child attached beneath it: [Close, Retire] for an attached leaf, [Retire] when it is already closing, and [] when there is nothing left to do. Beneath an attached group the whole subtree goes, closes top-down and retires bottom-up, so nothing is retired while a child beneath it still has a live edge. A retire is refused while work beneath it is outstanding or an open lease crosses it, even one reserving nothing, and so is every retire above it; detach again, or diff, once it has drained. Attaching the group again brings none of its children back.
The ledger id of the group at path, or null when this topology has no such group: a GroupPath.Declared it does not declare, a GroupPath.Attached whose group has no template, or a GroupPath.Nested whose parent's template carries no template. Never throws.
This tree written back out as a document: the form an editor starts from when an admin changes the tree that is running.