Skip to content

<fix>[sdk]: refactor HA network group validation#3770

Open
zstack-robot-2 wants to merge 1 commit intofeature-5.5.6-dpu-net-ha2from
sync/haoyu.ding/fix-84164@@2
Open

<fix>[sdk]: refactor HA network group validation#3770
zstack-robot-2 wants to merge 1 commit intofeature-5.5.6-dpu-net-ha2from
sync/haoyu.ding/fix-84164@@2

Conversation

@zstack-robot-2
Copy link
Copy Markdown
Collaborator

DBImpact

Resolves: ZSTAC-84164

Change-Id: I736967737a6963726b666776746b677a69717278

sync from gitlab !9639

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

Warning

Rate limit exceeded

@MatheMatrix has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 54 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 1 minutes and 54 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ 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: 97fec4e3-13e6-4244-8862-06ca348d1bb9

📥 Commits

Reviewing files that changed from the base of the PR and between 7e7f9c0 and dac798d.

⛔ Files ignored due to path filters (2)
  • sdk/src/main/java/org/zstack/sdk/CreateHaNetworkGroupAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/HaNetworkGroupInventory.java is excluded by !sdk/**
📒 Files selected for processing (2)
  • conf/db/upgrade/V5.5.12__schema.sql
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

概览

本次变更对HA网络组的数据库架构进行了调整。移除了HaNetworkGroupVO表中的clusterUuidconfigVersion列,将HaNetworkGroupL3NetworkRefVO表的l3NetworkUuid索引改为唯一约束,并新增HaNetworkGroupGlobalConfigVersionVO表用于管理全局版本配置(并插入初始记录)。同时在错误码常量中添加了三个新的标识符。

变更

Cohort / File(s) Summary
数据库架构升级
conf/db/upgrade/V5.5.12__schema.sql
zstack.HaNetworkGroupVO 表中移除 clusterUuid(及其 FK ON DELETE CASCADE)和 configVersion 列;将 zstack.HaNetworkGroupL3NetworkRefVO 表的 l3NetworkUuid 索引由非唯一改为唯一;新增表 zstack.HaNetworkGroupGlobalConfigVersionVO(name PK, version BIGINT UNSIGNED DEFAULT 0) 并使用 INSERT ... ON DUPLICATE KEY UPDATE 写入 ('ha-network-group', 0)
错误代码常量
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
新增三个公共字符串常量:ORG_ZSTACK_HA_10037ORG_ZSTACK_HA_10038ORG_ZSTACK_HA_10039

估计代码审查工作量

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

诗歌

🐰 小兔轻敲键,表结构换新颜,
唯一索引立,旧列悄然散,
全局版本表,初值稳又甜,
错误码添新,日志更分明,
嘻嘻祝合并,代码跳花圈 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题遵循规定的格式要求 [scope]: ,长度为48个字符,未超过72字符限制。
Description check ✅ Passed 描述与变更集相关,提到了 ZSTAC-84164 和 DBImpact,与数据库架构变更相符。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/haoyu.ding/fix-84164@@2

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

Copy link
Copy Markdown

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
conf/db/upgrade/V5.5.12__schema.sql (1)

1-24: ⚠️ Potential issue | 🟡 Minor

将 TIMESTAMP 默认值改为 CURRENT_TIMESTAMP

第 8、17、31 行的 lastOpDatecreateDate 列使用了 DEFAULT '0000-00-00 00:00:00',违反编码指南规范。应改为 DEFAULT CURRENT_TIMESTAMP

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/db/upgrade/V5.5.12__schema.sql` around lines 1 - 24, The TIMESTAMP
columns use the invalid zero-date default; update the DEFAULT for lastOpDate and
createDate in HaNetworkGroupVO and HaNetworkGroupL3NetworkRefVO: replace
"DEFAULT '0000-00-00 00:00:00'" with "DEFAULT CURRENT_TIMESTAMP" and keep the ON
UPDATE CURRENT_TIMESTAMP only on lastOpDate (i.e., HaNetworkGroupVO.lastOpDate
and HaNetworkGroupL3NetworkRefVO.lastOpDate should have DEFAULT
CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, while HaNetworkGroupVO.createDate
and HaNetworkGroupL3NetworkRefVO.createDate should have DEFAULT
CURRENT_TIMESTAMP without ON UPDATE).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@conf/db/upgrade/V5.5.12__schema.sql`:
- Around line 1-24: The TIMESTAMP columns use the invalid zero-date default;
update the DEFAULT for lastOpDate and createDate in HaNetworkGroupVO and
HaNetworkGroupL3NetworkRefVO: replace "DEFAULT '0000-00-00 00:00:00'" with
"DEFAULT CURRENT_TIMESTAMP" and keep the ON UPDATE CURRENT_TIMESTAMP only on
lastOpDate (i.e., HaNetworkGroupVO.lastOpDate and
HaNetworkGroupL3NetworkRefVO.lastOpDate should have DEFAULT CURRENT_TIMESTAMP ON
UPDATE CURRENT_TIMESTAMP, while HaNetworkGroupVO.createDate and
HaNetworkGroupL3NetworkRefVO.createDate should have DEFAULT CURRENT_TIMESTAMP
without ON UPDATE).

ℹ️ 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: 74be4c8c-3ce6-4b3b-a34d-a46971c83f27

📥 Commits

Reviewing files that changed from the base of the PR and between 9b253dc and af329bc.

⛔ Files ignored due to path filters (2)
  • sdk/src/main/java/org/zstack/sdk/CreateHaNetworkGroupAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/HaNetworkGroupInventory.java is excluded by !sdk/**
📒 Files selected for processing (2)
  • conf/db/upgrade/V5.5.12__schema.sql
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

@MatheMatrix MatheMatrix force-pushed the sync/haoyu.ding/fix-84164@@2 branch from af329bc to 7e7f9c0 Compare April 16, 2026 09:22
Copy link
Copy Markdown

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
conf/db/upgrade/V5.5.12__schema.sql (1)

21-48: ⚠️ Potential issue | 🟠 Major

将结构变更放在历史版本脚本中,可能导致已升级环境缺失本次变更。

这里的唯一索引调整和新表创建都写在 V5.5.12__schema.sql。对已经执行过该版本升级的数据库,这些变更通常不会再次生效,可能造成:

  • l3NetworkUuid 唯一约束未落地;
  • HaNetworkGroupGlobalConfigVersionVO 与初始化记录缺失。

建议将这些变更放到新的更高版本升级脚本,并在添加唯一约束前补充重复数据清理与幂等保护。

As per coding guidelines **/*.sql: “Upgrading scene has been carefully handled”.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/db/upgrade/V5.5.12__schema.sql` around lines 21 - 48, The schema changes
(unique index `ukHaNetworkGroupL3NetworkRefVOl3NetworkUuid`, tables
`HostHaNetworkGroupStatusVO`, `HaNetworkGroupGlobalConfigVersionVO` and the
INSERT for `'ha-network-group'`) must not live in the historical file
`V5.5.12__schema.sql`; move them into a new higher-version migration script
(e.g., V5.5.13+), make the unique-index addition idempotent by first
deduplicating rows in the `HaNetworkGroupL3NetworkRefVO` source table and/or
skipping index creation if it already exists, and ensure the
`HaNetworkGroupGlobalConfigVersionVO` initialization uses an idempotent
INSERT/UPDATE path so re-running the migration is safe; reference the
constraints `fkHaNetworkGroupL3NetworkRefVOHaNetworkGroupVO` /
`fkHaNetworkGroupL3NetworkRefVOL3NetworkEO` when verifying referential integrity
during the migration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@conf/db/upgrade/V5.5.12__schema.sql`:
- Around line 21-48: The schema changes (unique index
`ukHaNetworkGroupL3NetworkRefVOl3NetworkUuid`, tables
`HostHaNetworkGroupStatusVO`, `HaNetworkGroupGlobalConfigVersionVO` and the
INSERT for `'ha-network-group'`) must not live in the historical file
`V5.5.12__schema.sql`; move them into a new higher-version migration script
(e.g., V5.5.13+), make the unique-index addition idempotent by first
deduplicating rows in the `HaNetworkGroupL3NetworkRefVO` source table and/or
skipping index creation if it already exists, and ensure the
`HaNetworkGroupGlobalConfigVersionVO` initialization uses an idempotent
INSERT/UPDATE path so re-running the migration is safe; reference the
constraints `fkHaNetworkGroupL3NetworkRefVOHaNetworkGroupVO` /
`fkHaNetworkGroupL3NetworkRefVOL3NetworkEO` when verifying referential integrity
during the migration.

