Skip to content

<fix>[sdk,db]: add PodInventory request fields#3811

Open
zstack-robot-2 wants to merge 1 commit into5.5.16from
sync/zhong.xian/fixbug/ZSTAC-80103@@2
Open

<fix>[sdk,db]: add PodInventory request fields#3811
zstack-robot-2 wants to merge 1 commit into5.5.16from
sync/zhong.xian/fixbug/ZSTAC-80103@@2

Conversation

@zstack-robot-2
Copy link
Copy Markdown
Collaborator

Expose requestCpu/requestMemory on the generated PodInventory so
SDK callers can deserialize the fields returned by ZQL.

Upgrade script adds matching columns on PodVO and backfills
existing pods with request=limit for legacy-equivalent behaviour.

Resolves: ZSTAC-80103

Change-Id: I5b2a9d4e8c6f3b7a1d0e9c5b4a8f2d7e6c1b3a9f

sync from gitlab !9682

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

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: 04149144-b485-44de-a6ba-6437e0f9573b

📥 Commits

Reviewing files that changed from the base of the PR and between e8b3e06 and 3696498.

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

Walkthrough

zstack.PodVO 表添加两列:requestCpu(INT,可空)和 requestMemory(BIGINT,可空),并在 PodVO.uuid = VmInstanceVO.uuid 的条件下将 VmInstanceVO.cpuNumVmInstanceVO.memorySize 回填到对应新列(仅当目标列为 NULL 时)。

Changes

Cohort / File(s) Summary
数据库架构迁移
conf/db/upgrade/V5.5.16__schema.sql
新增 zstack.PodVO 两个可空列:requestCpu(INT)和 requestMemory(BIGINT);执行基于 PodVO.uuid = VmInstanceVO.uuid 的回填,将 VmInstanceVO.cpuNumVmInstanceVO.memorySize 填入对应新列,仅在目标字段为 NULL 时更新。

Sequence Diagram(s)

(无)

代码审查工作量评估

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

诗歌

🐰 新枝轻插数据库土,
CPU 与内存悄然入驻,
回填如雨润旧行,
表格里春意舒展,
小兔欢跳,记录新舞。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required [scope]: format and is within 72 characters, clearly describing the addition of request fields to PodInventory.
Description check ✅ Passed The description is related to the changeset, explaining the purpose of adding requestCpu/requestMemory fields and the upgrade script's backfill logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/zhong.xian/fixbug/ZSTAC-80103@@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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@conf/db/upgrade/V5.5.16__schema.sql`:
- Around line 352-355: The UPDATE currently overwrites existing columns when
only one side is NULL; modify the PodVO/ VmInstanceVO update to only fill NULL
fields by using per-column COALESCE/IFNULL semantics (e.g., set p.requestCpu =
COALESCE(p.requestCpu, v.cpuNum) and p.requestMemory = COALESCE(p.requestMemory,
v.memorySize)) and keep the WHERE checking p.requestCpu IS NULL OR
p.requestMemory IS NULL so the statement is idempotent and won’t overwrite
non-NULL values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ 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: e6e0a7a3-277c-4bd7-b407-c9cfdea2509b

📥 Commits

Reviewing files that changed from the base of the PR and between 2042399 and cc25c39.

