perf(grpc-data): A2 review N3 — a caught-up hub reader skips the partition scan

ConditionStateHub.Read scanned the whole partition under its gate on every tick even when the cursor
was at the tail. The partition now records its tail version; a reader at or past it returns empty.
This commit is contained in:
Joseph Doherty
2026-11-24 14:56:49 -05:00
parent 69014cc4f8
commit 7694eb67b2
@@ -49,6 +49,8 @@ public sealed class ConditionStateHub : IConditionStateSink
public readonly object Gate = new();
public readonly Queue<ConditionStateRecord> Buffer = new();
public long Floor;
/// <summary>The version of the newest buffered record (A2 review N3: a caught-up reader skips the scan).</summary>
public long Tail;
}
private readonly Partition[] _partitions;
@@ -111,6 +113,7 @@ public sealed class ConditionStateHub : IConditionStateSink
}
p.Buffer.Enqueue(record with { Version = version });
p.Tail = version;
return version;
}
}
@@ -154,6 +157,8 @@ public sealed class ConditionStateHub : IConditionStateSink
lock (p.Gate)
{
if (afterVersion < p.Floor) return new ConditionDeltaRead(true, p.Floor, []);
// A2 review N3: a reader at or past the tail has nothing to read — never scan the partition under its gate.
if (afterVersion >= p.Tail) return new ConditionDeltaRead(false, p.Floor, []);
var records = new List<ConditionStateRecord>();
foreach (var r in p.Buffer)
{