SnapshotMaintenance
Keeps the snapshot targets of one bounded context in step with the log and the code, on every node, every SnapshotOptions.maintenanceInterval:
State revision claims: each node is a member of its state revision of each snapshotted type (in the lease group
<group>#snapshot/<aggregate>@<revision>), heartbeated on a timer of its own from enter until stop, whatever a round takes (SnapshotMembership), and claims each target's table (SnapshotRebuildStore.claim) at its revision: a higher revision at once (a new deployment, the start of a rolling upgrade), a lower one only once no member of the claimed revision is left (a rollback). Its snapshot subscriptions write at its revision whatever the claim; the store keeps a node of a lower revision from overwriting the higher one and marks those snapshots stale.In-place rebuild: a node whose revision a table is claimed at, and which holds the table's rebuild lease (the lease group
<group>#snapshot-rebuild/<store>/<aggregate>, so one node rebuilds), rewrites its pending snapshots (SnapshotRebuildStore.pending) from the log, page by page, at their latest version, each run going on from where the last one stopped, and marks the table rebuilt once a scan from its first snapshot finds none left, or parks every one it finds. A snapshot it cannot rewrite, whose history does not replay, whose read or rewrite fails in a way no retry changes, or whose log holds no stream of it, is parked underwow.snapshot.rewrite(skips) and left as it is stored, still pending, for an operator to retry (retry) or skip; any other failure stops the run, which resumes where it stopped. Once it marks the table rebuilt, it scans it from the first again: a snapshot pending then that no ledger parks, written or marked stale before the mark, behind a scan that parked every one included, marks the table rebuilding again, and the run goes on; a node whose round read the record between the two marks answers that the type is not rebuilding until its next round. A node of another revision marks the table rebuilding on each run, so the stale marks its refused saves leave are rewritten.Backfill: a target that has not caught up with the log since it was first claimed is filled from the beginning of the log by the subscription its table's record names (SnapshotTable.fill), decided once by the claim that first records it (claim), so every node reads the same: the subscription that writes the store when that one had no checkpoint then (SnapshotFill.SUBSCRIPTION: it starts at the beginning), else a subscription of the table's own (SnapshotFill.BACKFILL, prepare,
<subscription>#<aggregate>) on every node for the partitions it runs, a node joining meanwhile included, whatever the store and its subscription's name: a store that replaced a type's own, even the default one, is filled from the log too. A target caught up once the subscription the record names has its checkpoint in every partition at the log's head of the previous run; the table is then marked backfilled, and every node's backfill of it stops writing on that mark, whichever node wrote it.The first claim's reading: the checkpoints are read before the claim that records the table. SUBSCRIPTION is recorded only when no checkpoint was seen: a checkpoint saved after that read is of a subscription starting at the beginning, which fills the table too. Two first claims leave one record, BACKFILL at worst redundant.
Nothing to backfill: a table its own subscription fills, met while the log holds no entry (a cluster started on fresh stores), is marked backfilled at once: that subscription starts at a beginning that holds nothing.
Rebuild requests: the built-in subscription REBUILD_SUBSCRIPTION rewrites, from the log, the snapshots each
wow.snapshot.SnapshotRebuildRequestedof the rebuild aggregate names (SnapshotRebuildModel), in each target: in place on a node of the claimed revision, else marked stale (or written at its own revision when missing) for the rebuild. The claim is read from the store before the rewrite and again after it, once for a request's ids and once for a page of the access walk (RebuildPage): a table claimed at another revision in between is marked rebuilding at it.
It answers rebuilding for a type while the table of the store its queries read (its copy when it has one, else its own store) is rebuilding or not backfilled, and removedFrom once that table's record says it was removed.
A removed table: a table whose record says its structure was removed under it (SnapshotTable.removed) holds nothing the log committed before, and its store serves it no more. The maintenance neither rebuilds it nor checks or marks its backfill, so no revision's rebuild reports it rebuilt: a run that finds it removed after a page or before its last mark stops, marking nothing, and the round checks no backfill on that record. It logs an error once a node meets it, naming the type, the store and what restores it, and queries of it are refused.
A table's generation (SnapshotGenerations): a claim whose configured generation is above the record's renews the table, which a backfill named after the record's generation then fills from the log's beginning; a lowered one leaves the record's. A node that first sees a table's generation in round n (its prepare is round 0) checks its backfill only against heads read in round n + 1 or later, so it marks it no earlier than round n + 2: every node, on one maintenance interval, has seen the renewal by then, and no entry one passed over before it is marked caught up.
The claims, rebuilds and backfill checks need a target store's rebuild control plane (SnapshotStore.rebuilds): a store without one is left out of them, with a warning when the node prepares and a count of the fallback (the observer's storeFellBack), and so is its share of a rebuild request.
Constructors
Properties
The built-in subscription that carries out the rebuild requests of the context.
Where the rebuilds park the snapshots they cannot rewrite; none: a failure of one stops the run.
The snapshotted aggregate types of the context.
Functions
Keeps this node a member of its revision of each type from now until stop, heartbeated in scope at once and then every third of SnapshotOptions.memberTtl, whatever a round takes: call it once the node is ready to join, at its start or at its activation from standby, so the join is covered.
Runs rewrites, a page of the access walk over type's aggregates, with the rebuild of each one's snapshot as rebuild does from its whole log, already replayed: one page (RebuildPage), so two reads of each target's table for the page, not for each aggregate. A type without snapshots rewrites none.
Makes this node a member of its revision of each type, with one heartbeat; claims every target's table at this node's revisions, and gives the subscriptions that backfill the targets whose store subscription is already past the beginning of the log: register them before the node starts. A node that waits on standby keeps no more than that heartbeat until enter: it rebuilds nothing meanwhile, so after SnapshotOptions.memberTtl the nodes of a lower revision roll its claim back, and its activation raises it again.
Rebuilds the snapshot of ref from the log in each target of its type (a rebuild request): in place where the table is claimed at this node's revision; elsewhere marked stale, or written at this node's revision when there is none, for the node of the claimed revision to rewrite. A page of one (RebuildPage): two reads of each target's table.
The store, by name, the table type's snapshot queries read was removed from under its record, or null while it is there; none is removed by default.
An operator's retry of ref, whose rewrite a rebuild skipped: rebuilt as rebuild does; true when every target was rewritten here, and its entry resolved. A target whose table is claimed at another revision, before the rewrite or after it, is left to the node of that revision, whose rebuild resolves the entry once it rewrites it; a failure that skips it leaves the entry as it is.
Stops the runs and the memberships' heartbeats, and leaves this node's revision memberships, so a rollback need not wait for them to expire. Call it once the node's subscriptions stopped: a table claimed at another revision than this node's is marked rebuilding once more, for the stale marks its last refused saves left; a removed one is left as its record says. A stop cut short before it leaves heartbeats no more, so the memberships expire.
The table records last seen, by store and aggregate type.