TopologyChange

sealed interface 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

Link copied to clipboard
data class Added(val path: List<Int>, val names: List<String>, val node: Topology.Node) : TopologyChange

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.

Link copied to clipboard
data class CeilingChanged(val path: List<Int>, val names: List<String>, val before: Long?, val after: Long?) : TopologyChange

The node's maxConcurrent ceiling went from before to after; null is no ceiling and 0 pauses the node.

Link copied to clipboard
data class GroupBecameLane(val path: List<Int>, val names: List<String>) : TopologyChange

A group became a lane of the same name. It keeps its history; the children and template it lost follow as their own changes.

Link copied to clipboard
data class LaneBecameGroup(val path: List<Int>, val names: List<String>) : TopologyChange

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.

Link copied to clipboard
data class Removed(val path: List<Int>, val names: List<String>, val node: Topology.Node) : TopologyChange

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.

Link copied to clipboard
data class RootRenamed(val before: String, val after: String) : TopologyChange

The root was renamed from before to after. Addressed at [], under the new name.

Link copied to clipboard

What a TopologyChange costs in fairness history; see TopologyChange.saveEffect. Three answers, because an editor does three things: saves, warns, or refuses.

Link copied to clipboard
data class TemplateAdded(val path: List<Int>, val names: List<String>, val template: Topology.ChildTemplate) : TopologyChange

The group gained a template, so the app may now attach children to it while running.

Link copied to clipboard
data class TemplateChanged(val path: List<Int>, val names: List<String>, val before: Topology.ChildTemplate, val after: Topology.ChildTemplate) : TopologyChange

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.

Link copied to clipboard
data class TemplateRemoved(val path: List<Int>, val names: List<String>, val template: Topology.ChildTemplate) : TopologyChange

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.

Link copied to clipboard
data class WeightChanged(val path: List<Int>, val names: List<String>, val before: Weight, val after: Weight) : TopologyChange

The node's weight went from before to after. The node keeps its name but restarts its share, rejoining its parent's front: a new weight is a new edge in the ledger.

Properties

Link copied to clipboard
abstract val names: List<String>

the names along path, starting with the root's, so it always holds one more entry than path. None is empty.

Link copied to clipboard
abstract val path: List<Int>

the child indices from the root to the node this change concerns; [] only for RootRenamed. Every index is >= 0.

Link copied to clipboard

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.