Skip to content

<fix>[host]: Supports returning cpuCoreNum when getting capacity#4105

Closed
ZStack-Robot wants to merge 16 commits into
4.8.36from
sync/hanyu.liang/fix-78594@@3
Closed

<fix>[host]: Supports returning cpuCoreNum when getting capacity#4105
ZStack-Robot wants to merge 16 commits into
4.8.36from
sync/hanyu.liang/fix-78594@@3

Conversation

@ZStack-Robot
Copy link
Copy Markdown
Collaborator

Backport to 4.8.36.

Original MR: http://dev.zstack.io:9080/zstackio/zstack/-/merge_requests/8458

Resolves: ZSTAC-78594

sync from gitlab !10001

liang-hanyu and others added 11 commits April 14, 2026 14:20
DBImpact

Resolves: ZSTAC-81065

Change-Id: I6563736d6769787876777a63796b697474617a66
…plit-brain

When a management node departs, its VM skip-trace entries were
immediately removed. If VMs were still being started by kvmagent,
the next VM sync would falsely detect them as Stopped and trigger
HA, causing split-brain.

Fix: transfer departed MN skip-trace entries to an orphaned set with
10-minute TTL instead of immediate deletion. VMs in the orphaned set
remain skip-traced until the TTL expires or they are explicitly
continued, preventing false HA triggers during MN restart scenarios.

Resolves: ZSTAC-80821

Change-Id: I3222e260b2d7b33dc43aba0431ce59a788566b34

Conflicts:
	plugin/kvm/src/main/java/org/zstack/kvm/KvmVmSyncPingTask.java
…anup

Resolves: ZSTAC-80821

Change-Id: I59284c4e69f5d2ee357b1836b7c243200e30949a
Resolves: ZSTAC-80821

Change-Id: Ia9a9597feceb96b3e6e22259e2d0be7bde8ae499
<fix>[ha]: defer skip-trace list cleanup on MN departure to prevent split-brain

See merge request zstackio/zstack!9626
<fix>[conf]: bump version to 4.8.37

See merge request zstackio/zstack!9608
DBImpact

Change-Id: I7473677a7265777a616f6d706776706e67626173
Resolves: ZSTAC-69124

Change-Id: I616e64727376796e696d6f6779776e7378727076
(cherry picked from commit 85c9b9a)
stdout and stderr will both write into ssh output

Resolves: ZSTAC-69124

Change-Id: I6b68767166687072756e64776d6d6377746a6a6a
(cherry picked from commit 5bf5b0a)
top is unused after storage migration even if
its snapshot referenced by other volumes.

only skip trash volume when its snapshots are inner snapshot.

Resolves: ZSTAC-71514

Change-Id: I636b6d726d6c757478737869726f6a777a736663
(cherry picked from commit 866b137)
If fast cloning is performed on the data volume, it will result in image cache filtering error, further causing the image cache to be unable to be cleared

Resolves/Related: ZSTAC-71233

Change-Id: I6d716679646d74726e69726b7968636667746b6f
(cherry picked from commit ff9bf21)
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Review Change Stack

Warning

Review limit reached

@MatheMatrix, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 18 minutes and 6 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1c7761f9-6258-478c-953a-fab2e4e99cbc

📥 Commits

Reviewing files that changed from the base of the PR and between 1b8944f and 115ac2b.

