Class AppendOnlyChunkSink
ICacheChunkSink implementation for live sessions: writes LZ4-compressed chunk bytes back-to-back to a
caller-provided Stream (typically a temp file). No headers, no section table, no trailer — chunks only.
The owning AttachSessionRuntime keeps the manifest in memory and serves chunks via offset+length lookups.
public sealed class AppendOnlyChunkSink : ICacheChunkSink, IDisposable
- Inheritance
-
AppendOnlyChunkSink
- Implements
- Inherited Members
Remarks
This sink does NOT write a trailer (SupportsTrailer returns false). The builder calls
WriteTrailer(IReadOnlyList<TickSummary>, in GlobalMetricsFixed, IReadOnlyList<SystemAggregateDuration>, IReadOnlyList<ChunkManifestEntry>, IReadOnlyDictionary<int, string>, ReadOnlySpan<byte>, in CacheHeader, IReadOnlyList<SystemTickSummary>, IReadOnlyList<QueueTickSummary>, IReadOnlyList<PostTickSummary>, IReadOnlyDictionary<ushort, string>, IReadOnlyList<SystemArchetypeTouchSummary>) only when this is true; live mode skips it. If a future feature wants to
snapshot a live session as a sealed cache file, it can build a FileCacheSink alongside this one and
stream-replay the chunks into it.
The sink is NOT thread-safe — the builder is the sole writer, on the AttachSessionRuntime's read loop thread.
Constructors
AppendOnlyChunkSink(Stream, bool)
Wrap a writable stream as a chunk sink.
public AppendOnlyChunkSink(Stream stream, bool ownsStream)
Parameters
streamStreamDestination for compressed chunk bytes. Must be writable.
ownsStreamboolWhen
true, Dispose() also disposesstream.
Exceptions
- ArgumentNullException
streamisnull.- ArgumentException
streamis not writable.
Properties
Position
The current write position in the underlying stream — equals total compressed bytes appended so far.
public long Position { get; }
Property Value
SupportsTrailer
True if this sink writes a trailer (TickSummaries / GlobalMetrics / ChunkManifest / SpanNameTable + cache header).
public bool SupportsTrailer { get; }
Property Value
Remarks
Always false — live mode keeps trailer metadata in memory and never seals a trailer.
Methods
AppendChunk(ReadOnlySpan<byte>)
LZ4-compress and append a chunk's records to the sink's underlying storage. Returns the byte offset and lengths needed to populate the matching ChunkManifestEntry.
public (long CacheOffset, uint CompressedLength, uint UncompressedLength) AppendChunk(ReadOnlySpan<byte> uncompressedRecords)
Parameters
uncompressedRecordsReadOnlySpan<byte>
Returns
Remarks
Flushes the stream after each append so a separate reader (the live chunk endpoint) can see the bytes immediately.
Exceptions
- ArgumentException
uncompressedRecordsis empty.- InvalidOperationException
LZ4 compression produced a non-positive length.
Dispose()
Flushes the stream a final time and, if this sink owns it, disposes it. Idempotent; never throws.
public void Dispose()
WriteTrailer(IReadOnlyList<TickSummary>, in GlobalMetricsFixed, IReadOnlyList<SystemAggregateDuration>, IReadOnlyList<ChunkManifestEntry>, IReadOnlyDictionary<int, string>, ReadOnlySpan<byte>, in CacheHeader, IReadOnlyList<SystemTickSummary>, IReadOnlyList<QueueTickSummary>, IReadOnlyList<PostTickSummary>, IReadOnlyDictionary<ushort, string>, IReadOnlyList<SystemArchetypeTouchSummary>)
public void WriteTrailer(IReadOnlyList<TickSummary> tickSummaries, in GlobalMetricsFixed globalMetrics, IReadOnlyList<SystemAggregateDuration> systemAggregates, IReadOnlyList<ChunkManifestEntry> chunkManifest, IReadOnlyDictionary<int, string> spanNames, ReadOnlySpan<byte> sourceMetadataBytes, in CacheHeader headerTemplate, IReadOnlyList<SystemTickSummary> systemTickSummaries, IReadOnlyList<QueueTickSummary> queueTickSummaries, IReadOnlyList<PostTickSummary> postTickSummaries, IReadOnlyDictionary<ushort, string> queueIdToName, IReadOnlyList<SystemArchetypeTouchSummary> systemArchetypeTouches)
Parameters
tickSummariesIReadOnlyList<TickSummary>globalMetricsGlobalMetricsFixedsystemAggregatesIReadOnlyList<SystemAggregateDuration>chunkManifestIReadOnlyList<ChunkManifestEntry>spanNamesIReadOnlyDictionary<int, string>sourceMetadataBytesReadOnlySpan<byte>headerTemplateCacheHeadersystemTickSummariesIReadOnlyList<SystemTickSummary>queueTickSummariesIReadOnlyList<QueueTickSummary>postTickSummariesIReadOnlyList<PostTickSummary>queueIdToNameIReadOnlyDictionary<ushort, string>systemArchetypeTouchesIReadOnlyList<SystemArchetypeTouchSummary>
Remarks
Not supported by the live sink — always throws NotSupportedException. Gate on SupportsTrailer.
Exceptions
- NotSupportedException
Always — live mode keeps trailer metadata in memory.