Repository navigation
Extend the graph state machine with a recovery state - #1033
NicolasFussberger wants to merge 10 commits into
Conversation
63688cd to
fbc11f4
Compare
|
Documentation preview for this pull request is available at: |
7875c69 to
cde6867
Compare
4be4fc2 to
87daed8
Compare
| Graph -> Component ++: deactivate() | ||
| Component --> Graph --: clean up done | ||
| note over Graph | ||
| The clean up is done in place on the main loop thread, not on a worker. |
There was a problem hiding this comment.
Maybe we should number the arrows and give longer notes in a table? Maybe the diagrams wouldn't have the sideways scroll then? Would be nice if this works.
There was a problem hiding this comment.
mmh I am not sure if this would be better then you need two screens to look at the diagram and the table at the same time
| kInTransition : Run Target transition is in progress | ||
| kAborting : Wait for ongoing jobs to finish after\na failure or transition cancellation | ||
| kUndefinedState : No ongoing jobs, graph is in\nan undefined but consistent state | ||
| state kComponentRecovery #Red |
There was a problem hiding this comment.
| state kComponentRecovery #Red | |
| state kComponentRecovery #LightCoral |
Bit hard to read with the saturated red 😆
| kAborting --> kAborting : job finished\n[not the last job] | ||
| kAborting --> kUndefinedState : job finished\n[last job] | ||
| kAborting --> kAborting : cancel or new request | ||
| kAborting --> kAborting : cancel or\nnew request |
There was a problem hiding this comment.
I think if you merge all the loops going to itself into a single arrow and in the description concatenate the steps it would look a bit more readable.
| } | ||
|
|
||
| if (new_state == GraphState::kSuccess) | ||
| if (target_state == GraphState::kSuccess && old_state == GraphState::kInTransition) |
There was a problem hiding this comment.
| if (target_state == GraphState::kSuccess && old_state == GraphState::kInTransition) | |
| const bool transition_successful = target_state == GraphState::kSuccess && old_state == GraphState::kInTransition; | |
| if (transition_successful ) |
Might be nice to name what is happening.
There was a problem hiding this comment.
I think new code is more strict and less resilient... I would go for something like this:
if (new_state == GraphState::kSuccess)
{
if (old_state == GraphState::kComponentRecovery)
{
// Log recovery success
}
else
{
// Do successful graph state transition things
}
}| LM_LOG_INFO() << "Completed the request for Run Target" << getRequestedRunTarget() << "in" << timeDiff.count() | ||
| << "ms"; | ||
| } | ||
| else if (target_state == GraphState::kSuccess && old_state == GraphState::kComponentRecovery) |
There was a problem hiding this comment.
| else if (target_state == GraphState::kSuccess && old_state == GraphState::kComponentRecovery) | |
| const bool recovery_successful = target_state == GraphState::kSuccess && old_state == GraphState::kComponentRecovery; | |
| else if (recovery_successful ) |
|
|
||
| if (jobs_in_progress_ == 0) | ||
| const GraphState state = getState(); | ||
| if ((state == GraphState::kSuccess || state == GraphState::kComponentRecovery) && |
There was a problem hiding this comment.
| if ((state == GraphState::kSuccess || state == GraphState::kComponentRecovery) && | |
| const bool in_recoverable_state = state == GraphState::kSuccess || state == GraphState::kComponentRecovery; | |
| if (in_recoverable_state && |
| } | ||
| else | ||
| { | ||
| cancel(); |
There was a problem hiding this comment.
Might need a log here, unless it already does somewhere down the chain.
| response = score::MakeUnexpected(ExecErrc::kInTransitionToSameState); | ||
| } | ||
| } | ||
| else if (GraphState::kComponentRecovery == graph_state) |
There was a problem hiding this comment.
| else if (GraphState::kComponentRecovery == graph_state) | |
| else if (graph_state == GraphState::kComponentRecovery) |
| A component can be configured with a restart recovery action. If it terminates unexpectedly while | ||
| its Run Target is active, the graph moves to kComponentRecovery and restarts only this component on the |
There was a problem hiding this comment.
| A component can be configured with a restart recovery action. If it terminates unexpectedly while | |
| its Run Target is active, the graph moves to kComponentRecovery and restarts only this component on the | |
| A component can be configured with a restart recovery action. If it terminates unexpectedly outside | |
| Run Target activation, the graph moves to kComponentRecovery and restarts only this component on the |
| { | ||
|
|
||
| /// @brief States in which the graph has jobs that can be stopped through its stop source. | ||
| bool isActiveState(const GraphState state) |
There was a problem hiding this comment.
I just cannot figure out what is the problem or a check that this function is solving.
We should either update name or description. What is special or what is the shared characteristic between kInTransition and kComponentRecovery?
| // kInTransition and kComponentRecovery are never entered directly from each other, so one stop source | ||
| // is enough for both. | ||
| const bool becomes_active = !isActiveState(old_state) && isActiveState(target_state); | ||
| const bool leaves_active = isActiveState(old_state) && target_state != old_state; |
There was a problem hiding this comment.
The old code is not very readable, but the new code is even less readable IMHO. Please note that introduction of the new function, is only making it harder to understand.
Now I'm not saying that become_transition and coming_from_transition are perfect variable names, but becomes_active and leaves_active are even more cryptic...
AFAIK this code is detecting if we are about to do one of two things:
- Start new graph state transition.
- Stop an active graph state transition.
Variables with names like starting_new_graph_state_transition / stopping_new_graph_state_transition or starting_new_run_target_activation / stopping_new_run_target_activation would make this code much more readable. Please note I'm not advocating to leak Run Target terminology into the graph here.
With descriptive variable names and a bit of comments, this code could become ease to maintain.
There was a problem hiding this comment.
The case that needs to be distinguished whether going to a state that dispatches jobs on the thread pool or leaving a state that dispatches jobs on the thread pool so that the stop source can be adapted accordingly.
Previously, this was a property of kInTransition but now its also a property of kComponentRecovery state.
I'll try to come up with a name for this
| } | ||
|
|
||
| if (new_state == GraphState::kSuccess) | ||
| if (target_state == GraphState::kSuccess && old_state == GraphState::kInTransition) |
There was a problem hiding this comment.
I think new code is more strict and less resilient... I would go for something like this:
if (new_state == GraphState::kSuccess)
{
if (old_state == GraphState::kComponentRecovery)
{
// Log recovery success
}
else
{
// Do successful graph state transition things
}
}87daed8 to
83900a2
Compare
Introduces the new state
kComponentRecoveryin the Graph state machine which is entered while executing any component recovery actions.The new state is highlighted in red in the following state machine.
Discussed alternative: Allow component restarts in state
kSuccessWe can achieve the same behavior this way, but in a less explicit way.
The state machine edges would all depend on whether any jobs are in progress (i.e. restarts are happening) or not.
A dedicated state machine state was deemed easier to understand.
Scenarios if Restart recovery action is configured for a component:
A component fails during a transition (Graph in kInTransition) -> No change to before, transition is aborted, Run Target recovery action
A component fails during active Run Target (Graph in kSuccess) -> Graph moves to kComponentRecovery, component is restarted
A second component fails while recovering a first component (Graph in kComponentRecovery) -> Graph stays in kComponentRecovery, second component is restarted as well
A (non-forced) transition request while recovering component (Graph in kComponentRecovery) -> request is queued
A forced transition request while recovering component (Graph in kComponentRecovery) -> graph moves to kAborting/kUndefined and initiates transition to the requested Run Target.
Why not just do a self-transition to the already active Run Target?