📒 Files selected for processing (32)
  • VERSION
  • compute/src/main/java/org/zstack/compute/allocator/HostAllocatorManagerImpl.java
  • conf/db/upgrade/V4.8.37__schema.sql
  • conf/db/upgrade/V4.8.38__schema.sql
  • core/src/main/java/org/zstack/core/ansible/CallBackNetworkChecker.java
  • core/src/main/java/org/zstack/core/ansible/SshChronyConfigChecker.java
  • core/src/main/java/org/zstack/core/ansible/SshFileExistChecker.java
  • core/src/main/java/org/zstack/core/ansible/SshFileMd5Checker.java
  • core/src/main/java/org/zstack/core/ansible/SshFilesMd5Checker.java
  • core/src/main/java/org/zstack/core/ansible/SshFolderMd5Checker.java
  • core/src/main/java/org/zstack/core/ansible/SshYamlChecker.java
  • core/src/main/java/org/zstack/core/ansible/SshYumRepoChecker.java
  • header/src/main/java/org/zstack/header/allocator/HostCapacityInventory.java
  • header/src/main/java/org/zstack/header/allocator/HostCapacityVO.java
  • header/src/main/java/org/zstack/header/allocator/HostCapacityVO_.java
  • header/src/main/java/org/zstack/header/cluster/ReportHostCapacityMessage.java
  • header/src/main/java/org/zstack/header/storage/snapshot/VolumeSnapshotTree.java
  • header/src/main/java/org/zstack/header/storage/snapshot/reference/VolumeSnapshotReferenceInventory.java
  • header/src/main/java/org/zstack/header/storage/snapshot/reference/VolumeSnapshotReferenceVO.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMGlobalConfig.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KvmHostConfigChecker.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KvmVmSyncPingTask.java
  • sdk/src/main/java/org/zstack/sdk/LicenseInventory.java
  • sdk/src/main/java/org/zstack/sdk/license/api/server/RequestLicenseCapacityAction.java
  • storage/src/main/java/org/zstack/storage/snapshot/reference/VolumeSnapshotReferenceUtils.java
  • storage/src/main/java/org/zstack/storage/volume/VolumeBase.java
  • test/src/test/groovy/org/zstack/test/integration/kvm/capacity/CheckHostCapacityWhenAddHostCase.groovy
  • test/src/test/groovy/org/zstack/test/integration/storage/primary/nfs/imagecleaner/imagecache/CleanImageCacheOnPrimaryStorageCase.groovy
  • utils/src/main/java/org/zstack/utils/ssh/Ssh.java
  • utils/src/main/java/org/zstack/utils/ssh/SshCmdHelper.java

Walkthrough

该PR扩展主机容量跟踪系统以支持CPU核心数字段,从KVM代理采集、消息传递、模型映射到数据库持久化的完整链路;同时为License实体添加配额类型字段,并调整License容量请求的资源类型验证规则。

Changes

Host Capacity and License Enhancements

Layer / File(s) Summary
Data Model and Contract Changes
header/src/main/java/org/zstack/header/allocator/HostCapacityVO.java, header/src/main/java/org/zstack/header/allocator/HostCapacityInventory.java, header/src/main/java/org/zstack/header/allocator/HostCapacityVO_.java, header/src/main/java/org/zstack/header/cluster/ReportHostCapacityMessage.java, plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java
HostCapacityVO、HostCapacityInventory、ReportHostCapacityMessage和KVMAgentCommands.HostCapacityResponse中均新增cpuCoreNum字段及其访问器;HostCapacityVO_提供JPA元模型支持。
Host Capacity Integration and Persistence
plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java, compute/src/main/java/org/zstack/compute/allocator/HostAllocatorManagerImpl.java
KVMHost在上报容量时将HostCapacityResponse的cpuCoreNum转发到ReportHostCapacityMessage;HostAllocatorManager在创建和更新HostCapacityVO时赋值该字段,并在needUpdateCapacity中新增cpuCoreNum变更检测条件。
License Capacity Enhancements
sdk/src/main/java/org/zstack/sdk/LicenseInventory.java, sdk/src/main/java/org/zstack/sdk/license/api/server/RequestLicenseCapacityAction.java
LicenseInventory新增quotaType字段和访问器;RequestLicenseCapacityAction的resourceUuid验证值从CPU更新为CPU_Socket和CPU_Core。
Database Schema Migration and Testing
conf/db/upgrade/V4.8.36__schema.sql, test/src/test/groovy/org/zstack/test/integration/kvm/capacity/CheckHostCapacityWhenAddHostCase.groovy
数据库迁移脚本为HostCapacityVO添加cpuCoreNum列(unsigned int),为LicenseHistoryVO添加quotaType列(varchar);集成测试导入必要的查询工具,在模拟响应中设置cpuCoreNum=20,并验证该值被正确持久化。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 小白添新功能,CPU核心数齐跟踪,
从代理到存储,链路完善又通畅,
License配额类型新花样,
数据库迁移稳稳当,测试验证放心想!✨

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰准确地反映了主要变更内容:添加返回 cpuCoreNum 功能。
Description check ✅ Passed 描述与变更集相关,说明这是针对 4.8.36 的 backport,包含原始 MR 链接和问题编号。
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/hanyu.liang/fix-78594@@3

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

Resolves: ZSTAC-76704

