Skip to content

<fix>[vm]: publish HA start state change#3909

Open
MatheMatrix wants to merge 1 commit into5.4.8from
sync/hanyu.liang/fix-84266
Open

<fix>[vm]: publish HA start state change#3909
MatheMatrix wants to merge 1 commit into5.4.8from
sync/hanyu.liang/fix-84266

Conversation

@MatheMatrix
Copy link
Copy Markdown
Owner

Root Cause

VmInstanceBase.handle(HaStartVmInstanceMsg) directly updated VmInstanceVO.state to Stopped through SQL before HA start. This bypassed changeVmStateInDb(), so the VM state transition log, /vm/state/change canonical event, and VmStateChangedExtensionPoint callback were not emitted for the HA internal Unknown -> Stopped transition.

Resolve

  • Add optional stateChangeSource to VmCanonicalEvents.VmStateChangedData; existing events keep the default null value.
  • Route HA start's internal state reset through changeVmStateInDb(VmInstanceStateEvent.stopped, ..., HaStartVmInstanceMsg.class.getName()) instead of direct SQL update.
  • The matching premium MR uses this source to skip HA's own state-change event and avoid recursive NeverStop HA start.

Verification

Remote environment: root@172.20.18.132

  • /home/zstack/header: /usr/local/maven/bin/mvn clean install -Dmaven.test.skip=true -> BUILD SUCCESS
  • /home/zstack/compute: /usr/local/maven/bin/mvn clean install -Dmaven.test.skip=true -> BUILD SUCCESS
  • /home/zstack/premium/mevoco: /usr/local/maven/bin/mvn clean install -Dmaven.test.skip=true -> BUILD SUCCESS
  • /home/zstack/premium/test-premium: /usr/local/maven/bin/mvn test -T 1C -Dtest=VmHaStartStateChangeEventCase -> Tests run: 1, Failures: 0, Errors: 0

Jira: ZSTAC-84266

sync from gitlab !9794

Resolves: ZSTAC-84266

Change-Id: Ib8851991f035890cac610ac0fb3829e6780ded0f
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 3d00e8b4-5dbb-403f-b6d4-528fa3b07c6c

📥 Commits

Reviewing files that changed from the base of the PR and between 6de8314 and ae30a7b.

📒 Files selected for processing (2)
  • compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
  • header/src/main/java/org/zstack/header/vm/VmCanonicalEvents.java

概览

该变更向虚拟机状态变化事件中添加了 stateChangeSource 字段,用于记录触发状态转换的源。扩展了 changeVmStateInDb 方法以支持传递此信息,并更新了HA启动流程以利用新的状态变更跟踪机制。

变更内容

虚拟机状态变更源追踪

层级 / 文件 摘要
数据结构与契约
header/src/main/java/org/zstack/header/vm/VmCanonicalEvents.java
VmStateChangedData 中添加 stateChangeSource 字段及其公开的 getter/setter 方法,用于序列化和传递状态变更来源。
状态持久化实现
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
新增 changeVmStateInDb 三参数重载版本,接收 stateChangeSource 并在触发 VmCanonicalEvents.VmStateChangedData 时记录该值。
HA启动流程集成
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
HA启动虚拟机流程被重构,使用新的 changeVmStateInDb 重载(传递 HaStartVmInstanceMsg.class.getName() 作为来源)替代直接 UpdateQuery 执行。

评估代码审查工作量

🎯 2 (Simple) | ⏱️ ~12 分钟

兔子的诗

🐰 一只兔子欢呼雀跃,
追踪变化的源头来处,
VM状态有了新身份证,
从何而来一清二楚,
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 标题完全符合要求的格式 [scope]: ,40字符,清晰描述了主要变更:通过changeVmStateInDb发布HA启动的状态变化事件。
Description check ✅ Passed 描述详细说明了根本原因、解决方案和验证步骤,与变更内容高度相关,包含JIRA链接和完整的测试验证信息。
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/hanyu.liang/fix-84266

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.1)
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java

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

@ZStack-Robot
Copy link
Copy Markdown
Collaborator

Comment from hanyu.liang:

Superseded by http://dev.zstack.io:9080/zstackio/zstack/-/merge_requests/9795 because this issue touches both zstack and premium, so the branch name should be fix-84266@@2.

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.

3 participants