fix(grpc-data): A1 review round 2 F4 — a Galaxy sentinel signals only a stream opened under the live subscription
The feed raises a new IGalaxyAlarmFeed.StreamOpened (default no-op accessors) before each stream's first message; GalaxyDriver records the live subscription then, and its sentinel signals only if that is still the live one — so refs whose snapshot entries arrived before (or without) the subscription are never signalled. The handle is now added before the feed starts, so the first stream opens under it.
This commit is contained in:
@@ -165,6 +165,10 @@ public sealed class GalaxyDriver
|
||||
// grpc-data A1: the alarm refs (RawPaths) of the live subscription — what a sentinel signal covers. Under
|
||||
// _alarmHandlersLock, replaced with the handle.
|
||||
private IReadOnlyList<string> _alarmSubscriptionRefs = Array.Empty<string>();
|
||||
// A1 review round 2 F4: the live alarm subscription when the feed's current stream opened (guarded by
|
||||
// _alarmHandlersLock). A sentinel signals only if it is still the live one — entries delivered before a later
|
||||
// subscription (or while none was live) were not delivered under it.
|
||||
private GalaxyAlarmSubscriptionHandle? _streamOpenedUnder;
|
||||
|
||||
// Production runtime owned by InitializeAsync (BuildProductionRuntimeAsync). The
|
||||
// driver builds these when it opens a real gw session; tests bypass them by
|
||||
@@ -1083,6 +1087,7 @@ public sealed class GalaxyDriver
|
||||
{
|
||||
alarmFeed.OnAlarmTransition -= OnAlarmFeedTransition;
|
||||
alarmFeed.SnapshotDelivered -= OnAlarmFeedSnapshotDelivered;
|
||||
alarmFeed.StreamOpened -= OnAlarmFeedStreamOpened;
|
||||
_alarmFeedWired = false;
|
||||
}
|
||||
if (releaseFeed) _alarmFeed = null;
|
||||
@@ -2740,6 +2745,7 @@ public sealed class GalaxyDriver
|
||||
if (_alarmFeedWired) return;
|
||||
_alarmFeed.OnAlarmTransition += OnAlarmFeedTransition;
|
||||
_alarmFeed.SnapshotDelivered += OnAlarmFeedSnapshotDelivered;
|
||||
_alarmFeed.StreamOpened += OnAlarmFeedStreamOpened;
|
||||
_alarmFeed.Start();
|
||||
_alarmFeedWired = true;
|
||||
}
|
||||
@@ -2757,7 +2763,7 @@ public sealed class GalaxyDriver
|
||||
// StreamAlarms feed, and the server filters by source node before raising Part 9
|
||||
// conditions. The subscription handle is a sentinel the server uses for
|
||||
// symmetric Unsubscribe. Same shape AbCip uses.
|
||||
EnsureAlarmFeedStarted();
|
||||
// A1 review round 2 F4: the handle is live BEFORE the feed starts, so the first stream opens under it.
|
||||
var handle = new GalaxyAlarmSubscriptionHandle(Guid.NewGuid().ToString("N"));
|
||||
lock (_alarmHandlersLock)
|
||||
{
|
||||
@@ -2773,6 +2779,16 @@ public sealed class GalaxyDriver
|
||||
_alarmSubscriptions.Add(handle);
|
||||
_alarmSubscriptionRefs = sourceNodeIds.ToArray();
|
||||
}
|
||||
try { EnsureAlarmFeedStarted(); }
|
||||
catch
|
||||
{
|
||||
lock (_alarmHandlersLock)
|
||||
{
|
||||
_alarmSubscriptions.Remove(handle);
|
||||
if (_alarmSubscriptions.Count == 0) _alarmSubscriptionRefs = Array.Empty<string>();
|
||||
}
|
||||
throw;
|
||||
}
|
||||
return Task.FromResult<IAlarmSubscriptionHandle>(handle);
|
||||
}
|
||||
|
||||
@@ -3020,6 +3036,12 @@ public sealed class GalaxyDriver
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A1 review round 2 F4: a feed stream (re)opened — record the subscription its snapshot is delivered under.</summary>
|
||||
private void OnAlarmFeedStreamOpened(object? sender, EventArgs e)
|
||||
{
|
||||
lock (_alarmHandlersLock) _streamOpenedUnder = _alarmSubscriptions.Count > 0 ? _alarmSubscriptions[0] : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// grpc-data A1 (§5.1, Galaxy row): the feed's <c>snapshot_complete</c> sentinel, on the feed thread after
|
||||
/// the snapshot entries were bridged. Signals the live subscription's refs; nothing while unsubscribed (G5).
|
||||
@@ -3030,6 +3052,12 @@ public sealed class GalaxyDriver
|
||||
lock (_alarmHandlersLock)
|
||||
{
|
||||
if (_alarmSubscriptions.Count == 0) return;
|
||||
// A1 review round 2 F4: only a stream whose whole snapshot was delivered under THIS subscription.
|
||||
if (!ReferenceEquals(_alarmSubscriptions[0], _streamOpenedUnder))
|
||||
{
|
||||
_logger.LogDebug("GalaxyDriver alarm sentinel for a stream opened under an earlier (or no) subscription — not signalled; the next stream's sentinel will.");
|
||||
return;
|
||||
}
|
||||
refs = _alarmSubscriptionRefs;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,9 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? SnapshotDelivered;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? StreamOpened;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="GatewayGalaxyAlarmFeed"/> class.</summary>
|
||||
/// <param name="streamFactory">A factory delegate that opens the alarm stream.</param>
|
||||
/// <param name="logger">An optional logger for diagnostic output.</param>
|
||||
@@ -127,6 +130,10 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
AlarmFilterPrefix = _alarmFilterPrefix,
|
||||
};
|
||||
|
||||
// A1 review round 2 F4: before any message of this stream, on this (the dispatch) thread.
|
||||
try { StreamOpened?.Invoke(this, EventArgs.Empty); }
|
||||
catch (Exception ex) { _logger.LogWarning(ex, "Galaxy alarm feed StreamOpened handler threw — continuing."); }
|
||||
|
||||
await foreach (var message in _streamFactory(request, ct)
|
||||
.WithCancellation(ct).ConfigureAwait(false))
|
||||
{
|
||||
|
||||
@@ -46,4 +46,11 @@ internal interface IGalaxyAlarmFeed : IAsyncDisposable
|
||||
/// The default accessors make it a no-op for feeds with no snapshot phase.
|
||||
/// </summary>
|
||||
event EventHandler? SnapshotDelivered { add { } remove { } }
|
||||
|
||||
/// <summary>
|
||||
/// Raised synchronously on the feed thread each time a stream is (re)opened, before any of its messages (A1 review
|
||||
/// round 2 F4): the driver records which alarm subscription the stream's snapshot is delivered under, and its
|
||||
/// sentinel signals only if that subscription is still the live one. The default accessors make it a no-op.
|
||||
/// </summary>
|
||||
event EventHandler? StreamOpened { add { } remove { } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user