已合并
fix: DataDist DataRace修复 #4541
youxiao创建于 7 天前
fix: DataDist DataRace修复 #4541
已合并
youxiao创建于 7 天前
youxiao
7 天前

Pull Request

描述

Prompt 侧 _BuiltIn_cluster_kv_data_sync_func(空输入常驻调度)在 HandleRequest -> Accept 成功后会对 ip_to_conns_emplace(持 entity_mutex_,可能 rehash)。同时 Host UnlinkClusters 会 Feed _BuiltIn_cluster_unlink_func(ServerUnlink),UDF 中 DoServerUnlink 通过 GetEntityByIp 无锁 find 同一张 unordered_multimap。这两条是不同 flow func,UDF worker 可并行,构成 data race。

本次将 GetEntityByIp、Accept 路径上的查找/残留清理、以及 ClearEntitiesip_to_conns_ 的访问统一放到 entity_mutex_ 下。

变更类型

关联的Issue

如何测试

  1. 编译并运行 llm_service_flow_func UT,覆盖 get_entity_by_ip_locked_lookup:CreateEntity 后按 IP 查到 conn;server map 残留时清理 ip_to_conns_
  2. Prompt 场景下并发 Accept 与 ServerUnlink,确认不再出现 ip_to_conns_ rehash 导致的崩溃。

核对清单

其他信息

本地已对改动文件执行 pre-commit(clang-format / codespell / OAT)通过。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 youxiao 的贡献)
Yyouxiao
7 天前 创建了 pull request,commit ee89e59e
atomgit-bot
atomgit-bot
7 天前 评论:

变更摘要

本 PR 修复 LlmCommEntityMgrip_to_conns_ 的并发数据竞争:Prompt 侧 _BuiltIn_cluster_kv_data_sync_funcHandleRequest -> Accept 成功后会对 ip_to_conns_ 执行 emplace(持 entity_mutex_,可能触发 rehash),而 Host UnlinkClusters_BuiltIn_cluster_unlink_func(ServerUnlink)在 DoServerUnlink 中通过 GetEntityByIp 对同一张 unordered_multimap 做无锁 find;这两条属不同 flow func,UDF worker 可并行执行,构成 data race。本次改动将 GetEntityByIp、Accept 路径上的查找/残留清理以及 ClearEntitiesip_to_conns_ 的访问统一纳入 entity_mutex_ 保护,并新增 FindServerEntityByIp 辅助方法及对应单元测试。

主要改动

  • GetEntityByIp 加锁: GetEntityByIp 内部增加 std::lock_guard<std::mutex> lock(entity_mutex_),并相应去掉 const 限定,消除 DoServerUnlink 无锁 find 与 Accept 路径 emplace/rehash 的并发冲突。
  • 新增 FindServerEntityByIp: HandleLinkRequest 的 Accept 路径改为调用新私有方法 FindServerEntityByIp(ip, cleared_residual),在锁内完成查找;命中实体则强制关闭旧连接并复用,server_entity_map_ 无对应实体时清理 ip_to_conns_ 残留并标记 cleared_residual,随后走新建实体流程。
  • ClearEntities 加锁: ClearEntitiesip_to_conns_.clear() 移入 entity_mutex_ 锁保护范围内(server_entity_map_client_entity_map_ 的清理原已在锁内)。
  • 新增单元测试: llm_service_flow_func_utest.cpp 新增 get_entity_by_ip_locked_lookup 用例,覆盖 CreateEntity 后按 IP 查到 conn、以及 server map 残留时清理 ip_to_conns_ 的加锁查找行为。
likedislike
atomgit-bot
atomgit-bot
7 天前 评论:

代码审查

✅ 未发现问题

likedislike
CANN-robotCANN-robot成员
7 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7 天前 评论:

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/ge 张德鹏, xchu42, lining23666 (3/2) 张德鹏 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
7 天前 将yangyongqiang0606,kobemini,ClarkXie,tangqunzhang,xchu42,hugo111,lining23666,fu-jun2,depeng1994,wqtshg_wt,peiyang,shengnan666,zhangfan_hanq,zhanj,zhujingjing,Mexyy,wangxiaotian995,stevenaw0,yuht9设为评审人
CANN-robotCANN-robot成员
7 天前 将yangyongqiang0606,kobemini,ClarkXie,tangqunzhang,xchu42,hugo111,lining23666,fu-jun2,depeng1994,wqtshg_wt,peiyang,shengnan666,zhangfan_hanq,zhanj,zhujingjing,Mexyy,wangxiaotian995,stevenaw0,yuht9设为审查人
youxiao
7 天前 评论:

