Repository navigation
Stop actors when a dispatch update changes its merge identity - #318
Conversation
| self._dispatch_identities[dispatch.id] = identity | ||
| self._running_dispatches[dispatch.id] = dispatch | ||
| self._failed_dispatches.pop(identity, None) |
There was a problem hiding this comment.
If we have a class for dispatch status, this can probably be done as one operation in that class, hopefully making manipulating stuff less bug prone (if we forget to update one dict it could be bad).
There was a problem hiding this comment.
Done. A start or update now replaces one DispatchStatus, and a stop pops one. The dispatch and its identity can no longer drift between separate maps.
There was a problem hiding this comment.
Thanks, the dispatch side looks good now. A start or update replaces a single DispatchStatus, so the dispatch and its identity are always updated together.
The actor side is still updated inline, though. _handle_dispatch repeats the same steps in three places (L440-L445, L465-L467 and L477-L482): get the ActorStatus, check if it holds a failed dispatch, and pop it. Two of those places also check that the failed dispatch is the one being handled. A small helper method, something like _drop_failed_dispatch(identity, dispatch_id=None), would keep that rule in one place, which is what I was after with this comment.
Two smaller things about the new dataclasses:
ActorStatusholds either a running actor or a failed dispatch. Both fields are optional, though, so nothing prevents both from being set or both from beingNone. A union of two small types, something likeRunningActor | FailedStart, would let the type checker rule that out.ActorStatus,DispatchStatusandMergeContextare public names onActorDispatcher, which is public too, so they'll show up in the API docs. Prefixing them with_would keep them internal.ActorAndChannelis already exposed the same way, so this could also go in a separate cleanup.
All of this is optional. I'm approving anyway, so feel free to merge as is or leave it for a follow-up.
6573546 to
07c983c
Compare
The v1.0.4 notes were still present after the release. Restore the empty template before adding new entries. Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Remember each dispatch's routed identity in one status record. If it changes, stop the old actor unless another running dispatch still uses it. Keep failed starts with actor state so retries cannot drift from routing state. Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
07c983c to
aa8dfce
Compare
llucax
left a comment
There was a problem hiding this comment.
LGTM. I left an optional suggestion in one thread. Feel free to merge as is.
| self._dispatch_identities[dispatch.id] = identity | ||
| self._running_dispatches[dispatch.id] = dispatch | ||
| self._failed_dispatches.pop(identity, None) |
There was a problem hiding this comment.
Thanks, the dispatch side looks good now. A start or update replaces a single DispatchStatus, so the dispatch and its identity are always updated together.
The actor side is still updated inline, though. _handle_dispatch repeats the same steps in three places (L440-L445, L465-L467 and L477-L482): get the ActorStatus, check if it holds a failed dispatch, and pop it. Two of those places also check that the failed dispatch is the one being handled. A small helper method, something like _drop_failed_dispatch(identity, dispatch_id=None), would keep that rule in one place, which is what I was after with this comment.
Two smaller things about the new dataclasses:
ActorStatusholds either a running actor or a failed dispatch. Both fields are optional, though, so nothing prevents both from being set or both from beingNone. A union of two small types, something likeRunningActor | FailedStart, would let the type checker rule that out.ActorStatus,DispatchStatusandMergeContextare public names onActorDispatcher, which is public too, so they'll show up in the API docs. Prefixing them with_would keep them internal.ActorAndChannelis already exposed the same way, so this could also go in a separate cleanup.
All of this is optional. I'm approving anyway, so feel free to merge as is or leave it for a follow-up.
Updating a running dispatch could change its merge identity, start a new actor, and leave the old one running.
Remember the identity each dispatch was routed to, stop the old actor when the identity changes (unless another running dispatch still uses it), and drop stale retries.
Fixes #310