已合并
[bugfix]: roll back registered endpoints when server RegisterMem fails (#716) #1120
[bugfix]: roll back registered endpoints when server RegisterMem fails (#716) #1120
已合并
lining23666创建于 19 天前
lining23666成员
19 天前

提交 PR 前,请先阅读 HIXL贡献指南 ,查看 PR 提交方式并遵守相关提交规范。

类型标签

描述

修复 #716 。

HixlCSServer::RegisterMem 依次向所有匹配的 Endpoint 注册同一块内存时,若后续 Endpoint 注册失败,HIXL_CHK_STATUS_RET 直接返回错误,此前已成功注册的 Endpoint 不会被注销回滚:

  • 残留注册在 server 存续期间占用 HCCL 侧注册资源,调用方重试 RegisterMem 会重复注册放大占用;
  • 聚合句柄仅在全部成功后写入 reg_mems_,失败路径调用方无法通过 HixlCSServerUnregMem 清理残留。

本修复为注册流程引入 HIXL_DISMISSABLE_GUARD 回滚:任一 Endpoint 注册失败时,逆序注销本次已成功注册的 Endpoint 后再返回原始注册失败错误码(单点注销失败仅记录 ERROR 日志并继续,best-effort);全部成功后在写入 reg_mems_ 前 Dismiss,与 Endpoint::RegisterMem 内部已有的回滚模式保持一致。

测试项

  1. tests/depends/hccl/src/hccl_stub.{h,cc}:新增 SetMemRegFailureOnCall(第 N 次 HcommMemReg 注入指定错误)、GetMemRegCallCount、GetMemUnregCallCount,ResetMemRegRecord 统一重置;
  2. 新增 UT HixlCSTest.RegisterMemRollsBackEarlierEndpointsWhenLaterEndpointFails:两个 HOST UBC_CTP Endpoint,第 2 次 HcommMemReg 注入 HCCL_E_INTERNAL,断言注册发起 2 次、成功 1 次、回滚注销 1 次、mem_handle 不写出、回滚后重新注册成功;
  3. 新增 UT HixlCSTest.RegisterMemFirstEndpointFailureRollsBackNothing:首个 Endpoint 即失败时回滚为空操作;
  4. 按 TDD 验证:修复前主用例稳定失败(GetMemUnregCallCount() 为 0,与 issue 716 日志一致),修复后通过。

测试结果

bash tests/run_test.sh -s hixl
# [PASSED] hixl
# [PASSED] log_fallback
# All selected C++ test binaries passed.

基于 up/master@4cb24f42 + 本修复提交验证通过。

Checklist

其它(可选)

关联 issue:#716 ,修复方案已在 issue 中答复(失败原子性回滚)。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 lining23666 的贡献)
Llining23666成员
19 天前 创建了 pull request,commit 4bc28ecc
Llining23666成员
19 天前 关联了issue:[Bug-Report|缺陷反馈]: 服务端向多个 Endpoint 注册内存时,后续注册失败未回滚前序成功注册
atomgit-bot
atomgit-bot
19 天前 评论:

变更摘要

本 PR 为 bugfix(关联 issue #716):修复 HixlCSServer::RegisterMem 在多 Endpoint 注册同一块内存时,若后续 Endpoint 注册失败(HIXL_CHK_STATUS_RET 直接返回错误)导致此前已成功注册的 Endpoint 残留、无法通过 HixlCSServerUnregMem 清理的问题。修复方案是在注册流程中引入 HIXL_DISMISSABLE_GUARD 回滚:任一 Endpoint 注册失败时,逆序注销本次已成功注册的 Endpoint 后返回原始错误码(单点注销失败仅记录 ERROR 日志并继续,best-effort);全部成功后才写入 reg_mems_ 并 Dismiss,与 Endpoint::RegisterMem 内部既有回滚模式保持一致,同时补充了对应 UT 与 HCCL stub 注入能力。

主要改动

  • 引入注册回滚机制:在 src/hixl/cs/hixl_cs_server.cc 新增 RollbackRegisteredMem(逆序遍历 ep_mem_infos 调用 DeregisterMem,注销失败仅记录日志),并在 RegisterMem 中通过 HIXL_DISMISSABLE_GUARD 在任一 Endpoint 注册失败时触发回滚,全部成功后写入 reg_mems_ 前调用 HIXL_DISMISS_GUARD 取消回滚,保证失败路径无残留注册、mem_handle 不写出。

  • 新增回滚 UT 用例:在 test_hixl_cs_server.cc 新增 RegisterMemRollsBackEarlierEndpointsWhenLaterEndpointFails(两个 HOST UBC_CTP Endpoint,第 2 次 HcommMemReg 注入 HCCL_E_INTERNAL,断言注册 2 次、成功 1 次、回滚注销 1 次、mem_handle 为 nullptr、恢复后重注册成功)与 RegisterMemFirstEndpointFailureRollsBackNothing(首个 Endpoint 即失败时回滚为空操作,无注销调用),并在 TearDown 中调用 ResetMemRegRecord 清理记录。

  • 扩展 HCCL stub 故障注入与计数:在 hccl_stub.cc/h 新增 SetMemRegFailureOnCall(第 N 次 HcommMemReg 注入指定错误码)、GetMemRegCallCount、GetMemUnregCallCount,并在 HcommMemReg/HcommMemUnreg 中累计调用次数、ResetMemRegRecord 中统一重置注入与计数状态。

likedislike
不准确?
atomgit-bot
atomgit-bot
19 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
19 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
19 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/hixl ✅ zhujingjing, youyx, zhaozhihui (3/2) ✅ zhujingjing (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

lining23666, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
19 天前 将leabclove,youyx,yanyefeng,peiyang,zhujingjing,songmingyang,zhaozhihui,wenxuemin设为评审人
CANN-robotCANN-robot成员
19 天前 将leabclove,youyx,yanyefeng,peiyang,zhujingjing,songmingyang,zhaozhihui,wenxuemin设为审查人
lining23666成员
19 天前 评论:

compile

likedislike
Llining23666成员
19 天前 预合并成功(commit_id: 3169d86932de0e0e710e540232290c733d9796ee)
CANN-robot
CANN-robot成员
19 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
19 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
19 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
19 天前 添加了label:ci-pipeline-passed
youxiao成员
19 天前 评论:

/lgtm

likedislike
Llining23666成员
19 天前 预合并成功(commit_id: 0d9d22ef2acb4518ac3186dd4e6defec19bdb484)
此处折叠了5条事件消息 查看更多
CANN-robotCANN-robot成员
19 天前 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
19 天前 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
lining23666成员
18 天前 评论:

compile

likedislike
Llining23666成员
18 天前 预合并成功(commit_id: d755056d2a3594ca9fb305ffd1599103f5ec38b3)
CANN-robot
CANN-robot成员
18 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
18 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
18 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
18 天前 添加了label:ci-pipeline-passed
youxiao成员
18 天前 评论:

/lgtm

likedislike
zhaozhihui成员
18 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
18 天前 添加了label:lgtm
zhujingjing成员
18 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
18 天前 添加了label:approved
CANN-robotCANN-robot成员
18 天前 合入了pull request