TopologyChange
One difference between two trees, named the way the admin who edited them thinks of it: a lane added, a weight changed, a template removed. Topology.changesTo lists them, so an admin page can show what an edit does before it is applied.
This is the reading of an edit, not the doing of it. The steps that move a ledger come from Topology.diff, which an interpreter runs; this list is for a person to confirm.
Addressed the way TopologyProblem is. path holds the child indices from the root down, counted from zero in the order written, and names the names along it, starting with the root's. A Removed child is addressed in the tree before the edit, since it is not in the tree after; every other change is addressed in the tree after it. In a valid tree sibling names are unique and non-empty, so names alone also identifies the node, in its own tree.
What carries history, and what does not. A group is identified by its names from the root down, so the changes say what the ledger will do:
a rename or a move is a Removed and an Added. There is no "moved" change, because nothing moves: the old child's history stays with the old child, and the new one starts with none.
a WeightChanged keeps the child but restarts its share: it rejoins its parent's front.
LaneBecameGroup, GroupBecameLane, CeilingChanged and every template change keep the child and its own history. What a template change does to the children the app attached under it is on TemplateRemoved and TemplateChanged.
a RootRenamed changes every name below it, so it is followed by every new child Added, then every old child Removed. Topology.diff refuses a change of root: it is a new tree, not an edit of the running one.
saveEffect says which of these a change is, so an editor warns from it rather than sorting the arms itself.
Samples
val running = draft("pool") {
group("acme", Weight.of(3)) {
lane("interactive")
lane("batch")
}
group("hobby") { lane("batch") }
}
val edited = draft("pool") {
group("acme", Weight.of(4)) {
lane("interactive", maxConcurrent = 2)
}
group("hobby") {
lane("batch")
lane("nightly")
}
}
check(
running.changesTo(edited) == listOf(
TopologyChange.WeightChanged(listOf(0), listOf("pool", "acme"), Weight.of(3), Weight.of(4)),
TopologyChange.CeilingChanged(listOf(0, 0), listOf("pool", "acme", "interactive"), null, 2L),
// A removed child is addressed where it was, in the running tree.
TopologyChange.Removed(listOf(0, 1), listOf("pool", "acme", "batch"), Topology.Lane("batch")),
TopologyChange.Added(listOf(1, 1), listOf("pool", "hobby", "nightly"), Topology.Lane("nightly")),
),
)
// Nothing changed, nothing listed.
check(running.changesTo(running).isEmpty())Inheritors
Types
node is new in the tree after the edit, with everything beneath it: one change for a whole new subtree. It starts with no history.
A group became a lane of the same name. It keeps its history; the children and template it lost follow as their own changes.
A lane became a group of the same name. It keeps its history; its new children, and its template if it has one, follow as their own changes.
node is gone from the tree after the edit, with everything beneath it, and its history with it. Addressed in the tree before the edit.
What a TopologyChange costs in fairness history; see TopologyChange.saveEffect. Three answers, because an editor does three things: saves, warns, or refuses.
The group gained a template, so the app may now attach children to it while running.
The group's template went from before to after. A new template weight restarts the share of every attached child; a new ceiling keeps their history. The same holds a level down for a nested template: a new weight there restarts every child attached beneath an attached one, and a nested template going closes them all, while one arriving turns each attached leaf into a group and keeps its history.
The group lost its template. Every child the app attached to it is closed, with its history, and does not come back if the template does.
Properties
the child indices from the root to the node this change concerns; [] only for RootRenamed. Every index is >= 0.
What LocalHeddle.apply does to fairness history when it lands this change: SaveEffect.LOST for a change that costs a group its history, the one to warn about before saving; SaveEffect.KEPT for one that costs nobody any; and SaveEffect.NEW_TREE for the one apply throws on, which an editor refuses to save rather than warns about.