hamgrd: gate Active to SwitchingToStandby transition on peer DPU role - #212
Merged
vivekrnv merged 1 commit intoAug 7, 2026
Merged
Conversation
|
/azp run |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR updates hamgrd’s NPU-driven HA scope state machine to prevent the active side from demoting to SwitchingToStandby until the peer DPU is confirmed ready (peer role is SwitchingToActive and the peer ASIC has acknowledged that role), supporting either message arrival order.
Changes:
- Add a shared gate helper to determine when the peer is ready for the active→
SwitchingToStandbytransition. - Update the
HaState::Activetransition logic to use the new gate (requires accepted/in-progress switchover + peer role + peer ASIC ack). - Add unit tests covering both message orderings (request-first vs peer-state-first).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/hamgrd/src/actors/ha_scope/npu.rs | Gates Active→SwitchingToStandby transition on peer DPU role + ASIC ack, allowing either event ordering. |
| crates/hamgrd/src/actors/ha_scope/mod.rs | Adds unit tests for the new gate helper covering both message arrival orderings. |
| self.current_npu_peer_ha_state(state.internal()), | ||
| &self.current_npu_peer_acked_asic_ha_state(state.internal()), | ||
| ) { | ||
| Some((HaState::SwitchingToStandby, "peer DPU entered switching_to_active role")) |
zjswhhh
approved these changes
Aug 4, 2026
Signed-off-by: BYGX-wcr <wcr@live.cn>
BYGX-wcr
force-pushed
the
fix/gate-active-to-standby-on-peer-role
branch
from
August 4, 2026 18:57
256990e to
ca2e396
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
crates/hamgrd/src/actors/ha_scope/npu.rs:36
ha_role_to_string(HaRole::SwitchingToActive.as_str_name())allocates a newStringon every gate check even though the expected value is a fixed, lowercase role string in the HA-scope state (same format as otheracked_asic_ha_statecomparisons). This adds avoidable per-event overhead in the state-machine hot path.
matches!(event, HaEvent::SwitchoverRequested | HaEvent::PeerStateChanged)
&& switchover_state == Some("in_progress")
&& peer_ha_state == HaState::SwitchingToActive
&& peer_acked_asic_ha_state == ha_role_to_string(HaRole::SwitchingToActive.as_str_name())
crates/hamgrd/src/actors/ha_scope/npu.rs:1731
- In the
HaState::Activearm,get_npu_ha_scope_state()is now called (and deserializes the full NPU HA scope state) for every event, even for events likePeerLost/LocalFailurethat will immediately transition without needing the NPU snapshot. This is an avoidable performance regression compared to the prior structure where deserialization was skipped for early-exit events.
let npu_state = self.base.get_npu_ha_scope_state(state.internal());
let switchover_state = npu_state.as_ref().and_then(|scope| scope.switchover_state.as_deref());
let peer_ha_state = npu_state
.as_ref()
.and_then(|scope| scope.peer_ha_state.as_deref())
vivekrnv
approved these changes
Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of PR
Summary:
Gate the NPU-driven Active to SwitchingToStandby transition until the peer DPU has entered the switching_to_active role. This prevents the active DPU from demoting before the peer is ready and supports either message arrival order.
Type of change
Approach
What is the motivation for this PR?
A SwitchoverRequest could previously move the active HA scope to SwitchingToStandby before the peer DPU acknowledged switching_to_active.
How did you do it?
Require an accepted in-progress switchover, peer SwitchingToActive state, and peer ASIC switching_to_active acknowledgement. Allow either the request or peer state update to complete the gate. Add HA scope unit coverage in ha_scope/mod.rs for both message orderings.
How did you verify/test it?
Any platform specific information?
Applies to NPU-driven planned switchover.
Documentation
No documentation changes are required for this behavior fix.