Skip to content

Conversation

@zstack-robot-1
Copy link
Collaborator

When BIOS settings modify CPU features without changing cpuModelName,
the CpuFeaturesHistoryVO records become stale and block valid migrations.

Changes:

  • Add cpuFeatureMd5 field to HostFactResponse
  • Add CPU_FEATURE_MD5 SystemTag to store MD5 per host
  • Compare MD5 on host reconnect, delete related CpuFeaturesHistoryVO
    records (both src and dst) when MD5 changes

Resolves: ZSTAC-76397

Change-Id: I6d626e6d67666d6f677a727471797a63776f7868

sync from gitlab !9039

When BIOS settings modify CPU features without changing cpuModelName,
the CpuFeaturesHistoryVO records become stale and block valid migrations.

Changes:
- Add cpuFeatureMd5 field to HostFactResponse
- Add CPU_FEATURE_MD5 SystemTag to store MD5 per host
- Compare MD5 on host reconnect, delete related CpuFeaturesHistoryVO
  records (both src and dst) when MD5 changes

Resolves: ZSTAC-76397

Change-Id: I6d626e6d67666d6f677a727471797a63776f7868
@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

步骤说明

该变更为 KVM 主机引入 CPU 特征 MD5 跟踪机制。在 HostFactResponse 中新增 cpuFeatureMd5 字段及其访问器,在 KVMHost 中添加 MD5 变化处理逻辑以清理历史记录,并在 KVMSystemTags 中定义新的系统标签。

变更内容

变更集合 / 文件 变更摘要
HostFactResponse 属性扩展
plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java
新增 cpuFeatureMd5 私有字段,配备公开 getter 和 setter 方法,用于代理响应中的 CPU 特征 MD5 值传输
CPU 特征变化处理逻辑
plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java
新增 deleteCpuHistoryVOOnCpuFeatureChange() 私有方法,用于在 CPU 特征 MD5 发生变化时删除相关的 CpuFeaturesHistoryVO 记录,防止历史数据污染
系统标签定义
plugin/kvm/src/main/java/org/zstack/kvm/KVMSystemTags.java
新增 CPU_FEATURE_MD5_TOKEN 常量和 CPU_FEATURE_MD5 模式系统标签,用于在 HostVO 上存储和管理 CPU 特征 MD5 值

代码审查工作量估计

🎯 2 (简单) | ⏱️ ~12 分钟

诗歌

🐰 CPU 特征换新衣,
MD5 来记录细微,
历史数据自清理,
主机状态更清晰~

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题遵循[kvm]格式,长度68字符未超过72字符限制,清晰描述了主要变更:删除CPU特性MD5变更时的CpuFeaturesHistoryVO记录。
Description check ✅ Passed 描述与变更集相关,明确说明了问题背景、具体改动(添加cpuFeatureMd5字段、CPU_FEATURE_MD5系统标签、MD5对比时删除历史记录)和JIRA票号。

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

✨ Finishing touches
  • 📝 Generate docstrings

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.40.5)
plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java

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

Copy link