/compile

likedislike
Yyouxiao
7 天前 update merge request[project id: 8824148, iid: 4541, commit_id: 31cae8029bd43c29f67693e953a4b72d5630d9f4] virtual merging success
CANN-robotCANN-robot成员
7 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7 天前 评论:

流水线任务触发成功
任务链接 [d787428938ce4610b43a911ec5d449fc][流水线指导]

任务名称状态日志下载链接
pre_comment ✅ SUCCESS >>>>>
Compile_X86_compiler ✅ SUCCESS >>>>> >>>>>
Compile_X86_executor ✅ SUCCESS >>>>> >>>>>
Compile_X86_dflow ✅ SUCCESS >>>>> >>>>>
UT_Test_dflow ✅ SUCCESS
UT_Test_ge_common ✅ SUCCESS
UT_Test_parser ✅ SUCCESS
UT_Test_python ✅ SUCCESS >>>>>
UT_Test_rt ✅ SUCCESS
UT_Test_acl ✅ SUCCESS
UT_Test_autofuse ✅ SUCCESS
UT_Test_executor ✅ SUCCESS
UT_Test_autofuse_ascendc_api ✅ SUCCESS
ST_Test_dflow ✅ SUCCESS
ST_Test_ge_common ✅ SUCCESS
ST_Test_parser ✅ SUCCESS
ST_Test_python ✅ SUCCESS >>>>>
ST_Test_rt ✅ SUCCESS
ST_Test_autofuse ✅ SUCCESS
ST_Test_executor ✅ SUCCESS
ST_Test_hetero ✅ SUCCESS
ST_Test_autofuse_ascendc_api ✅ SUCCESS
ST_Test_autofuse_e2e ✅ SUCCESS
UT_Test_fe ✅ SUCCESS
UT_Test_tefusion ✅ SUCCESS
ST_Test_fe ✅ SUCCESS
ST_Test_tefusion ✅ SUCCESS
ST_Test_ge_common_atc ✅ SUCCESS
UT_Test_Report_graphengine ✅ SUCCESS >>>>>
UT_Test_Report_ge_executor_c ✅ SUCCESS >>>>>
UT_Test_Report_ge_autofuse ✅ SUCCESS >>>>>
ST_Test_Report_graphengine ✅ SUCCESS >>>>>
ST_Test_Report_ge_executor_c ✅ SUCCESS >>>>>
ST_Test_Report_ge_autofuse ✅ SUCCESS >>>>>
UT_Test_Report_fe ✅ SUCCESS >>>>>
ST_Test_Report_fe ✅ SUCCESS >>>>>

[2026-08-25 10:27:21]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
7 天前 评论:

流水线任务触发成功
任务链接 [8d27f678c6f541d1acfd0811d2030098][流水线指导]

任务名称状态日志下载链接
pre_comment ✅ SUCCESS >>>>>
Compile_ARM_compiler ✅ SUCCESS >>>>> >>>>>
Compile_ARM_executor ✅ SUCCESS >>>>> >>>>>
Compile_ARM_dflow ✅ SUCCESS >>>>> >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_A900_npupool ✅ SUCCESS >>>>>

[2026-08-25 10:19:24]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
7 天前 评论:

流水线任务触发成功
任务链接 [a8de619925b142efa446dcb54ff1141a][流水线指导]

任务名称状态日志下载链接
codecheck_Pr ✅ SUCCESS
antipoison ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
codecheck_dt ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>>
StaticCheck_codespell ✅ SUCCESS
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS

[2026-08-25 10:17:36]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
7 天前 删除了label:api-check-pass
CANN-robotCANN-robot成员
7 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7 天前 添加了label:ci-pipeline-passed
xchu42
xchu42成员
7 天前 评论:

/lgtm

likedislike
lining23666成员
7 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
7 天前 添加了label:lgtm
Yyouxiao
7 天前 修改标题为 “fix: DataDist DataRace修复”,原标题为“fix: lock Prompt ip_to_conns_ lookups against Accept rehash”
张德鹏成员
7 天前 评论:

/approve

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