feat(717): Warm non-transparent redundancy, default-off (T1-T10)
OpcUa:Redundancy:Mode (Unset default = today's server exactly; None; Warm; Hot and unknown values fail start). - T1 options + validator + effective-URI check + boot banner; Warm needs the driver role. - T2 metadata in OnNodeManagerStartedAsync: Warm -> NonTransparentRedundancyType, read-only ServerUriArray [self, peers], RedundancySupport=Warm, boot ServiceLevel 1; None -> RedundancySupport=None and the SDK's orphan i=11314 deleted; Unset untouched. - T3 RedundancyStateChanged.Revision (up-number, incarnation tick, sequence); subscribers drop older revisions under Warm (OpcUaPublishActor, DriverHostActor); unrevisioned never makes a node Active. - T4 WarmRoleAuthority + ComputeWarm bands (Standby 90/50, Active 250/200/100), PromoteWhilePrimaryUnreachable. - T5 IStandbyProjection + DeferredStandbyProjection; OpcUaPublishActor runs promotion/demotion in the spec 4.7 order (Active level last and retried; Standby level first, data degraded regardless). - T6 EquipmentVariableState read projection (BadOutOfService/null); Warm Standby refuses writes BadInvalidState. - T7 D4 mechanism adopted after T0: ordinary-tag marker on MonitoredItemNotification.Message validated by (ClientHandle, DataValue); first-delivery decision keyed by (SubscriptionId, SequenceNumber); the SDK's cached copy is never mutated. - T8 queue current/BadOutOfService to live ordinary-tag items ignoring filters. - T9 alarm stamp/deliver split (suppressed on Standby), Part 9 methods refused on Standby, promotion refresh via ISubscription.ConditionRefresh2Async on every live event item. - T10 deploy-time RedundancyMode cross-check + six instruments. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -37,6 +37,11 @@ public sealed class RedundancyStateActor : ReceiveActor, IWithTimers
|
||||
private readonly Action<object>? _broadcastOverride;
|
||||
private readonly TimeSpan _heartbeatInterval;
|
||||
private bool _dirty;
|
||||
/// <summary>Gitea #717 spec §4.2: <c>Environment.TickCount64</c> at <see cref="PreStart"/>, ordering a singleton
|
||||
/// restarted in the same process.</summary>
|
||||
private long _incarnationTick;
|
||||
/// <summary>Gitea #717 spec §4.2: incremented on every publish, heartbeats included.</summary>
|
||||
private long _sequence;
|
||||
|
||||
/// <summary>Gets the timer scheduler for this actor.</summary>
|
||||
public ITimerScheduler Timers { get; set; } = null!;
|
||||
@@ -78,6 +83,7 @@ public sealed class RedundancyStateActor : ReceiveActor, IWithTimers
|
||||
/// <inheritdoc />
|
||||
protected override void PreStart()
|
||||
{
|
||||
_incarnationTick = NextIncarnationTick();
|
||||
_cluster.Subscribe(
|
||||
Self,
|
||||
ClusterEvent.InitialStateAsEvents,
|
||||
@@ -107,12 +113,63 @@ public sealed class RedundancyStateActor : ReceiveActor, IWithTimers
|
||||
_dirty = false;
|
||||
|
||||
var snapshot = BuildSnapshot();
|
||||
var msg = new RedundancyStateChanged(snapshot, CorrelationId.NewId());
|
||||
var msg = new RedundancyStateChanged(snapshot, CorrelationId.NewId(), NextRevision());
|
||||
if (_broadcastOverride is not null) _broadcastOverride(msg);
|
||||
else DistributedPubSub.Get(Context.System).Mediator.Tell(new Publish(Topic, msg));
|
||||
_log.Debug("Published RedundancyStateChanged with {Count} nodes", snapshot.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The ordered revision of the next publish (Gitea #717 spec §4.2): the up-number of the member hosting this
|
||||
/// singleton, this incarnation's start tick, and a per-publish sequence. Subscribers drop anything not newer,
|
||||
/// so a late heartbeat from an old incarnation can no longer overwrite the new incarnation's snapshot.
|
||||
/// </summary>
|
||||
private SnapshotRevision NextRevision()
|
||||
{
|
||||
long upNumber;
|
||||
try
|
||||
{
|
||||
upNumber = ReadUpNumber(_cluster.SelfMember)
|
||||
?? throw new InvalidOperationException("Akka.Cluster Member.UpNumber is not readable on this Akka version");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Not expected on a running singleton; an unordered 0 can never outrank a real publisher.
|
||||
_log.Debug(ex, "RedundancyState: SelfMember up-number unavailable; publishing revision up-number 0");
|
||||
upNumber = 0;
|
||||
}
|
||||
|
||||
return new SnapshotRevision(upNumber, _incarnationTick, ++_sequence);
|
||||
}
|
||||
|
||||
private static long _lastIncarnationTick;
|
||||
|
||||
/// <summary><c>Environment.TickCount64</c>, made strictly increasing within the process so a singleton restarted
|
||||
/// inside one tick still outranks its predecessor (whose sequence may be ahead of the new one's).</summary>
|
||||
/// <returns>The incarnation tick.</returns>
|
||||
public static long NextIncarnationTick()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var last = Interlocked.Read(ref _lastIncarnationTick);
|
||||
var next = Math.Max(Environment.TickCount64, last + 1);
|
||||
if (Interlocked.CompareExchange(ref _lastIncarnationTick, next, last) == last) return next;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly System.Reflection.PropertyInfo? UpNumberProperty = typeof(Member).GetProperty(
|
||||
"UpNumber", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
|
||||
|
||||
/// <summary>
|
||||
/// A member's up-number — the order in which members became Up, the basis of <c>Member.IsOlderThan</c> and of
|
||||
/// singleton placement. Akka.NET 1.5 keeps the property <c>internal</c>, so it is read by reflection; the
|
||||
/// <c>SnapshotRevisionTests</c> pin that it resolves, so an Akka upgrade that renames it fails loudly.
|
||||
/// </summary>
|
||||
/// <param name="member">The member.</param>
|
||||
/// <returns>The up-number, or null if the property is unavailable.</returns>
|
||||
public static int? ReadUpNumber(Member member) =>
|
||||
UpNumberProperty?.GetValue(member) is int value ? value : null;
|
||||
|
||||
/// <summary>The cluster role that marks a node as carrying the driver runtime.</summary>
|
||||
public const string DriverRole = RoleParser.Driver;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user