ℹ️ 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: 8253e10d-fa79-4194-b648-4842872a0141

📥 Commits

Reviewing files that changed from the base of the PR and between af329bc and 7e7f9c0.

⛔ Files ignored due to path filters (2)
  • sdk/src/main/java/org/zstack/sdk/CreateHaNetworkGroupAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/HaNetworkGroupInventory.java is excluded by !sdk/**
📒 Files selected for processing (2)
  • conf/db/upgrade/V5.5.12__schema.sql
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
✅ Files skipped from review due to trivial changes (1)
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

@zstack-robot-2
Copy link
Copy Markdown
Collaborator Author

Comment from ye.zou:

Code Review

# 严重程度 分类 文件 问题描述 修复建议
1 🟡 Major 回归风险 V5.5.12__schema.sql 在已有的 migration 文件里修改结构(删列 clusterUuid/configVersion、改 INDEX 为 UNIQUE INDEX、新增表)。target branch 是 feature 分支所以目前影响有限,但如果此 feature branch 已经有人部署过旧版本的 V5.5.12__schema.sql,Flyway 会因为 checksum 不匹配而拒绝启动。 确认 feature branch 上没有已部署环境;如果有,需要新建 V5.5.13__schema.sql 做增量变更(ALTER TABLE DROP COLUMNDROP INDEX + ADD UNIQUE INDEXCREATE TABLE IF NOT EXISTS)。
2 🔵 Minor 数据一致性 V5.5.12__schema.sql:18 l3NetworkUuid 从普通 INDEX 改为 UNIQUE INDEX,意味着一个 L3 只能属于一个 network group。这是正确的业务约束(interceptor 里 validateL3NetworkUniqueBinding 也在检查),但没有配套的数据迁移——如果已有脏数据(同一 L3 绑了多个 group),加 UNIQUE 会直接失败。 feature 分支新建表问题不大(CREATE TABLE IF NOT EXISTS + 没有历史数据)。只需确认不存在旧数据路径。
3 🔵 Minor 代码质量 V5.5.12__schema.sql:42-48 INSERT ... ON DUPLICATE KEY UPDATE name = name 是幂等的 ✅,但 UPDATE name = name 是个 no-op 写——会触发不必要的 binlog 事件。 改成 INSERT IGNORE 更干净:INSERT IGNORE INTO ... VALUES ('ha-network-group', 0);

结论: APPROVE ✅(条件性)
回归风险: 低 — 变更集中在 schema 和 SDK 同步,逻辑正确。
必须确认: #1(feature branch 无已部署环境则 OK)
建议修: #3

DBImpact

Resolves: ZSTAC-84164

Change-Id: I736967737a6963726b666776746b677a69717278
@MatheMatrix MatheMatrix force-pushed the sync/haoyu.ding/fix-84164@@2 branch from 7e7f9c0 to dac798d Compare April 16, 2026 10:39
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