refactor(driver-pages): address post-review follow-ups
- DriverInstanceSpec carries ClusterId from the deployment artifact; DriverHostActor threads the real cluster identity into DriverInstanceActor instead of the local NodeId. Old pre-PR artifacts without a ClusterId field fall back to the NodeId so in-flight deployments keep working. - DriverHostActor.ChildEntry holds the full DriverInstanceSpec (was only carrying DriverType + LastConfigJson). Restart respawns preserve RowId, Name, Enabled, ClusterId — no placeholder values. - Drop the unnecessary _faultLock on DriverInstanceActor — every read/write site runs inside an Akka message handler which is single-threaded per actor instance. - DriverStatusPanel.DisposeAsync awaits Timer.DisposeAsync so an in-flight 5s tick can't invoke StateHasChanged on a component whose hub has already been torn down.
This commit is contained in:
@@ -55,7 +55,12 @@ public sealed class DriverHostActor : ReceiveActor, IWithTimers
|
||||
|
||||
private readonly Dictionary<string, ChildEntry> _children = new(StringComparer.Ordinal);
|
||||
|
||||
private sealed record ChildEntry(IActorRef Actor, string DriverType, string LastConfigJson, bool Stubbed);
|
||||
private sealed record ChildEntry(IActorRef Actor, DriverInstanceSpec Spec, bool Stubbed)
|
||||
{
|
||||
// Convenience accessors for sites that don't need the full spec.
|
||||
public string DriverType => Spec.DriverType;
|
||||
public string LastConfigJson => Spec.DriverConfig;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ITimerScheduler Timers { get; set; } = null!;
|
||||
@@ -374,7 +379,10 @@ public sealed class DriverHostActor : ReceiveActor, IWithTimers
|
||||
}
|
||||
|
||||
IActorRef child;
|
||||
var clusterId = _localNode.Value;
|
||||
// Prefer the real ClusterId from the deployment artifact; fall back to the local node
|
||||
// identity for pre-PR artifacts that don't carry it yet (older deploys persisted before
|
||||
// ClusterId was added to DriverInstanceSpec).
|
||||
var clusterId = !string.IsNullOrEmpty(spec.ClusterId) ? spec.ClusterId : _localNode.Value;
|
||||
if (stub)
|
||||
{
|
||||
child = Context.ActorOf(
|
||||
@@ -397,7 +405,7 @@ public sealed class DriverHostActor : ReceiveActor, IWithTimers
|
||||
child.Tell(new DriverInstanceActor.InitializeRequested(spec.DriverConfig));
|
||||
}
|
||||
|
||||
_children[spec.DriverInstanceId] = new ChildEntry(child, spec.DriverType, spec.DriverConfig, stub);
|
||||
_children[spec.DriverInstanceId] = new ChildEntry(child, spec, stub);
|
||||
_log.Info("DriverHost {Node}: spawned {Type} driver {Id} (stub={Stub})",
|
||||
_localNode, spec.DriverType, spec.DriverInstanceId, stub);
|
||||
}
|
||||
@@ -406,7 +414,8 @@ public sealed class DriverHostActor : ReceiveActor, IWithTimers
|
||||
{
|
||||
if (!_children.TryGetValue(spec.DriverInstanceId, out var entry)) return;
|
||||
entry.Actor.Tell(new DriverInstanceActor.ApplyDelta(spec.DriverConfig, CorrelationId.NewId()));
|
||||
_children[spec.DriverInstanceId] = entry with { LastConfigJson = spec.DriverConfig };
|
||||
// Store the full new spec — a delta can change Name, Enabled, ClusterId, etc. in addition to config.
|
||||
_children[spec.DriverInstanceId] = entry with { Spec = spec };
|
||||
_log.Debug("DriverHost {Node}: ApplyDelta queued for {Id}", _localNode, spec.DriverInstanceId);
|
||||
}
|
||||
|
||||
@@ -467,14 +476,8 @@ public sealed class DriverHostActor : ReceiveActor, IWithTimers
|
||||
Context.Stop(entry.Actor);
|
||||
_children.Remove(msg.DriverInstanceId);
|
||||
|
||||
// Respawn using the same spec that was applied during the last reconcile.
|
||||
SpawnChild(new DriverInstanceSpec(
|
||||
DriverInstanceRowId: Guid.Empty,
|
||||
DriverInstanceId: msg.DriverInstanceId,
|
||||
Name: msg.DriverInstanceId,
|
||||
DriverType: entry.DriverType,
|
||||
Enabled: true,
|
||||
DriverConfig: entry.LastConfigJson));
|
||||
// Respawn from the same spec the last reconcile used — preserves RowId, Name, ClusterId.
|
||||
SpawnChild(entry.Spec);
|
||||
}
|
||||
|
||||
private void HandleReconnectDriver(ReconnectDriver msg)
|
||||
|
||||
Reference in New Issue
Block a user