fix(grpc-data): H4 review 4 — an origin chunk holding its page cursor is one open continuation, not two
This commit is contained in:
@@ -58,6 +58,9 @@ public sealed class OriginHistoryCursors
|
||||
/// <summary>Releases a token (idempotent).</summary>
|
||||
public bool Release(byte[]? token) => Store.Release(token);
|
||||
|
||||
/// <summary>Whether a token names a live page cursor (diagnostics).</summary>
|
||||
public bool Contains(byte[]? token) => Store.Contains(token);
|
||||
|
||||
/// <summary>Drops every record (the channel closed).</summary>
|
||||
public void Clear() => Store.Clear();
|
||||
}
|
||||
|
||||
@@ -185,6 +185,17 @@ internal sealed class PeerHistoryContinuationStore
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Whether <paramref name="token"/> names a live (unexpired) record (diagnostics: de-duplicating open continuations).</summary>
|
||||
public bool Contains(byte[]? token)
|
||||
{
|
||||
if (token is not { Length: TokenLength }) return false;
|
||||
lock (_gate)
|
||||
{
|
||||
Sweep(_clock.GetTimestamp());
|
||||
return _entries.ContainsKey(new Guid(token));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Drops a record without reading it (<c>release_continuations</c>). Idempotent.</summary>
|
||||
/// <param name="token">The token to release.</param>
|
||||
/// <returns>Whether a live record was dropped.</returns>
|
||||
|
||||
@@ -44,6 +44,27 @@ internal sealed class OriginHistorySession
|
||||
get { lock (_gate) { Sweep(_clock.GetTimestamp()); return _chunks.Count; } }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// H4 review: open continuations of this session, each counted once — a chunk that still holds its page cursor (a
|
||||
/// deferred node, or a remainder that ends with a continuation) is one open continuation, not two.
|
||||
/// </summary>
|
||||
public int OpenContinuations
|
||||
{
|
||||
get
|
||||
{
|
||||
byte[]?[] behindChunks;
|
||||
int chunks;
|
||||
lock (_gate)
|
||||
{
|
||||
Sweep(_clock.GetTimestamp());
|
||||
chunks = _chunks.Count;
|
||||
behindChunks = _chunks.Values.Select(x => x.Continuation).ToArray();
|
||||
}
|
||||
var shared = behindChunks.Count(token => token is not null && Cursors.Contains(token));
|
||||
return chunks + Cursors.Count - shared;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A stored part of one node's answer. <see cref="Deferred"/> = the node was not read yet because the response budget
|
||||
/// was spent: resuming reads it then, from <see cref="Continuation"/> (its original page token, or null = fresh).
|
||||
@@ -194,14 +215,14 @@ internal sealed class OriginHistorySessions(TimeProvider clock, int maxSessions
|
||||
/// <summary>Live sessions (diagnostics/tests).</summary>
|
||||
public int Count { get { lock (_gate) return _sessions.Count; } }
|
||||
|
||||
/// <summary>Open page cursors plus chunk remainders across every session (diagnostics/tests).</summary>
|
||||
/// <summary>Open continuations across every session, each once (a chunk holding its page cursor counts once).</summary>
|
||||
public int OpenContinuations
|
||||
{
|
||||
get
|
||||
{
|
||||
OriginHistorySession[] sessions;
|
||||
lock (_gate) sessions = _sessions.Values.Select(x => x.Session).ToArray();
|
||||
return sessions.Sum(x => x.Cursors.Count + x.ChunkCount);
|
||||
return sessions.Sum(x => x.OpenContinuations);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user