fix(controlplane): close a lost dispatch from the in-flight check; guard terminal rows; blob-free status writes
I7: a Dispatching row committed after the coordinator's PreStart whose Tell never arrived had no owner and refused every later deploy. The in-flight check (now fully off the admin singleton's thread, serialised by the actor-local compose flag alone) closes a Dispatching row with zero NodeDeploymentState rows that is past the apply deadline as TimedOut (optimistic on RowVersion) and proceeds. HandleDispatch ignores a dispatch for a Sealed/PartiallyFailed/TimedOut row, so a late or duplicated dispatch cannot flip it back. Coordinator status/reason writes attach a key+RowVersion stub instead of loading the multi-MB ArtifactBlob; proven on the real SQL Server (blob untouched, seal lands). Refs #733 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
+70
-14
@@ -234,6 +234,26 @@ public sealed class ConfigPublishCoordinator : ReceiveActor, IWithTimers
|
||||
|
||||
private void HandleDispatch(DispatchDeployment msg)
|
||||
{
|
||||
// Terminal-state guard (fix round 1): a late or re-delivered dispatch for a row that is already
|
||||
// Sealed / PartiallyFailed / TimedOut — e.g. one AdminOps closed as a lost dispatch while this message
|
||||
// was still queued — must never flip it back to AwaitingApplyAcks or seed an expected set for it.
|
||||
using (var check = _dbFactory.CreateDbContext())
|
||||
{
|
||||
var status = check.Deployments
|
||||
.AsNoTracking()
|
||||
.Where(d => d.DeploymentId == msg.DeploymentId.Value)
|
||||
.Select(d => (DeploymentStatus?)d.Status)
|
||||
.FirstOrDefault();
|
||||
if (status is DeploymentStatus.Sealed or DeploymentStatus.PartiallyFailed or DeploymentStatus.TimedOut)
|
||||
{
|
||||
_log.Warning(
|
||||
"Ignoring DispatchDeployment {Id}: the deployment is already {Status} (a late or duplicated dispatch)",
|
||||
msg.DeploymentId, status);
|
||||
if (_current == msg.DeploymentId) ResetForNext();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_current = msg.DeploymentId;
|
||||
_acks.Clear();
|
||||
_degraded.Clear();
|
||||
@@ -371,11 +391,9 @@ public sealed class ConfigPublishCoordinator : ReceiveActor, IWithTimers
|
||||
// same as clean, though: the deployment's reason names the degraded nodes (per-node detail is on
|
||||
// each NodeDeploymentState row) and the seal logs at Warning.
|
||||
var nodes = _degraded.Select(n => n.Value).Order(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
var d = db.Deployments.FirstOrDefault(x => x.DeploymentId == _current.Value.Value);
|
||||
if (d is not null)
|
||||
d.FailureReason = Truncate(
|
||||
$"Sealed with a degraded address-space apply on {nodes.Count} node(s): {string.Join(", ", nodes)}. " +
|
||||
"See each node's NodeDeploymentState.FailureReason; re-deploying the same revision re-applies it.");
|
||||
SetFailureReason(db, Truncate(
|
||||
$"Sealed with a degraded address-space apply on {nodes.Count} node(s): {string.Join(", ", nodes)}. " +
|
||||
"See each node's NodeDeploymentState.FailureReason; re-deploying the same revision re-applies it."));
|
||||
db.SaveChanges();
|
||||
_log.Warning(
|
||||
"Deployment {Id} sealed DEGRADED (acks={Count}) — the address-space apply was degraded on: {Nodes}",
|
||||
@@ -420,11 +438,9 @@ public sealed class ConfigPublishCoordinator : ReceiveActor, IWithTimers
|
||||
UpdateDeploymentStatus(db, _current.Value, DeploymentStatus.TimedOut);
|
||||
if (_expectedAcks.Count == 0)
|
||||
{
|
||||
var d = db.Deployments.FirstOrDefault(x => x.DeploymentId == _current.Value.Value);
|
||||
if (d is not null)
|
||||
d.FailureReason = Truncate(
|
||||
"Dispatch was lost before any node was expected to ack (coordinator restart or singleton " +
|
||||
"hand-over mid-dispatch) and the apply deadline has passed. Redeploy.");
|
||||
SetFailureReason(db, Truncate(
|
||||
"Dispatch was lost before any node was expected to ack (coordinator restart or singleton " +
|
||||
"hand-over mid-dispatch) and the apply deadline has passed. Redeploy."));
|
||||
db.SaveChanges();
|
||||
_log.Warning(
|
||||
"Deployment {Id} timed out with NO expected-ack rows: the dispatch was lost before any node was " +
|
||||
@@ -459,13 +475,53 @@ public sealed class ConfigPublishCoordinator : ReceiveActor, IWithTimers
|
||||
|
||||
public sealed record DeadlineElapsed(DeploymentId DeploymentId);
|
||||
|
||||
/// <summary>
|
||||
/// Stages a status change WITHOUT materialising the row: the row carries the whole <c>ArtifactBlob</c>
|
||||
/// (varbinary(max), multi-MB on a real fleet), which no status transition reads (fix round 1). A stub
|
||||
/// carrying only the key and the row's current RowVersion is attached and the changed columns marked
|
||||
/// modified, so the UPDATE writes those columns and keeps the optimistic-concurrency check. The staged
|
||||
/// stub stays tracked so <see cref="SetFailureReason"/> can add to the same UPDATE.
|
||||
/// </summary>
|
||||
private static void UpdateDeploymentStatus(
|
||||
OtOpcUaConfigDbContext db, DeploymentId id, DeploymentStatus status, bool sealNow = false)
|
||||
{
|
||||
var d = db.Deployments.FirstOrDefault(x => x.DeploymentId == id.Value);
|
||||
if (d is null) return;
|
||||
d.Status = status;
|
||||
if (sealNow) d.SealedAtUtc = DateTime.UtcNow;
|
||||
var entry = TrackStub(db, id);
|
||||
if (entry is null) return;
|
||||
entry.Entity.Status = status;
|
||||
entry.Property(x => x.Status).IsModified = true;
|
||||
if (sealNow)
|
||||
{
|
||||
entry.Entity.SealedAtUtc = DateTime.UtcNow;
|
||||
entry.Property(x => x.SealedAtUtc).IsModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Stages the current deployment's failure reason onto the stub <see cref="UpdateDeploymentStatus"/> staged.</summary>
|
||||
private void SetFailureReason(OtOpcUaConfigDbContext db, string reason)
|
||||
{
|
||||
if (_current is null) return;
|
||||
var entry = TrackStub(db, _current.Value);
|
||||
if (entry is null) return;
|
||||
entry.Entity.FailureReason = reason;
|
||||
entry.Property(x => x.FailureReason).IsModified = true;
|
||||
}
|
||||
|
||||
/// <summary>The tracked blob-free stub for a deployment, attaching one on first use; null when the row is gone.</summary>
|
||||
private static Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<Deployment>? TrackStub(
|
||||
OtOpcUaConfigDbContext db, DeploymentId id)
|
||||
{
|
||||
var tracked = db.ChangeTracker.Entries<Deployment>().FirstOrDefault(e => e.Entity.DeploymentId == id.Value);
|
||||
if (tracked is not null) return tracked;
|
||||
var stamp = db.Deployments
|
||||
.AsNoTracking()
|
||||
.Where(x => x.DeploymentId == id.Value)
|
||||
.Select(x => new { x.RowVersion })
|
||||
.FirstOrDefault();
|
||||
if (stamp is null) return null;
|
||||
return db.Deployments.Attach(new Deployment
|
||||
{
|
||||
DeploymentId = id.Value, RevisionHash = string.Empty, CreatedBy = string.Empty, RowVersion = stamp.RowVersion,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user