Change-Id: I6d66726c636e6e707076667772707a7578777379
(cherry picked from commit 6efc547)
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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@conf/db/upgrade/V4.8.36__schema.sql`:
- Line 47: Alter the HostCapacityVO change to explicitly target the zstack
schema and follow a safe migration: add zstack.HostCapacityVO.cpuCoreNum as int
unsigned NULL DEFAULT 0, run a backfill query to populate historical rows (e.g.,
set cpuCoreNum = 0 where NULL), then alter zstack.HostCapacityVO to modify
cpuCoreNum to NOT NULL DEFAULT 0; also replace the SSOClientAttributeVO
timestamp defaults that use '0000-00-00 00:00:00' by setting
SSOClientAttributeVO.createDate and SSOClientAttributeVO.lastOpDate to DEFAULT
CURRENT_TIMESTAMP (and add ON UPDATE CURRENT_TIMESTAMP for lastOpDate if
intended) to remove the forbidden zero-date defaults.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 131f1c6c-6f5f-4042-a1be-49086eced651

📥 Commits

Reviewing files that changed from the base of the PR and between 97a38fa and 1b8944f.

📒 Files selected for processing (11)
  • compute/src/main/java/org/zstack/compute/allocator/HostAllocatorManagerImpl.java
  • conf/db/upgrade/V4.8.36__schema.sql
  • header/src/main/java/org/zstack/header/allocator/HostCapacityInventory.java
  • header/src/main/java/org/zstack/header/allocator/HostCapacityVO.java
  • header/src/main/java/org/zstack/header/allocator/HostCapacityVO_.java
  • header/src/main/java/org/zstack/header/cluster/ReportHostCapacityMessage.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java
  • sdk/src/main/java/org/zstack/sdk/LicenseInventory.java
  • sdk/src/main/java/org/zstack/sdk/license/api/server/RequestLicenseCapacityAction.java
  • test/src/test/groovy/org/zstack/test/integration/kvm/capacity/CheckHostCapacityWhenAddHostCase.groovy

Comment thread conf/db/upgrade/V4.8.36__schema.sql Outdated
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `zstack`.`LicenseHistoryVO` ADD COLUMN `quotaType` varchar(64) DEFAULT 'None';
ALTER TABLE HostCapacityVO ADD cpuCoreNum int unsigned NOT NULL DEFAULT 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n 'ALTER TABLE.*HostCapacityVO|cpuCoreNum|NOT NULL' conf/db/upgrade/V4.8.36__schema.sql

Repository: MatheMatrix/zstack

Length of output: 1659


🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="conf/db/upgrade/V4.8.36__schema.sql"
echo "=== file line count ==="
wc -l "$FILE"
echo "=== context around cpuCoreNum add (lines 35-70) ==="
nl -ba "$FILE" | sed -n '35,70p'
echo "=== all occurrences of DEFAULT '0000-00-00 00:00:00' ==="
rg -n "DEFAULT '0000-00-00 00:00:00'" "$FILE" || true
echo "=== occurrences of HostCapacityVO in this file ==="
rg -n "HostCapacityVO" "$FILE" || true
echo "=== occurrences of SSOClientAttributeVO in this file ==="
rg -n "SSOClientAttributeVO" "$FILE" || true

Repository: MatheMatrix/zstack

Length of output: 238


🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="conf/db/upgrade/V4.8.36__schema.sql"
echo "=== file line count ==="
wc -l "$FILE"
echo "=== context around cpuCoreNum add (lines 35-70) ==="
nl -ba "$FILE" | sed -n '35,70p'
echo "=== all occurrences of DEFAULT '0000-00-00 00:00:00' ==="
rg -n "DEFAULT '0000-00-00 00:00:00'" "$FILE" || true
echo "=== occurrences of HostCapacityVO in this file ==="
rg -n "HostCapacityVO" "$FILE" || true
echo "=== occurrences of SSOClientAttributeVO in this file ==="
rg -n "SSOClientAttributeVO" "$FILE" || true

Repository: MatheMatrix/zstack

Length of output: 238


🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="conf/db/upgrade/V4.8.36__schema.sql"
echo "=== context around cpuCoreNum add (lines 35-70) ==="
cat -n "$FILE" | sed -n '35,70p'
echo "=== all occurrences of DEFAULT '0000-00-00 00:00:00' ==="
rg -n "DEFAULT '0000-00-00 00:00:00'" "$FILE" || true
echo "=== occurrences of HostCapacityVO in this file ==="
rg -n "HostCapacityVO" "$FILE" || true
echo "=== occurrences of SSOClientAttributeVO in this file ==="
rg -n "SSOClientAttributeVO" "$FILE" || true

Repository: MatheMatrix/zstack

Length of output: 2270


🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="conf/db/upgrade/V4.8.36__schema.sql"
echo "=== context around cpuCoreNum add (lines 35-70) ==="
cat -n "$FILE" | sed -n '35,70p'
echo "=== all occurrences of DEFAULT '0000-00-00 00:00:00' ==="
rg -n "DEFAULT '0000-00-00 00:00:00'" "$FILE" || true
echo "=== occurrences of HostCapacityVO in this file ==="
rg -n "HostCapacityVO" "$FILE" || true
echo "=== occurrences of SSOClientAttributeVO in this file ==="
rg -n "SSOClientAttributeVO" "$FILE" || true

Repository: MatheMatrix/zstack

Length of output: 2270


修复 conf/db/upgrade/V4.8.36__schema.sql:补齐 zstack schema、对历史数据先回填再收敛 NOT NULL,并移除 DEFAULT '0000-00-00 00:00:00'

  • 第47行当前写法 ALTER TABLE HostCapacityVO ... ADD cpuCoreNum ... NOT NULL DEFAULT 0 未显式限定 zstack schema,且未按规范先处理历史数据再收敛为 NOT NULL,存在升级风险。

    🛠 建议修正
    -ALTER TABLE HostCapacityVO ADD cpuCoreNum int unsigned NOT NULL DEFAULT 0;
    +ALTER TABLE `zstack`.`HostCapacityVO` ADD COLUMN `cpuCoreNum` int unsigned DEFAULT NULL;
    +UPDATE `zstack`.`HostCapacityVO` SET `cpuCoreNum` = 0 WHERE `cpuCoreNum` IS NULL;
    +ALTER TABLE `zstack`.`HostCapacityVO` MODIFY COLUMN `cpuCoreNum` int unsigned NOT NULL DEFAULT 0;
  • 第60-61行:SSOClientAttributeVO.lastOpDateSSOClientAttributeVO.createDate 使用 DEFAULT '0000-00-00 00:00:00',违反禁用项要求,应替换为 DEFAULT CURRENT_TIMESTAMP(并与 ON UPDATE 语义一致)。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ALTER TABLE HostCapacityVO ADD cpuCoreNum int unsigned NOT NULL DEFAULT 0;
ALTER TABLE `zstack`.`HostCapacityVO` ADD COLUMN `cpuCoreNum` int unsigned DEFAULT NULL;
UPDATE `zstack`.`HostCapacityVO` SET `cpuCoreNum` = 0 WHERE `cpuCoreNum` IS NULL;
ALTER TABLE `zstack`.`HostCapacityVO` MODIFY COLUMN `cpuCoreNum` int unsigned NOT NULL DEFAULT 0;
🤖 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 `@conf/db/upgrade/V4.8.36__schema.sql` at line 47, Alter the HostCapacityVO
change to explicitly target the zstack schema and follow a safe migration: add
zstack.HostCapacityVO.cpuCoreNum as int unsigned NULL DEFAULT 0, run a backfill
query to populate historical rows (e.g., set cpuCoreNum = 0 where NULL), then
alter zstack.HostCapacityVO to modify cpuCoreNum to NOT NULL DEFAULT 0; also
replace the SSOClientAttributeVO timestamp defaults that use '0000-00-00
00:00:00' by setting SSOClientAttributeVO.createDate and
SSOClientAttributeVO.lastOpDate to DEFAULT CURRENT_TIMESTAMP (and add ON UPDATE
CURRENT_TIMESTAMP for lastOpDate if intended) to remove the forbidden zero-date
defaults.

@MatheMatrix MatheMatrix force-pushed the sync/hanyu.liang/fix-78594@@3 branch from 1b8944f to c442200 Compare May 26, 2026 08:38
MaJin1996 and others added 4 commits May 27, 2026 02:36
<fix>[backport]: cherry-pick fixes to 4.8.38 (ZSTAC-69412, ZSTAC-74250)

See merge request zstackio/zstack!9997
<fix>[imagecache]: fix unable to clear image cache

See merge request zstackio/zstack!9999
fix(storage): markSnapshotAsVolume before delete origin volume bits

See merge request zstackio/zstack!9998
Resolves: ZSTAC-77257

Change-Id: I737577257765547655441897574646678757a7a734578
(cherry picked from commit 9c99f99)
@MatheMatrix
Copy link
Copy Markdown
Owner

Comment from gitlab:

自上次添加REVIEWED标签(2026-05-27 18:08:48.000Z)后, 有新的COMMIT更新(2026-05-28 10:15:28.669Z), 所以移除了REVIEWED标签

@MatheMatrix MatheMatrix force-pushed the sync/hanyu.liang/fix-78594@@3 branch from c442200 to 115ac2b Compare May 28, 2026 02:15
@ZStack-Robot ZStack-Robot deleted the sync/hanyu.liang/fix-78594@@3 branch May 28, 2026 05:34
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.

6 participants