[ZSTAC-83890][ha] create pre-fence tag after HA state update#4027
[ZSTAC-83890][ha] create pre-fence tag after HA state update#4027zstack-robot-2 wants to merge 1 commit into
Conversation
Move HA pre-fence pending tag creation into HaStartVmInstanceMsg handling after the VM state update, so later pre-fence execution observes the same database state. Resolves: ZSTAC-83890 Change-Id: I7f046732e0245319ed4cf188d1342b65dad11767
概览在虚拟机 HA 启动流程中新增预围栏待处理系统标签机制。定义了标签格式和 token 常量,并在 HA 启动时根据怀疑主机和可访问对等主机信息自动创建标签。 变更HA 预围栏待处理标签系统
🎯 2 (Simple) | ⏱️ ~12 分钟
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.2)compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.javaComment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java (1)
1059-1061: ⚡ Quick win建议优先选取
softAvoidHostUuids中首个非空白值,避免因首元素空白导致误跳过打标签。当前只取
get(0),若首元素是空白字符串而后续元素有效,会直接走“缺失”分支并跳过创建 pre-fence tag。建议先过滤空白值再回退到lastHostUuid。可参考修改
- String suspectHostUuid = StringUtils.trimToNull(CollectionUtils.isEmpty(msg.getSoftAvoidHostUuids()) ? - self.getLastHostUuid() : msg.getSoftAvoidHostUuids().get(0)); + String suspectHostUuid = Optional.ofNullable(msg.getSoftAvoidHostUuids()) + .orElse(Collections.emptyList()) + .stream() + .map(StringUtils::trimToNull) + .filter(Objects::nonNull) + .findFirst() + .orElse(StringUtils.trimToNull(self.getLastHostUuid()));As per coding guidelines: “注意检查来自 Message 的参数是否做过 trim,用户可能在浏览器上复制粘贴的数据带有空格、换行符等”。
🤖 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/VmInstanceBase.java` around lines 1059 - 1061, 在 VmInstanceBase 中计算 suspectHostUuid 时不要直接使用 msg.getSoftAvoidHostUuids().get(0);应先对 msg.getSoftAvoidHostUuids() 做过滤并对每个元素 trim 后取第一个非空值(例如通过 stream/filter + StringUtils.trimToNull),如果没有可用元素再回退到 self.getLastHostUuid(); 同样确保对 msg.getAccessiblePeerHostUuid() 使用 StringUtils.trimToNull 来去除空白并赋给 peerHostUuid,避免因首元素为空白而跳过创建 pre-fence tag。
🤖 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/VmInstanceBase.java`:
- Around line 1059-1061: 在 VmInstanceBase 中计算 suspectHostUuid 时不要直接使用
msg.getSoftAvoidHostUuids().get(0);应先对 msg.getSoftAvoidHostUuids() 做过滤并对每个元素
trim 后取第一个非空值(例如通过 stream/filter + StringUtils.trimToNull),如果没有可用元素再回退到
self.getLastHostUuid(); 同样确保对 msg.getAccessiblePeerHostUuid() 使用
StringUtils.trimToNull 来去除空白并赋给 peerHostUuid,避免因首元素为空白而跳过创建 pre-fence tag。
ℹ️ 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: 0ecc1e51-8c5c-4399-8251-24a13b6f9e8a
📒 Files selected for processing (2)
compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.javacompute/src/main/java/org/zstack/compute/vm/VmSystemTags.java
背景
ZSTAC-83890 review 要求
createPreFencePendingTag放到HaStartVmInstanceMsg的 handle 流程中,并且位于 VM state/hostUuid 数据库更新之后,保证后续 pre-fence 逻辑读取到的 tag 与数据库状态一致。改动
VmSystemTags中定义HA_PRE_FENCE_PENDING,使 core 可以直接创建该 tag。VmInstanceBase.handle(HaStartVmInstanceMsg)中,sql.update(); refreshVO();后创建 pre-fence pending tag,再进入startVm(...)。验证
git diff --checkmvn -pl compute -am -DskipTests compilemvn -pl compute -am -DskipTests installsync from gitlab !9922