StateCache

Where the kernel keeps aggregates' states between commands, so a command does not replay the log.

The kernel takes a state out for one attempt and puts it back only when the attempt leaves it valid: committed (the evolved state at the new version), or decided without evolving (rejected, unchanged). Any other end drops it and the next command reloads. With mutable states evolving changes the cached instance itself, so a state must never stay cached through an attempt that may have changed it and did not commit.

Commands of one aggregate must not run concurrently on one cache (the executor serializes them). Across nodes, a state goes stale when another node commits to its aggregate without the partition's lease (a command it ran locally because its forward surely did not reach the owner): the owner drops it as soon as its tail of the partition reads that commit from the log (dropBefore), and until then the stale state costs a version conflict and a reload. A state carries the aggregate's recent requests, which must never be behind the log while the node owns the partition: a node drops the states of a partition whenever it acquires or releases it (invalidate).

Inheritors

Types

Link copied to clipboard

Caches nothing.

Functions

Link copied to clipboard
open fun dropBefore(ref: AggregateRef, version: Int): Boolean

Drops the state of ref when it is cached at a version before version, atomically with take and put: a stream of the aggregate at version is in the log, so the state is behind it. Whether it dropped one. A state taken out for a command is not in the cache and is left alone: that command's append meets the version and conflicts. Drops nothing by default: a cache that cannot drop atomically leaves its stale states to their conflicts.

Link copied to clipboard
open fun invalidate(partition: Int, partitions: Int)

Drops the states of the aggregates in partition of partitions, as me.ahoo.wow.spi.log.Partitioner.partitionOf places them: the node acquired or released the partition, so another node may have committed to them. A state taken out meanwhile is not put back by a command that runs without the partition's lease (ExecutionLease.NOT_HELD). Drops nothing by default.

Link copied to clipboard
abstract fun put(ref: AggregateRef, state: CachedState)

Caches state of ref.

Link copied to clipboard
abstract fun take(ref: AggregateRef): CachedState?

Removes and returns the state of ref, or null when none is cached.