-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[kvm]: delete CpuFeaturesHistoryVO when CPU feature MD5 changes #3220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.5.6
Are you sure you want to change the base?
Conversation
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
步骤说明该变更为 KVM 主机引入 CPU 特征 MD5 跟踪机制。在 HostFactResponse 中新增 cpuFeatureMd5 字段及其访问器,在 KVMHost 中添加 MD5 变化处理逻辑以清理历史记录,并在 KVMSystemTags 中定义新的系统标签。 变更内容
代码审查工作量估计🎯 2 (简单) | ⏱️ ~12 分钟 诗歌
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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.javaComment |
There was a problem hiding this 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;
|
|
||
| // 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); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
首次写入 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.
When BIOS settings modify CPU features without changing cpuModelName,
the CpuFeaturesHistoryVO records become stale and block valid migrations.
Changes:
records (both src and dst) when MD5 changes
Resolves: ZSTAC-76397
Change-Id: I6d626e6d67666d6f677a727471797a63776f7868
sync from gitlab !9039