@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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java`:
- Around line 6209-6224: When handling ret.getCpuFeatureMd5() in KVMHost, ensure
we also clear legacy CpuFeaturesHistoryVO when this is the first time writing
the CPU_FEATURE_MD5 tag: if newMd5 != null and oldMd5 is null, query for
existing CpuFeaturesHistoryVO records for this host (use self.getUuid()) and, if
any exist, call deleteCpuHistoryVOOnCpuFeatureChange() and log the deletion just
like when md5 changes; keep the existing
createTagWithoutNonValue(KVMSystemTags.CPU_FEATURE_MD5,
KVMSystemTags.CPU_FEATURE_MD5_TOKEN, newMd5, true) afterward so the tag is still
created.
🧹 Nitpick comments (1)
plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java (1)

524-524: 建议添加 @GrayVersion 注解以保持一致性。

HostFactResponse 中的大多数字段都有 @GrayVersion 注解(如 lines 459-522)。考虑为 cpuFeatureMd5 添加该注解以保持一致性,例如 @GrayVersion(value = "5.5.6")

♻️ 建议的修改
         private String iscsiInitiatorName;
+        `@GrayVersion`(value = "5.5.6")
         private String cpuFeatureMd5;

Comment on lines +6209 to +6224

// check CPU feature MD5 change
String newMd5 = ret.getCpuFeatureMd5();
if (newMd5 != null) {
String oldMd5 = KVMSystemTags.CPU_FEATURE_MD5.getTokenByResourceUuid(
self.getUuid(), KVMSystemTags.CPU_FEATURE_MD5_TOKEN);

if (oldMd5 != null && !oldMd5.equals(newMd5)) {
deleteCpuHistoryVOOnCpuFeatureChange();
logger.debug(String.format("host[uuid:%s] CPU feature changed, old MD5: %s, new MD5: %s, deleted related CpuFeaturesHistoryVO records",
self.getUuid(), oldMd5, newMd5));
}

createTagWithoutNonValue(KVMSystemTags.CPU_FEATURE_MD5,
KVMSystemTags.CPU_FEATURE_MD5_TOKEN, newMd5, true);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

首次写入 CPU_FEATURE_MD5 时不会清理旧历史,可能仍阻塞迁移

当前仅在 oldMd5 非空且变化时清理。升级后首次上报时 oldMd5 为空,若该主机已有旧的 CpuFeaturesHistoryVO(正是本次问题的遗留数据),迁移仍可能被阻塞。建议在首次写入 MD5 时也做一次清理(或至少在存在历史记录时清理),避免遗留数据继续影响。

🐛 建议修复
-                String newMd5 = ret.getCpuFeatureMd5();
-                if (newMd5 != null) {
-                    String oldMd5 = KVMSystemTags.CPU_FEATURE_MD5.getTokenByResourceUuid(
-                        self.getUuid(), KVMSystemTags.CPU_FEATURE_MD5_TOKEN);
-
-                    if (oldMd5 != null && !oldMd5.equals(newMd5)) {
-                        deleteCpuHistoryVOOnCpuFeatureChange();
-                        logger.debug(String.format("host[uuid:%s] CPU feature changed, old MD5: %s, new MD5: %s, deleted related CpuFeaturesHistoryVO records",
-                            self.getUuid(), oldMd5, newMd5));
-                    }
-
-                    createTagWithoutNonValue(KVMSystemTags.CPU_FEATURE_MD5,
-                        KVMSystemTags.CPU_FEATURE_MD5_TOKEN, newMd5, true);
-                }
+                String newMd5 = ret.getCpuFeatureMd5();
+                if (StringUtils.isNotBlank(newMd5)) {
+                    String oldMd5 = KVMSystemTags.CPU_FEATURE_MD5.getTokenByResourceUuid(
+                        self.getUuid(), KVMSystemTags.CPU_FEATURE_MD5_TOKEN);
+
+                    if (oldMd5 == null) {
+                        // first time after upgrade: clear possible stale history
+                        deleteCpuHistoryVOOnCpuFeatureChange();
+                        logger.debug(String.format("host[uuid:%s] CPU feature MD5 initialized to %s, cleared CpuFeaturesHistoryVO to avoid stale history",
+                                self.getUuid(), newMd5));
+                    } else if (!oldMd5.equals(newMd5)) {
+                        deleteCpuHistoryVOOnCpuFeatureChange();
+                        logger.debug(String.format("host[uuid:%s] CPU feature changed, old MD5: %s, new MD5: %s, deleted related CpuFeaturesHistoryVO records",
+                            self.getUuid(), oldMd5, newMd5));
+                    }
+
+                    createTagWithoutNonValue(KVMSystemTags.CPU_FEATURE_MD5,
+                        KVMSystemTags.CPU_FEATURE_MD5_TOKEN, newMd5, true);
+                }
🤖 Prompt for AI Agents
In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java` around lines 6209 -
6224, When handling ret.getCpuFeatureMd5() in KVMHost, ensure we also clear
legacy CpuFeaturesHistoryVO when this is the first time writing the
CPU_FEATURE_MD5 tag: if newMd5 != null and oldMd5 is null, query for existing
CpuFeaturesHistoryVO records for this host (use self.getUuid()) and, if any
exist, call deleteCpuHistoryVOOnCpuFeatureChange() and log the deletion just
like when md5 changes; keep the existing
createTagWithoutNonValue(KVMSystemTags.CPU_FEATURE_MD5,
KVMSystemTags.CPU_FEATURE_MD5_TOKEN, newMd5, true) afterward so the tag is still
created.

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