⛔ Files ignored due to path filters (1)
  • sdk/src/main/java/org/zstack/sdk/PodInventory.java is excluded by !sdk/**
📒 Files selected for processing (1)
  • conf/db/upgrade/V5.5.16__schema.sql

Comment thread conf/db/upgrade/V5.5.16__schema.sql
@ZStack-Robot
Copy link
Copy Markdown
Collaborator

Comment from zhong.xian:

Code Review

本 MR 与 premium !13615 配套,只审 conf/db/upgrade/V5.5.16__schema.sql + sdk/PodInventory.java

# 严重程度 分类 文件 问题 建议
1 🔴 Critical 正确性 V5.5.16__schema.sql:353 backfill 的 INNER JOIN VmInstanceVO v ON p.uuid = v.uuid —— VmInstanceVO 是 VIEW(定义 ... FROM VmInstanceEO WHERE deleted IS NULL,见 V0.7__schema.sql:44 / V4.1.2__schema.sql:79 等)。软删除(VmInstanceEO.deleted IS NOT NULL)的 Pod 会被 JOIN 静默过滤掉,requestCpu/requestMemory 永远为 NULL。ZQL includeDeleted 查询、审计、数据恢复场景都会拿到残缺数据。 JOIN 目标改为底表 VmInstanceEOINNER JOIN \zstack`.`VmInstanceEO` v ON p.uuid = v.uuid`。
2 🔴 Critical 正确性 V5.5.16__schema.sql:355(commit cc25c39 SET p.requestCpu = v.cpuNum, p.requestMemory = v.memorySize WHERE p.requestCpu IS NULL OR p.requestMemory IS NULL —— 如果某行 requestCpu 已有值但 requestMemory IS NULL(WHERE 用 OR),SET 会把已有的 requestCpu 也 overwritev.cpuNum。一次性 migration 场景下两列同时 NULL 所以实际不触发,但这是定时炸弹。
:作者工作树里已改成 SET p.requestCpu = COALESCE(p.requestCpu, v.cpuNum), p.requestMemory = COALESCE(p.requestMemory, v.memorySize)但没 commit,合并进去的仍是有缺陷的版本。
把工作树里的 COALESCE 修改 commit 掉,别让它丢。
3 🟡 Major ZStack规范 sdk/PodInventory.java 这个 SDK 文件历史上是 auto-generated(git log 里有若干 "Update sdk"/"chore sdk" regeneration commits)。手工加字段只解决 Java SDK;Python SDK(sdk/python/)、Go SDK(sdk/go/)、CLI 是否也需要同步?如果这几个是靠 @PythonClassInventory 等注解从 premium PodInventory.java regenerate,那本 MR 合并时机与 premium !13615 的先后、以及下次 SDK regeneration 的触发都需要协调。只手改 Java SDK、premium 未合并前先到 5.5.16,Python/Go 客户端就拿不到 request 字段。 确认:(a) 本 MR 必须在 premium !13615 之后合并,否则生成器从 premium inventory 重新生成时会覆盖手工字段;(b) 合并后触发一次完整 SDK regeneration 刷 Python/Go/CLI。
4 🔵 Minor 正确性 V5.5.16__schema.sql:348 requestCpu 列类型 INT(核数)。注释写 "K8s resources.requests.cpu"——K8s 该字段允许小数(500m = 0.5 core),用 INT 会截断。不过 premium MR 13615 里 KubernetesNativeProvider 已经是 toBigInteger().intValue() 截断,上下对齐,不是新问题。 不强求本 MR 改;但将来如果要支持 fractional CPU,就得动这张表 → 改 INT 成 BIGINT(milliCPU) 或 DOUBLE。

结论: BLOCK 🚫

回归风险: 中高

  • Finding Test1 #1:VIEW vs EO 的 JOIN 是静默 bug,只在软删除 Pod 场景暴露,排查困难
  • Finding tao.yang/zstack-ZSV-3564@@2 #2:COALESCE 修复已存在于工作树但未 commit;若不 commit 就合并,等于把修复丢了

必修项:

  1. backfill 的 JOIN 改为 VmInstanceEO(底表),不要连 VIEW
  2. 把工作树里 SET ... = COALESCE(...) 的修改 commit + push 上去
  3. 确认 premium MR !13615 的合并顺序在本 MR 之前,合并后触发完整 SDK regeneration

建议项:

  • 文档/注释说明 requestCpu 单位是"核数"而非 milliCPU,免得未来使用者踩坑

其它(没问题的地方不展开):

  • ADD_COLUMN 幂等、可 null + default NULL,re-run 安全
  • PodVO 表由主仓 V5.3.52__schema.sql:8 创建,community 版也有此表,ADD_COLUMN / UPDATE 不会因为"没装 premium"失败

@MatheMatrix MatheMatrix force-pushed the sync/zhong.xian/fixbug/ZSTAC-80103@@2 branch from cc25c39 to e8b3e06 Compare April 21, 2026 07:50
Expose requestCpu/requestMemory on the generated PodInventory so
SDK callers can deserialize the fields returned by ZQL.

Upgrade script adds matching columns on PodVO and backfills
existing pods with request=limit for legacy-equivalent behaviour.

Resolves: ZSTAC-80103

Change-Id: I5b2a9d4e8c6f3b7a1d0e9c5b4a8f2d7e6c1b3a9f
@MatheMatrix MatheMatrix force-pushed the sync/zhong.xian/fixbug/ZSTAC-80103@@2 branch from e8b3e06 to 3696498 Compare April 21, 2026 10:51
@zstack-robot-2
Copy link
Copy Markdown
Collaborator Author

Comment from ye.zou:

Code Review

配套审了 premium !13615,两边一起看了。

本 MR 主要补了:

  • PodVO 的 schema upgrade,新增 requestCpu / requestMemory
  • 历史数据 backfill,保持 legacy pod 的 request = limit 语义
  • SDK PodInventory 暴露新增字段,支撑 ZQL 返回值反序列化

本轮没看到阻塞合入的问题。

结论: APPROVE ✅
回归风险: 低

说明:

  • 新增字段属于向后兼容增量,旧调用方不会因为这次改动被破坏
  • schema + SDK 与配套 premium MR 的持久化/查询链路是对齐的
  • 当前 branch 中 backfill 已使用 COALESCE(...),不会覆盖已有非空值

测试:

  • 未在本地执行编译/集成测试,本结论基于静态 code review
  • 配套 premium MR 已补 request 字段的持久化 / ZQL 查询测试

T7/commit-split: 通过,当前 MR 变更边界清晰

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.

3 participants