fix(site-runtime): static write refreshes quality/timestamp; redeploy reset gates native rehydration and the first flush (SRT-11, SRT-12, WP3 task 3.10)
This commit is contained in:
@@ -339,6 +339,16 @@ public class InstanceActor : ReceiveActor
|
||||
// Defaults to 100 ms, mirroring NativeAlarmActor's persistFlushInterval (P4).
|
||||
_staticOverrideFlushInterval = staticOverrideFlushInterval ?? TimeSpan.FromMilliseconds(100);
|
||||
_staticStateResetGate = staticStateResetGate;
|
||||
// SRT-12: the first static-override flush is ordered AFTER the redeploy reset. A value
|
||||
// script on the new instance can write a static attribute within the first ~100 ms; its
|
||||
// flush ran on its own connection with no ordering against the (slower, lock-contended)
|
||||
// clear, so the clear could land afterwards and delete it — in memory but not on disk,
|
||||
// silently reverted by the next restart. The reset's own fault is ignored here (the
|
||||
// deploy fails on it through its persistence join).
|
||||
if (staticStateResetGate != null)
|
||||
_staticOverridePersistTail = staticStateResetGate.ContinueWith(
|
||||
static _ => { }, CancellationToken.None,
|
||||
TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
|
||||
|
||||
_configuration = configuration;
|
||||
|
||||
@@ -780,6 +790,15 @@ public class InstanceActor : ReceiveActor
|
||||
if (!_overridesLoaded)
|
||||
_staticWritesBeforeOverrideLoad.Add(command.AttributeName);
|
||||
|
||||
// SRT-11: a successful write refreshes the stored quality and timestamp with the value.
|
||||
// A List attribute loaded Bad (malformed default/override) used to stay Bad for the
|
||||
// actor's lifetime — GetAttribute, the Debug View snapshot and a requireGoodQuality
|
||||
// waiter all saw Bad while the stream said Good — and a static attribute had no stored
|
||||
// timestamp at all, so every snapshot stamped it "now".
|
||||
var writtenAt = DateTimeOffset.UtcNow;
|
||||
_attributeQualities[command.AttributeName] = "Good";
|
||||
_attributeTimestamps[command.AttributeName] = writtenAt;
|
||||
|
||||
// Publish attribute change to stream and notify children
|
||||
var changed = new AttributeValueChanged(
|
||||
_instanceUniqueName,
|
||||
@@ -787,7 +806,7 @@ public class InstanceActor : ReceiveActor
|
||||
command.AttributeName,
|
||||
command.Value,
|
||||
"Good",
|
||||
DateTimeOffset.UtcNow,
|
||||
writtenAt,
|
||||
// (ParentExecutionId tag-cascade): carry the writing
|
||||
// execution's id onto the change so a child Alarm Actor this write
|
||||
// trips can chain its on-trigger script run under the writer. Null for
|
||||
@@ -1088,6 +1107,22 @@ public class InstanceActor : ReceiveActor
|
||||
/// Routes script call requests to the appropriate Script Actor.
|
||||
/// Uses Ask pattern.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// SRT-12: the native-alarm rehydration read, chained behind <see cref="_staticStateResetGate"/>
|
||||
/// when this start is a (re)deploy; null (the actor reads directly) on every other start.
|
||||
/// </summary>
|
||||
private Task<IReadOnlyList<NativeAlarmRow>>? GatedNativeAlarmRead(string sourceCanonicalName)
|
||||
{
|
||||
if (_staticStateResetGate == null)
|
||||
return null;
|
||||
var storage = _storage;
|
||||
var instanceName = _instanceUniqueName;
|
||||
return _staticStateResetGate
|
||||
.ContinueWith(_ => storage.GetNativeAlarmsAsync(instanceName, sourceCanonicalName),
|
||||
CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default)
|
||||
.Unwrap();
|
||||
}
|
||||
|
||||
private void HandleGetScriptExecutionTimeout(GetScriptExecutionTimeout request)
|
||||
{
|
||||
var script = _configuration?.Scripts.FirstOrDefault(s => s.CanonicalName == request.ScriptName);
|
||||
@@ -2329,6 +2364,11 @@ public class InstanceActor : ReceiveActor
|
||||
}
|
||||
|
||||
var nativeKind = ResolveNativeKind(nativeSource.ConnectionName);
|
||||
// SRT-12: on a (re)deploy the native-alarm rehydration read is chained behind the
|
||||
// reset gate too — not only the override load — so the successor can only observe the
|
||||
// CLEARED native_alarm_state, never re-emit the predecessor's conditions (stale alarms
|
||||
// from an old binding that no snapshot would ever reconcile if the source is down).
|
||||
var rehydrationRead = GatedNativeAlarmRead(nativeSource.CanonicalName);
|
||||
var props = Props.Create(() => new NativeAlarmActor(
|
||||
nativeSource,
|
||||
_instanceUniqueName,
|
||||
@@ -2338,7 +2378,9 @@ public class InstanceActor : ReceiveActor
|
||||
_options,
|
||||
_logger,
|
||||
nativeKind,
|
||||
_serviceProvider));
|
||||
_serviceProvider,
|
||||
null,
|
||||
rehydrationRead));
|
||||
|
||||
var actorRef = TryCreateChild(
|
||||
props, $"native-alarm-{nativeSource.CanonicalName}", "Native alarm source", nativeSource.CanonicalName);
|
||||
|
||||
Reference in New Issue
Block a user