Skip to content

<fix>[storage]: exclude deleted volumes from recalculate and sync physical capacity on reconnect#3677

Open
zstack-robot-2 wants to merge 1 commit intomasterfrom
sync/jin.ma/fix/ZSTAC-80937
Open

<fix>[storage]: exclude deleted volumes from recalculate and sync physical capacity on reconnect#3677
zstack-robot-2 wants to merge 1 commit intomasterfrom
sync/jin.ma/fix/ZSTAC-80937

Conversation

@zstack-robot-2
Copy link
Copy Markdown
Collaborator

Root Cause

PrimaryStorageCapacityRecalculator.recalculate() 第78行将 VolumeStatus.Deleted 计入 needCountVolumeStates,Deleted 卷在删除时已归还虚拟容量,但 recalculate() 又将其计入占用,导致双重扣减,存储池分配率异常增长。

次要问题:doConnect() 成功后直接发 RecalculatePrimaryStorageCapacityMsg,未先同步物理容量。

Solution

  1. PrimaryStorageCapacityRecalculator.java: 从 needCountVolumeStates 中去除 VolumeStatus.Deleted
  2. PrimaryStorageBase.java: doConnect() 改用 SyncPrimaryStorageCapacityMsg 替代 RecalculatePrimaryStorageCapacityMsg,确保先同步物理容量再重算

Testing

  • 编译验证通过 (mvn compile -pl storage -am)
  • 代码审查确认改动最小化:2文件6行

Jira

Resolves: ZSTAC-80937

sync from gitlab !9538

…sical capacity on reconnect

Resolves: ZSTAC-80937

Change-Id: I5380a3cb223c675c20418831fffe5c107089b5ea
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 64e8187a-b297-4c75-841f-dc7a045e2270

📥 Commits

Reviewing files that changed from the base of the PR and between 5a29293 and d3137fd.

📒 Files selected for processing (2)
  • storage/src/main/java/org/zstack/storage/primary/PrimaryStorageBase.java
  • storage/src/main/java/org/zstack/storage/primary/PrimaryStorageCapacityRecalculator.java

功能概览

在主存储连接成功流程中,doConnect 方法内发送的容量更新消息从 RecalculatePrimaryStorageCapacityMsg 改为 SyncPrimaryStorageCapacityMsg。此外,计算主存储已用容量时,卷状态过滤器现仅包含 CreatingReady 状态,不再包含 Deleted 状态。

变更内容

同类文件组 / 文件路径 变更摘要
主存储消息类型更新
storage/src/main/java/org/zstack/storage/primary/PrimaryStorageBase.java
将连接成功后的容量同步消息从 RecalculatePrimaryStorageCapacityMsg 更改为 SyncPrimaryStorageCapacityMsg,保持消息的实例化、参数设置及发送流程不变。
容量计算过滤条件调整
storage/src/main/java/org/zstack/storage/primary/PrimaryStorageCapacityRecalculator.java
移除卷状态过滤条件中的 VolumeStatus.Deleted,仅保留 CreatingReady 状态,使已删除卷不再参与已用容量聚合计算。

代码审查工作量评估

🎯 2 (简单) | ⏱️ ~8 分钟

庆祝诗

🐰 消息换新装,同步更高效,
已删卷无声,容量算得清,
小兔欢蹦跳,改进细又妙!

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了主要改动:排除已删除卷的重新计算,以及在重连时同步物理容量。
Description check ✅ Passed 描述清晰地说明了根本原因、解决方案、测试验证和相关的Jira工单,与代码改动相关。

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/jin.ma/fix/ZSTAC-80937

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

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