SnapshotRebuildStore

The snapshot rebuild control plane of a SnapshotStore, its own port: a store offers it through SnapshotStore.rebuilds. The snapshot subscriptions never use it; the node's snapshot maintenance does.

Rebuilds work per aggregate type, its table: the store records the state revision the table is claimed at (claim, table), and the snapshots of another revision or marked stale (markStale) are pending until a rebuild rewrites them from the log, in place, whatever their revision. The TCK's SnapshotStoreSpec checks it for a store that has it.

Functions

Link copied to clipboard
abstract suspend fun claim(type: AggregateType, revision: Int, lower: Boolean = false): SnapshotTable

Claims type's table at state revision and returns its record after the claim. The first claim records the table, not yet backfilled, and rebuilding unless revision is 1 (a snapshot written before revisions is of revision 1). A later claim raises a lower revision; it lowers a higher one only when lower says so (a rollback, once no node of the higher revision is left); either change starts a rebuild. Claims are atomic: concurrent claims leave one revision.

Link copied to clipboard
abstract suspend fun mark(type: AggregateType, revision: Int, rebuilding: Boolean? = null, backfilled: Boolean? = null): SnapshotTable?

Sets rebuilding and backfilled, each when given, on type's table while it is claimed at revision; returns the record after, or null when the table is claimed at another revision or not at all.

Link copied to clipboard
abstract suspend fun markStale(ref: AggregateRef): Boolean

Marks the snapshot of ref stale, so a rebuild rewrites it from the log (pending) whatever its state revision; false when there is none.

Link copied to clipboard
abstract suspend fun pending(type: AggregateType, revision: Int, after: AggregateRef? = null, limit: Int): List<AggregateRef>

The refs of type's snapshots a rebuild at state revision has to rewrite: those of another state revision, and those marked stale; at most limit of them, in key order (tenant, then aggregate id, by code point), after after when it is given.

Link copied to clipboard
abstract suspend fun rewrite(snapshot: SnapshotRecord): Boolean

Stores snapshot, rebuilt from the log, in place of the stored one: when the store holds none for its ref, or holds the same or a lower version, whatever its state revision; returns whether it was written. A stored version above snapshot's, written meanwhile, stays. Writing clears a stale mark of a version up to snapshot's.

Link copied to clipboard
abstract suspend fun table(type: AggregateType): SnapshotTable?

The record of type's table: the state revision it is claimed at and how far it is; null before any claim.