Class PointInTimeAccessor
Thread-safe, lightweight snapshot accessor for parallel entity access. Constructed once (empty), then Attach(DatabaseEngine, int)ed before each parallel system dispatch to obtain a fresh TSN. Per-worker EntityAccessor instances are stored in a flat array indexed by worker ID — zero per-entity dictionary overhead.
Supports reading all storage modes (Versioned via MVCC chain walk, SingleVersion/Transient direct). Supports writing SingleVersion and Transient components. Throws on Versioned writes. Does not support Spawn, Destroy, Commit, or Rollback.
Reuse pattern: A single PTA is constructed once and reused across all non-Versioned parallel systems within a tick and across ticks. Call Attach(DatabaseEngine, int) before each system dispatch — it allocates a fresh TSN and resets per-worker EntityAccessors while preserving ChunkAccessor page caches (zero allocation after first-tick warmup).
public sealed class PointInTimeAccessor : IDisposable
- Inheritance
-
PointInTimeAccessor
- Implements
- Inherited Members
Constructors
PointInTimeAccessor()
Creates an empty PointInTimeAccessor. Call Attach(DatabaseEngine, int) before use.
public PointInTimeAccessor()
Properties
IsAttached
Whether this accessor has been attached to a DatabaseEngine and has a valid TSN.
public bool IsAttached { get; }
Property Value
TSN
The frozen MVCC snapshot timestamp. All workers see the same snapshot.
public long TSN { get; }
Property Value
Methods
AdvanceSnapshot()
Advance to a new MVCC snapshot. Equivalent to Attach(DatabaseEngine, int) but reuses the existing engine and worker count.
public void AdvanceSnapshot()
Attach(DatabaseEngine, int)
Attach (or re-attach) this accessor with a fresh TSN. On first call: stores the engine reference and worker count, allocates the accessor array and a TSN. On subsequent calls: allocates a fresh TSN and resets all existing per-worker EntityAccessors via Typhon.Engine.EntityAccessor.ResetForNewSnapshot(System.Int64), preserving ChunkAccessor page caches.
Must be called from a single thread (the prepare phase), NOT concurrently with worker access.
public void Attach(DatabaseEngine dbe, int workerCount)
Parameters
dbeDatabaseEngineworkerCountint
Create(DatabaseEngine, int)
Creates a PointInTimeAccessor with a frozen MVCC snapshot at the current TSN.
public static PointInTimeAccessor Create(DatabaseEngine dbe, int workerCount = 1)
Parameters
dbeDatabaseEngineworkerCountint
Returns
Dispose()
Detaches this accessor and disposes every per-worker EntityAccessor it owns; idempotent.
public void Dispose()
Enter(int)
Leases the given worker's EntityAccessor to the calling thread: pins the thread's epoch for the lease's length and hands out the
worker's accessor, created on first use and kept warm across leases (its caches, not a pin). Read only through Accessor,
inside the lease: using var lease = pta.Enter(workerId);. The runtime takes one per chunk.
public PointInTimeAccessor.WorkerLease Enter(int workerId)
Parameters
workerIdint
Returns
Remarks
The pin is the lease's, never the accessor's (EP-04, #1532): held from the first use of a worker accessor until its thread died, it froze the page
cache's eviction floor at the oldest worker's pin, and a tick that stalled on a page never saw one freed. A lease is a ref struct, so it
cannot be stored, captured or carried to another thread: its pin and its unpin run on one thread. A worker accessor used with no lease open throws.
FlushWorker(int)
Flushes the given worker's EntityAccessor: commits its dirty chunk state, releases its dirty marks, and lets go of every page its windows hold (its component accessors', its entity-map cache's, its cluster cache's) — the accessor stays usable and refills on its next read. The runtime calls it once per system, for every worker, from whichever thread completed the system, with no lease open. Call it with no lease open, or from the thread holding the worker's lease. It moves no epoch: the worker holds none outside a lease.
public void FlushWorker(int workerId)
Parameters
workerIdint