Skip to content

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

Open
zstack-robot-1 wants to merge 1 commit into5.4.8from
sync/hanyu.liang/fix-84266@@2
Open

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

Conversation

@zstack-robot-1
Copy link
Copy Markdown
Collaborator

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

Supersedes wrong branch-name MR: http://dev.zstack.io:9080/zstackio/zstack/-/merge_requests/9794

sync from gitlab !9795

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: 043af87e-5ff9-4e01-b2f2-b9028db059a8

📥 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

通览

此变更为VM状态变化规范事件添加了源追踪能力。新增stateChangeSource字段到VmStateChangedData,扩展changeVmStateInDb方法接收此参数,并在HA启动处理中将状态转换从手动SQL改为调用新增的API。

变更

VM状态变化源追踪

层级 / 文件 摘要
事件数据契约
header/src/main/java/org/zstack/header/vm/VmCanonicalEvents.java
VmStateChangedData新增private字段stateChangeSource及其public getter/setter方法。
状态转换方法
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
新增三参数重载changeVmStateInDb(VmInstanceStateEvent, Runnable, String),原有的两参数重载改为委托此新重载。
事件数据设置
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
VM完整状态变化规范事件中,将stateChangeSource值设置到VmStateChangedData对象。
HA启动集成
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
HA启动处理将VM停止转换从显式UpdateQuery改为调用changeVmStateInDb(VmInstanceStateEvent.stopped, null, HaStartVmInstanceMsg.class.getName())。

代码审查工作量估计

🎯 2 (简单) | ⏱️ ~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 PR title follows the required [scope]: format and is 40 characters, well under the 72 character limit. Title accurately describes the main change of publishing HA start state change events.
Description check ✅ Passed PR description is comprehensive and directly related to the changeset. It explains the root cause, resolution approach, verification steps, and references the JIRA issue ZSTAC-84266.
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@@2

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.

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