fix(grpc-data): #1057 an item the origin's delivery index cannot hold is refused LimitExceeded in its ack instead of stopping the session after it
Registration in the session's delivery index happened after the Open/Add acknowledgement had been queued as Good, so a registration failure could only Stop() the whole session (every sibling item went with it). Items now register at admission, before the ack is built; a refusal is the item's own LimitExceeded. Waiting-for-initial-data items register at admission too (the index is keyed by source), so their later recovery can no longer reset the stream for capacity. SubscriptionSessionLimits.DeliveryIndexCapacity is a test-only override of the index size.
This commit is contained in:
@@ -213,8 +213,8 @@ internal sealed partial class DataSubscriptionSession : IDataSubscriptionTranspo
|
||||
// #994 (R-2): the delivery index must hold every item (and every distinct source) the stream may admit. It was sized
|
||||
// from the frame window alone (MaxPendingFrames × 16 = 1024 by default), so the 1025th item — inside the advertised
|
||||
// MaxMonitoredItems — failed registration AFTER its acknowledgement and stopped the whole session.
|
||||
var schedulerCapacity = checked(Math.Max(limits.MaxPendingFrames * 16, services.SubscriptionLimits.MaxMonitoredItems) +
|
||||
limits.MaxPendingFrames * 16);
|
||||
var schedulerCapacity = limits.DeliveryIndexCapacity ?? checked(Math.Max(limits.MaxPendingFrames * 16,
|
||||
services.SubscriptionLimits.MaxMonitoredItems) + limits.MaxPendingFrames * 16);
|
||||
_scheduler = new DeliveryScheduler(schedulerCapacity, schedulerCapacity);
|
||||
var preOpen = limits.PreOpenTimeout ?? TimeSpan.FromSeconds(10);
|
||||
_preOpen = services.Clock.CreateTimer(static state => ((DataSubscriptionSession)state!).Stop(), this,
|
||||
@@ -515,6 +515,17 @@ internal sealed partial class DataSubscriptionSession : IDataSubscriptionTranspo
|
||||
{ itemReservation!.Dispose(); result.Lease.Dispose(); acks.Add(new(request.ClientItemId, DataItemStatus.LimitExceeded, null, null, null)); continue; }
|
||||
var item = new Item(request.ClientItemId, handle, view, result.RevisedSettings, result.Lease, itemReservation!);
|
||||
if (_services.SubscriptionHub.TryGetCurrentTicket(view.Source, out var ticket)) item.Ticket = ticket;
|
||||
// #1057: register in the delivery index BEFORE the acknowledgement is built, so an item it cannot hold is refused
|
||||
// LimitExceeded in its own ack. Registering after the ack had been queued as Good could only stop the whole session.
|
||||
// No tick runs while this command does (one worker), so nothing considers the item before its snapshot group exists.
|
||||
// An item still waiting for its first value registers now too (the index is keyed by source, not ticket), so its
|
||||
// later recovery cannot fail for capacity after it was acknowledged either; until then it has no ticket to read.
|
||||
if (!_scheduler.TryRegister(view.Source, checked((long)handle.Handle)))
|
||||
{
|
||||
lock (_gate) _handles!.Remove(handle);
|
||||
item.Dispose();
|
||||
acks.Add(new(request.ClientItemId, DataItemStatus.LimitExceeded, null, null, null)); continue;
|
||||
}
|
||||
lock (_gate) { _items.Add(handle.Handle, item); _itemsByClient.Add(item.ClientItemId, item); }
|
||||
if (item.Ticket is null) lock (_gate) item.WaitingNode = _waiting.AddLast(handle.Handle);
|
||||
admitted.Add(item);
|
||||
@@ -562,7 +573,6 @@ internal sealed partial class DataSubscriptionSession : IDataSubscriptionTranspo
|
||||
foreach (var item in admitted)
|
||||
{
|
||||
if (item.Ticket is not { } ticket || !snapshot.Items.TryGetValue(ticket, out var captured)) continue;
|
||||
if (!_scheduler.TryRegister(item.View.Source, checked((long)item.Handle.Handle))) { Stop(); return; }
|
||||
if (captured.Sample is not null) item.LastConsidered = captured.Sample.Version;
|
||||
}
|
||||
_snapshotJobs.AddLast(new SnapshotJob(snapshot, admission, group, admitted, marks));
|
||||
@@ -959,8 +969,7 @@ internal sealed partial class DataSubscriptionSession : IDataSubscriptionTranspo
|
||||
{
|
||||
if (!_items.TryGetValue(item.Handle.Handle, out var current) || !ReferenceEquals(current, item))
|
||||
{ snapshot!.Dispose(); interest!.Dispose(); admission!.Dispose(); return true; }
|
||||
if (!_scheduler.TryRegister(item.View.Source, checked((long)item.Handle.Handle)))
|
||||
{ snapshot!.Dispose(); interest!.Dispose(); admission!.Dispose(); CloseWithReset("Interest capacity exhausted."); return true; }
|
||||
// #1057: the item has been in the delivery index since its admission.
|
||||
_snapshots.Add(snapshot!); _snapshotAdmissions.Add(admission!);
|
||||
group = new InterestGroup(interest!) { Count = 1 };
|
||||
group.Sources.Add(item.View.Source, 1);
|
||||
|
||||
@@ -17,9 +17,13 @@ internal sealed record SubscriptionDemandResult(DataItemStatus Status, DataSubsc
|
||||
long Boundary, IDisposable? Lease);
|
||||
|
||||
/// <param name="MaxConditionItems">A2 review S2: the most root-scoped condition items one stream may hold.</param>
|
||||
/// <param name="DeliveryIndexCapacity">
|
||||
/// #1057: overrides the delivery index's interest/source capacity (null = sized from the frame window and the advertised
|
||||
/// MaxMonitoredItems). Only tests set it, to reach the registration-refusal path the default sizing makes unreachable.
|
||||
/// </param>
|
||||
internal sealed record SubscriptionSessionLimits(int MaxCommands, int MaxPendingFrames, long MaxPendingBytes,
|
||||
TimeSpan MaxSessionLifetime, TimeSpan? PreOpenTimeout = null,
|
||||
int MaxConditionItems = SubscriptionSessionLimits.DefaultMaxConditionItems)
|
||||
int MaxConditionItems = SubscriptionSessionLimits.DefaultMaxConditionItems, int? DeliveryIndexCapacity = null)
|
||||
{
|
||||
/// <summary>The default per-stream condition-item cap (A3 opens one item per condition-bearing mapping).</summary>
|
||||
internal const int DefaultMaxConditionItems = 32;
|
||||
@@ -27,6 +31,7 @@ internal sealed record SubscriptionSessionLimits(int MaxCommands, int MaxPending
|
||||
internal void Validate()
|
||||
{
|
||||
if (MaxCommands <= 0 || MaxPendingFrames <= 0 || MaxPendingBytes <= 0 || MaxSessionLifetime <= TimeSpan.Zero || MaxConditionItems <= 0 ||
|
||||
DeliveryIndexCapacity is <= 0 ||
|
||||
PreOpenTimeout is { } timeout && (timeout <= TimeSpan.Zero || timeout > TimeSpan.FromMilliseconds(uint.MaxValue - 1)))
|
||||
throw new ArgumentOutOfRangeException(nameof(MaxCommands));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user