Skip to content

<fix>[ha]: ZSTAC-83890 backport pre-fence core to 4.8.38 (@@3)#4152

Open
zstack-robot-2 wants to merge 1 commit into
4.8.38from
sync/yingzhe.hu/4.8.38-ZSTAC-83890@@3
Open

<fix>[ha]: ZSTAC-83890 backport pre-fence core to 4.8.38 (@@3)#4152
zstack-robot-2 wants to merge 1 commit into
4.8.38from
sync/yingzhe.hu/4.8.38-ZSTAC-83890@@3

Conversation

@zstack-robot-2
Copy link
Copy Markdown
Collaborator

Summary

Backport ZSTAC-83890 core HA pre-fence support to 4.8.38.

This replaces !10055 with branch 4.8.38-ZSTAC-83890@@3 and a single squashed commit.

Changes

  • Carry accessiblePeerHostUuid on HaStartVmInstanceMsg.
  • Create haPreFencePending after HA updates VM state/host fields.
  • Require a concrete peer host before creating the pre-fence tag.

Testing

  • git diff --check upstream/4.8.38..HEAD
  • mvn -pl compute -am -DskipTests compile

Resolves: ZSTAC-83890

sync from gitlab !10056

Backport the core HA pre-fence support to 4.8.38.

Carry the accessible peer host through HA start messages. Record the
pre-fence pending tag after HA state updates, and require a concrete
peer before creating the tag.

Test: mvn -pl compute -am -DskipTests compile

Resolves: ZSTAC-83890

Change-Id: Ic0978d214bf3996ae6fd0c112f125067ce70bed3
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

走查概览

HA 虚拟机启动流程通过新增预围栏系统标签、消息字段扩展和流程异步化,改进主机故障检测与恢复机制。启动消息携带可达对端主机信息,扩展点接口支持异步完成回调,流程链按序执行扩展与消息发送,HA 启动处理根据字段创建预围栏待处理标签。

变更详情

HA 虚拟机启动流程异步化与预围栏标签

层 / 文件 摘要
消息字段与系统标签定义
header/src/main/java/org/zstack/header/vm/HaStartVmInstanceMsg.java, compute/src/main/java/org/zstack/compute/vm/VmSystemTags.java
HaStartVmInstanceMsg 新增 accessiblePeerHostUuidhaReason 字段与对应 getter/setter。VmSystemTags 新增 HA_PRE_FENCE_SUSPECT_HOST_UUID_TOKENHA_PRE_FENCE_ACCESSIBLE_PEER_HOST_UUID_TOKEN 常量与 HA_PRE_FENCE_PENDING PatternedSystemTag 定义。
扩展点接口异步化
header/src/main/java/org/zstack/header/vm/VmBeforeStartOnHypervisorExtensionPoint.java
接口无参方法改为默认空实现,新增带 Completion 参数的重载方法,默认实现调用无参版本后直接触发 completion.success()
流程链重构与异步编排
compute/src/main/java/org/zstack/compute/vm/VmStartOnHypervisorFlow.java
run 方法用 FlowChainBuilder 重构为两步异步流程:第一步通过 While + Completion 逐个执行扩展点并在 WhileDoneCompletion 根据错误码决定继续或失败;第二步发送 StartVmOnHypervisorMsg 并根据回复决定结果。导入依赖调整为工作流链相关类型。
HA 启动处理与预围栏标签创建
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
HA 启动时捕获 hostUuid,置数据库状态为 Stopped 并清空 hostUuid;若原 hostUuid 非空则写入 lastHostUuid。根据消息字段中 trimToNull 后的 suspectHostUuidpeerHostUuid 决定创建 HA_PRE_FENCE_PENDING 系统标签,缺失时输出 debug 日志。

预估代码审查工作量

🎯 4 (复杂) | ⏱️ ~45 分钟

可能相关的 PR

  • MatheMatrix/zstack#4027:实现了相同的"HA 启动后创建预围栏待处理标签"逻辑,使用相同的 VmSystemTags.HA_PRE_FENCE_PENDING 标签与 token,以及 HaStartVmInstanceMsg 的可疑/对端主机信息字段。

🐰 异步的流程链,轻轻编织,
扩展点默认,温柔以待,
预围栏标签,守护主机心间,
HA 启动更稳,故障不再来,
消息传递新信息,虚拟机安心启。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Pull request title clearly describes the main change: backporting HA pre-fence core support to version 4.8.38, with specific issue reference ZSTAC-83890.
Description check ✅ Passed Pull request description is directly related to the changeset, detailing specific changes (accessiblePeerHostUuid, haPreFencePending tag, peer host requirement) and testing validation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/yingzhe.hu/4.8.38-ZSTAC-83890@@3

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.3)
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
compute/src/main/java/org/zstack/compute/vm/VmStartOnHypervisorFlow.java (1)

61-61: 💤 Low value

建议使用 isEmpty() 替代 size() > 0

使用 !errorCodeList.getCauses().isEmpty() 更符合 Java 惯用写法。

♻️ 建议修改
-                                if (errorCodeList.getCauses().size() > 0) {
+                                if (!errorCodeList.getCauses().isEmpty()) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@compute/src/main/java/org/zstack/compute/vm/VmStartOnHypervisorFlow.java` at
line 61, In VmStartOnHypervisorFlow (around the check using
errorCodeList.getCauses()), replace the size() > 0 check with the idiomatic
!errorCodeList.getCauses().isEmpty() to improve readability and follow Java
conventions; locate the conditional that currently reads
errorCodeList.getCauses().size() > 0 and change it to use isEmpty() negation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@compute/src/main/java/org/zstack/compute/vm/VmStartOnHypervisorFlow.java`:
- Line 61: In VmStartOnHypervisorFlow (around the check using
errorCodeList.getCauses()), replace the size() > 0 check with the idiomatic
!errorCodeList.getCauses().isEmpty() to improve readability and follow Java
conventions; locate the conditional that currently reads
errorCodeList.getCauses().size() > 0 and change it to use isEmpty() negation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7b81e7c9-6d43-4b63-b15f-ec467d6ee335

📥 Commits

Reviewing files that changed from the base of the PR and between 00abf62 and 6358576.

📒 Files selected for processing (5)
  • compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
  • compute/src/main/java/org/zstack/compute/vm/VmStartOnHypervisorFlow.java
  • compute/src/main/java/org/zstack/compute/vm/VmSystemTags.java
  • header/src/main/java/org/zstack/header/vm/HaStartVmInstanceMsg.java
  • header/src/main/java/org/zstack/header/vm/VmBeforeStartOnHypervisorExtensionPoint.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants