-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[storage]: optimize snapshot group creation and deletion logic #2978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: zsv_4.10.28
Are you sure you want to change the base?
Conversation
Walkthrough将删除卷快照组的实现从原有的While循环改为基于ShareFlow/FlowChain的分阶段流程:先并行删除数据卷快照并收集结果,再在条件允许时单独删除根卷快照;引入辅助方法构建删除消息并以NoRollbackFlow封装各步骤,最终通过FlowChain完成回复与错误处理。 Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 分钟 需要重点检查的地方:
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java (2)
216-221: 建议添加对 VM 不存在情况的显式处理当 VM 已被删除时,
rootVolumeUuid将为null,虽然当前代码通过equals()的行为隐式处理了这种情况(不会抛出 NPE),但显式处理会提高代码可读性。String vmUuid = self.getVmInstanceUuid(); String rootVolumeUuid = Q.New(VmInstanceVO.class).eq(VmInstanceVO_.uuid, vmUuid) .select(VmInstanceVO_.rootVolumeUuid).findValue(); -VolumeSnapshotVO rootVolumeSnapshot = snapshots.stream().filter(s -> s.getVolumeUuid().equals(rootVolumeUuid)).findFirst().orElse(null); -snapshots.removeIf(s -> s.getVolumeUuid().equals(rootVolumeUuid)); +VolumeSnapshotVO rootVolumeSnapshot = null; +if (rootVolumeUuid != null) { + rootVolumeSnapshot = snapshots.stream().filter(s -> s.getVolumeUuid().equals(rootVolumeUuid)).findFirst().orElse(null); + snapshots.removeIf(s -> s.getVolumeUuid().equals(rootVolumeUuid)); +}
238-245: 建议使用!r.isSuccess()保持一致性当前使用
r.getError() != null检查错误,但代码库中其他位置(如第 195、363、400 行)使用!r.isSuccess()。建议保持一致的错误检查方式。bus.send(rmsg, new CloudBusCallBack(compl) { @Override public void run(MessageReply r) { - if (r.getError() != null) { + if (!r.isSuccess()) { skipDeleteRootVolumeSnapshot = true; } reply.addResult(new DeleteSnapshotGroupResult(rmsg.getSnapshotUuid(), rmsg.getVolumeUuid(), r.getError())); compl.done(); } });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.java
⚙️ CodeRabbit configuration file
**/*.java: ## 1. API 设计要求
- API 命名:
- API 名称必须唯一,不能重复。
- API 消息类需要继承
APIMessage;其返回类必须继承APIReply或APIEvent,并在注释中用@RestResponse进行标注。- API 消息上必须添加注解
@RestRequest,并满足如下规范:
path:
- 针对资源使用复数形式。
- 当 path 中引用消息类变量时,使用
{variableName}格式。- HTTP 方法对应:
- 查询操作 →
HttpMethod.GET- 更新操作 →
HttpMethod.PUT- 创建操作 →
HttpMethod.POST- 删除操作 →
HttpMethod.DELETE- API 类需要实现
__example__方法以便生成 API 文档,并确保生成对应的 Groovy API Template 与 API Markdown 文件。
2. 命名与格式规范
类名:
- 使用 UpperCamelCase 风格。
- 特殊情况:
- VO/AO/EO 类型类除外。
- 抽象类采用
Abstract或Base前缀/后缀。- 异常类应以
Exception结尾。- 测试类需要以
Test或Case结尾。方法名、参数名、成员变量和局部变量:
- 使用 lowerCamelCase 风格。
常量命名:
- 全部大写,使用下划线分隔单词。
- 要求表达清楚,避免使用含糊或不准确的名称。
包名:
- 统一使用小写,使用点分隔符,每个部分应是一个具有自然语义的英文单词(参考 Spring 框架的结构)。
命名细节:
- 避免在父子类或同一代码块中出现相同名字的成员或局部变量,防止混淆。
- 命名缩写:
- 不允许使用不必要的缩写,如:
AbsSchedulerJob、condi、Fu等。应使用完整单词提升可读性。
3. 编写自解释代码
意图表达:
- 避免使用布尔型参数造成含义不明确。例如:
- 对于
stopAgent(boolean ignoreError),建议拆分为不同函数(如stopAgentIgnoreError()),或使用枚举表达操作类型。- 命名应尽量用完整的单词组合表达意图,并在名称中体现数据类型或用途(例如在常量与变量名称中,将类型词放在末尾)。
注释:
- 代码应尽量做到自解释,对少于两行的说明可以直接写在代码中。
- 对于较长的注释,需要仔细校对并随代码更新,确保内容正确。
- 接口方法不应有多余的修饰符(例如
public),且必须配有有效的 Javadoc 注释。
4. 流程控制和结构优化
if...else 的使用:
- 应尽量减少 if...else 结构的使用,建议:
- 限制嵌套层级最多为两层,且内层不应再出现
else分支。- 尽早返回(Early Return),将条件判断中的处理逻辑提前结束或抽成独立方法。
- 使用 Java Stream 或 Lambda 表达式代替冗长的循环与条件判断。
条件判断:
- if 条件表达不宜过长或过于复杂,必要时可以将条件抽成 boolean 变量描述。
代码块长度:
- 单个 if 代码块不宜超过一屏显示,以提高可读性和后续维护性。
5. 异常处理与日志
- 捕获异常的原则:
- 对于可以通过预检查避免的 RuntimeException(如
NullPointerException、IndexOutOfBoundsException等),不建议使用 try-catch 来进行处理。- 捕获异常应仅用于处理真正的意外情况,不应将异常逻辑当作正常流程控制。
- 在必要时,应继续抛出异常,使上层业务处理者可以转换为用户友好的错误提示。
- 使用 try-with-resources 语法管理资源,确保在 finally 块中正确关闭资源,并避免在 finally 中返回值。
...
Files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
🧠 Learnings (10)
📓 Common learnings
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2360
File: network/src/main/java/org/zstack/network/l3/L3BasicNetwork.java:449-490
Timestamp: 2025-08-04T04:48:19.103Z
Learning: ZStack项目在cherry-pick操作中,即使发现了性能优化机会(如IP地址批量保存的内存优化),也严格遵循不做额外修改的政策,优先保证cherry-pick的完整性和一致性。
Learnt from: ZStack-Robot
Repo: MatheMatrix/zstack PR: 2489
File: storage/src/main/java/org/zstack/storage/snapshot/VolumeTree.java:471-545
Timestamp: 2025-08-22T05:36:40.467Z
Learning: In ZStack项目中,对于核心逻辑相关的代码,团队倾向于暂时不进行重构,即使代码复杂度较高,优先保证核心功能的稳定性。
Learnt from: ZStack-Robot
Repo: MatheMatrix/zstack PR: 2325
File: compute/src/main/java/org/zstack/compute/vm/VmMigrateCallExtensionFlow.java:29-29
Timestamp: 2025-07-24T05:53:10.246Z
Learning: 在ZStack项目的重构过程中,团队采用务实的优先级策略:优先完成影响运行时功能的代码重构,对于注释中的旧引用等非功能性问题可以延后处理,因为这些不会影响系统的实际运行。
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2360
File: compute/src/main/java/org/zstack/compute/vm/StaticIpOperator.java:364-501
Timestamp: 2025-08-04T03:19:07.454Z
Learning: In ZStack project, developers may prefer to keep related validation logic together in a single method (like validateStaticIpTagsInApiMessage with 130+ lines) when the architecture is clear and there's no code reuse, rather than splitting into smaller methods based purely on single responsibility principle.
Learnt from: ZStack-Robot
Repo: MatheMatrix/zstack PR: 2419
File: plugin/sdnController/src/main/java/org/zstack/sdnController/SdnControllerBase.java:986-1067
Timestamp: 2025-08-13T02:31:40.023Z
Learning: 在ZStack项目中,团队倾向于保持统一的业务流程方法不进行拆分,即使方法较长也会维持在单个方法中以保持业务逻辑的完整性。
Learnt from: zstack-robot-2
Repo: MatheMatrix/zstack PR: 2496
File: plugin/sharedMountPointPrimaryStorage/src/main/java/org/zstack/storage/primary/smp/KvmBackend.java:2545-2566
Timestamp: 2025-08-24T07:35:42.793Z
Learning: 在 ZStack 代码库中,当响应类包含数值字段(如 size、actualSize)时,优先使用原始类型(long)而不是包装类型(Long),以避免 NPE 风险和不必要的装箱/拆箱操作。如果 Agent 端可能不设置该字段,应在 Agent 端确保设置默认值,而不是在使用端做 null 检查。
📚 Learning: 2025-08-24T07:56:17.047Z
Learnt from: MatheMatrix
Repo: MatheMatrix/zstack PR: 2496
File: storage/src/main/java/org/zstack/storage/snapshot/VolumeSnapshotCascadeExtension.java:71-73
Timestamp: 2025-08-24T07:56:17.047Z
Learning: In VolumeSnapshotCascadeExtension, the createActionForChildResource method always wraps the context in VolumeSnapshotDeletionStructs when creating child actions, so no backward compatibility with List<VolumeSnapshotInventory> is needed in handleDeletionCleanup.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-14T06:56:19.585Z
Learnt from: zstack-robot-2
Repo: MatheMatrix/zstack PR: 2435
File: storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java:47-47
Timestamp: 2025-08-14T06:56:19.585Z
Learning: 在VolumeSnapshotGroupBase.java中,VmInstanceResourceMetadataManager的注入和SKIP_RESOURCE_ROLLBACK标记虽然在当前版本中未被使用,但这些导入在大型重构PR中是有意为之的,用于保持代码一致性或为后续功能做准备。
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-22T05:20:30.147Z
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2489
File: header/src/main/java/org/zstack/header/storage/snapshot/VolumeSnapshotDeletionStructs.java:5-14
Timestamp: 2025-08-22T05:20:30.147Z
Learning: In VolumeSnapshotDeletionStructs class, String fields for direction and scope are preferred over enum types (DeleteVolumeSnapshotDirection/DeleteVolumeSnapshotScope) as they meet the expected architectural design requirements.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2024-06-10T19:31:27.994Z
Learnt from: AlanJager
Repo: MatheMatrix/zstack PR: 175
File: storage/src/main/java/org/zstack/storage/volume/VolumeBase.java:31-38
Timestamp: 2024-06-10T19:31:27.994Z
Learning: The user has clarified that the `MemorySnapshotGroupExtensionPoint` has been removed and its implementation has been moved to `VolumeSnapshotCreationExtensionPoint`.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-24T06:36:54.519Z
Learnt from: zstack-robot-2
Repo: MatheMatrix/zstack PR: 2496
File: storage/src/main/java/org/zstack/storage/snapshot/VolumeSnapshotCascadeExtension.java:124-129
Timestamp: 2025-08-24T06:36:54.519Z
Learning: In cascade deletion scenarios for VolumeSnapshotCascadeExtension, the default values should be DeleteVolumeSnapshotDirection.Pull and DeleteVolumeSnapshotScope.Chain to maintain backward compatibility with existing cascade deletion logic, rather than using Auto values.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-14T06:48:00.549Z
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2435
File: header/src/main/java/org/zstack/header/storage/snapshot/group/APICheckMemorySnapshotGroupConflictMsg.java:3-7
Timestamp: 2025-08-14T06:48:00.549Z
Learning: 在ZStack项目中,同一包内的类(如VolumeSnapshotGroupVO)不需要显式导入。同时,uuid()辅助方法在API消息类的__example__()方法中可以直接使用,无需静态导入,这是通过项目的构建系统或框架配置实现的。
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-14T06:48:00.549Z
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2435
File: header/src/main/java/org/zstack/header/storage/snapshot/group/APICheckMemorySnapshotGroupConflictMsg.java:3-7
Timestamp: 2025-08-14T06:48:00.549Z
Learning: In the ZStack project, API message classes may not require explicit imports for VolumeSnapshotGroupVO references in APIParam annotations or for the uuid() helper method used in __example__() methods, even when these classes/methods are defined in other packages. The build system or framework appears to handle these references automatically.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-04T03:35:51.225Z
Learnt from: zstack-robot-2
Repo: MatheMatrix/zstack PR: 2360
File: compute/src/main/java/org/zstack/compute/vm/VmNicParamBuilder.java:27-28
Timestamp: 2025-08-04T03:35:51.225Z
Learning: 在 VmNicParamBuilder.buildByVmUuid 方法中,上层调用保证传入的 VM UUID 对应的实例一定存在,因此使用 Q.New(VmInstanceVO.class).eq(VmInstanceVO_.uuid, vmInstanceUuid).find() 查询后不需要进行 null 检查。
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-10T13:42:01.027Z
Learnt from: MatheMatrix
Repo: MatheMatrix/zstack PR: 2410
File: compute/src/main/java/org/zstack/compute/vm/VmInstanceHelper.java:334-356
Timestamp: 2025-08-10T13:42:01.027Z
Learning: 在 ZStack 的 `VmInstanceHelper.validateVmNicParams` 方法中调用 `VmNicParamValidator` 时,不需要对 msg.getType() 返回 null 的情况进行兼容处理,因为 vmType 为 null 的情况已在内部(VmNicParamValidator 或其他地方)得到处理。
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
🔇 Additional comments (1)
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java (1)
223-310: 流程设计合理,正确实现了优化逻辑FlowChain 结构清晰:
- 先并行删除数据卷快照
- 若任一数据卷快照删除失败,则跳过根卷快照删除
- 无论单个删除是否成功,都收集结果并返回
这种设计确保了根卷快照只在所有数据卷快照成功删除后才会被删除,符合 PR 优化目标。
Resolves: ZSV-9792 Change-Id: I6b65736e646e7163777a7872667077756771726d
00febb2 to
86ac154
Compare
There was a problem hiding this 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
🧹 Nitpick comments (3)
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java (3)
216-221: 根卷快照分离逻辑正确,但建议添加 VM 不存在场景的日志当 VM 已被删除时,
rootVolumeUuid将为null,此时equals(null)安全返回false,不会导致 NPE。但建议在rootVolumeUuid为null时添加 debug 日志,便于问题排查。String vmUuid = self.getVmInstanceUuid(); String rootVolumeUuid = Q.New(VmInstanceVO.class).eq(VmInstanceVO_.uuid, vmUuid) .select(VmInstanceVO_.rootVolumeUuid).findValue(); + if (rootVolumeUuid == null) { + logger.debug(String.format("vm[uuid:%s] not found or has no root volume, skip root volume snapshot separation", vmUuid)); + } VolumeSnapshotVO rootVolumeSnapshot = snapshots.stream().filter(s -> s.getVolumeUuid().equals(rootVolumeUuid)).findFirst().orElse(null); snapshots.removeIf(s -> s.getVolumeUuid().equals(rootVolumeUuid));
223-224: 建议为 FlowChain 设置名称以便调试当前
ShareFlowChain未设置名称,而同文件中handleRevert方法(第 343 行)的 FlowChain 设置了有意义的名称。为保持一致性并方便问题排查,建议添加名称。FlowChain chain = new ShareFlowChain(); + chain.setName(String.format("delete-snapshot-group-%s", self.getUuid())); chain.then(new ShareFlow() {
237-245: 建议使用!r.isSuccess()判断失败,保持代码风格一致当前使用
r.getError() != null检查失败,而 ZStack 代码库中更常见的模式是使用!r.isSuccess()(参考第 363 行的写法)。两者功能等价,但建议保持一致性。public void run(MessageReply r) { - if (r.getError() != null) { + if (!r.isSuccess()) { skipDeleteRootVolumeSnapshot = true; } reply.addResult(new DeleteSnapshotGroupResult(rmsg.getSnapshotUuid(), rmsg.getVolumeUuid(), r.getError()));
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.java
⚙️ CodeRabbit configuration file
**/*.java: ## 1. API 设计要求
- API 命名:
- API 名称必须唯一,不能重复。
- API 消息类需要继承
APIMessage;其返回类必须继承APIReply或APIEvent,并在注释中用@RestResponse进行标注。- API 消息上必须添加注解
@RestRequest,并满足如下规范:
path:
- 针对资源使用复数形式。
- 当 path 中引用消息类变量时,使用
{variableName}格式。- HTTP 方法对应:
- 查询操作 →
HttpMethod.GET- 更新操作 →
HttpMethod.PUT- 创建操作 →
HttpMethod.POST- 删除操作 →
HttpMethod.DELETE- API 类需要实现
__example__方法以便生成 API 文档,并确保生成对应的 Groovy API Template 与 API Markdown 文件。
2. 命名与格式规范
类名:
- 使用 UpperCamelCase 风格。
- 特殊情况:
- VO/AO/EO 类型类除外。
- 抽象类采用
Abstract或Base前缀/后缀。- 异常类应以
Exception结尾。- 测试类需要以
Test或Case结尾。方法名、参数名、成员变量和局部变量:
- 使用 lowerCamelCase 风格。
常量命名:
- 全部大写,使用下划线分隔单词。
- 要求表达清楚,避免使用含糊或不准确的名称。
包名:
- 统一使用小写,使用点分隔符,每个部分应是一个具有自然语义的英文单词(参考 Spring 框架的结构)。
命名细节:
- 避免在父子类或同一代码块中出现相同名字的成员或局部变量,防止混淆。
- 命名缩写:
- 不允许使用不必要的缩写,如:
AbsSchedulerJob、condi、Fu等。应使用完整单词提升可读性。
3. 编写自解释代码
意图表达:
- 避免使用布尔型参数造成含义不明确。例如:
- 对于
stopAgent(boolean ignoreError),建议拆分为不同函数(如stopAgentIgnoreError()),或使用枚举表达操作类型。- 命名应尽量用完整的单词组合表达意图,并在名称中体现数据类型或用途(例如在常量与变量名称中,将类型词放在末尾)。
注释:
- 代码应尽量做到自解释,对少于两行的说明可以直接写在代码中。
- 对于较长的注释,需要仔细校对并随代码更新,确保内容正确。
- 接口方法不应有多余的修饰符(例如
public),且必须配有有效的 Javadoc 注释。
4. 流程控制和结构优化
if...else 的使用:
- 应尽量减少 if...else 结构的使用,建议:
- 限制嵌套层级最多为两层,且内层不应再出现
else分支。- 尽早返回(Early Return),将条件判断中的处理逻辑提前结束或抽成独立方法。
- 使用 Java Stream 或 Lambda 表达式代替冗长的循环与条件判断。
条件判断:
- if 条件表达不宜过长或过于复杂,必要时可以将条件抽成 boolean 变量描述。
代码块长度:
- 单个 if 代码块不宜超过一屏显示,以提高可读性和后续维护性。
5. 异常处理与日志
- 捕获异常的原则:
- 对于可以通过预检查避免的 RuntimeException(如
NullPointerException、IndexOutOfBoundsException等),不建议使用 try-catch 来进行处理。- 捕获异常应仅用于处理真正的意外情况,不应将异常逻辑当作正常流程控制。
- 在必要时,应继续抛出异常,使上层业务处理者可以转换为用户友好的错误提示。
- 使用 try-with-resources 语法管理资源,确保在 finally 块中正确关闭资源,并避免在 finally 中返回值。
...
Files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
🧠 Learnings (10)
📓 Common learnings
Learnt from: ZStack-Robot
Repo: MatheMatrix/zstack PR: 2496
File: storage/src/main/java/org/zstack/storage/snapshot/VolumeSnapshotTreeBase.java:1218-1224
Timestamp: 2025-08-24T06:33:10.771Z
Learning: ZStack团队在容量管理相关问题上响应迅速,当发现Pull快照流程中申请容量与释放容量不匹配的问题时,开发人员会及时进行修复以确保主存储容量核算的准确性。
Learnt from: MatheMatrix
Repo: MatheMatrix/zstack PR: 2496
File: storage/src/main/java/org/zstack/storage/snapshot/VolumeSnapshotCascadeExtension.java:71-73
Timestamp: 2025-08-24T07:56:17.047Z
Learning: In VolumeSnapshotCascadeExtension, the createActionForChildResource method always wraps the context in VolumeSnapshotDeletionStructs when creating child actions, so no backward compatibility with List<VolumeSnapshotInventory> is needed in handleDeletionCleanup.
Learnt from: zstack-robot-2
Repo: MatheMatrix/zstack PR: 2496
File: storage/src/main/java/org/zstack/storage/snapshot/VolumeSnapshotCascadeExtension.java:124-129
Timestamp: 2025-08-24T06:36:54.519Z
Learning: In cascade deletion scenarios for VolumeSnapshotCascadeExtension, the default values should be DeleteVolumeSnapshotDirection.Pull and DeleteVolumeSnapshotScope.Chain to maintain backward compatibility with existing cascade deletion logic, rather than using Auto values.
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2360
File: network/src/main/java/org/zstack/network/l3/L3BasicNetwork.java:449-490
Timestamp: 2025-08-04T04:48:19.103Z
Learning: ZStack项目在cherry-pick操作中,即使发现了性能优化机会(如IP地址批量保存的内存优化),也严格遵循不做额外修改的政策,优先保证cherry-pick的完整性和一致性。
Learnt from: ZStack-Robot
Repo: MatheMatrix/zstack PR: 2489
File: storage/src/main/java/org/zstack/storage/snapshot/VolumeTree.java:471-545
Timestamp: 2025-08-22T05:36:40.467Z
Learning: In ZStack项目中,对于核心逻辑相关的代码,团队倾向于暂时不进行重构,即使代码复杂度较高,优先保证核心功能的稳定性。
Learnt from: ZStack-Robot
Repo: MatheMatrix/zstack PR: 2325
File: compute/src/main/java/org/zstack/compute/vm/VmMigrateCallExtensionFlow.java:29-29
Timestamp: 2025-07-24T05:53:10.246Z
Learning: 在ZStack项目的重构过程中,团队采用务实的优先级策略:优先完成影响运行时功能的代码重构,对于注释中的旧引用等非功能性问题可以延后处理,因为这些不会影响系统的实际运行。
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2360
File: compute/src/main/java/org/zstack/compute/vm/StaticIpOperator.java:364-501
Timestamp: 2025-08-04T03:19:07.454Z
Learning: In ZStack project, developers may prefer to keep related validation logic together in a single method (like validateStaticIpTagsInApiMessage with 130+ lines) when the architecture is clear and there's no code reuse, rather than splitting into smaller methods based purely on single responsibility principle.
Learnt from: ZStack-Robot
Repo: MatheMatrix/zstack PR: 2419
File: plugin/sdnController/src/main/java/org/zstack/sdnController/SdnControllerBase.java:986-1067
Timestamp: 2025-08-13T02:31:40.023Z
Learning: 在ZStack项目中,团队倾向于保持统一的业务流程方法不进行拆分,即使方法较长也会维持在单个方法中以保持业务逻辑的完整性。
Learnt from: zstack-robot-2
Repo: MatheMatrix/zstack PR: 2496
File: plugin/sharedMountPointPrimaryStorage/src/main/java/org/zstack/storage/primary/smp/KvmBackend.java:2545-2566
Timestamp: 2025-08-24T07:35:42.793Z
Learning: 在 ZStack 代码库中,当响应类包含数值字段(如 size、actualSize)时,优先使用原始类型(long)而不是包装类型(Long),以避免 NPE 风险和不必要的装箱/拆箱操作。如果 Agent 端可能不设置该字段,应在 Agent 端确保设置默认值,而不是在使用端做 null 检查。
📚 Learning: 2025-08-14T06:56:19.585Z
Learnt from: zstack-robot-2
Repo: MatheMatrix/zstack PR: 2435
File: storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java:47-47
Timestamp: 2025-08-14T06:56:19.585Z
Learning: 在VolumeSnapshotGroupBase.java中,VmInstanceResourceMetadataManager的注入和SKIP_RESOURCE_ROLLBACK标记虽然在当前版本中未被使用,但这些导入在大型重构PR中是有意为之的,用于保持代码一致性或为后续功能做准备。
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-24T07:56:17.047Z
Learnt from: MatheMatrix
Repo: MatheMatrix/zstack PR: 2496
File: storage/src/main/java/org/zstack/storage/snapshot/VolumeSnapshotCascadeExtension.java:71-73
Timestamp: 2025-08-24T07:56:17.047Z
Learning: In VolumeSnapshotCascadeExtension, the createActionForChildResource method always wraps the context in VolumeSnapshotDeletionStructs when creating child actions, so no backward compatibility with List<VolumeSnapshotInventory> is needed in handleDeletionCleanup.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2024-06-10T19:31:27.994Z
Learnt from: AlanJager
Repo: MatheMatrix/zstack PR: 175
File: storage/src/main/java/org/zstack/storage/volume/VolumeBase.java:31-38
Timestamp: 2024-06-10T19:31:27.994Z
Learning: The user has clarified that the `MemorySnapshotGroupExtensionPoint` has been removed and its implementation has been moved to `VolumeSnapshotCreationExtensionPoint`.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-22T05:20:30.147Z
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2489
File: header/src/main/java/org/zstack/header/storage/snapshot/VolumeSnapshotDeletionStructs.java:5-14
Timestamp: 2025-08-22T05:20:30.147Z
Learning: In VolumeSnapshotDeletionStructs class, String fields for direction and scope are preferred over enum types (DeleteVolumeSnapshotDirection/DeleteVolumeSnapshotScope) as they meet the expected architectural design requirements.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-24T06:36:54.519Z
Learnt from: zstack-robot-2
Repo: MatheMatrix/zstack PR: 2496
File: storage/src/main/java/org/zstack/storage/snapshot/VolumeSnapshotCascadeExtension.java:124-129
Timestamp: 2025-08-24T06:36:54.519Z
Learning: In cascade deletion scenarios for VolumeSnapshotCascadeExtension, the default values should be DeleteVolumeSnapshotDirection.Pull and DeleteVolumeSnapshotScope.Chain to maintain backward compatibility with existing cascade deletion logic, rather than using Auto values.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-14T06:48:00.549Z
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2435
File: header/src/main/java/org/zstack/header/storage/snapshot/group/APICheckMemorySnapshotGroupConflictMsg.java:3-7
Timestamp: 2025-08-14T06:48:00.549Z
Learning: 在ZStack项目中,同一包内的类(如VolumeSnapshotGroupVO)不需要显式导入。同时,uuid()辅助方法在API消息类的__example__()方法中可以直接使用,无需静态导入,这是通过项目的构建系统或框架配置实现的。
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-14T06:48:00.549Z
Learnt from: zstack-robot-1
Repo: MatheMatrix/zstack PR: 2435
File: header/src/main/java/org/zstack/header/storage/snapshot/group/APICheckMemorySnapshotGroupConflictMsg.java:3-7
Timestamp: 2025-08-14T06:48:00.549Z
Learning: In the ZStack project, API message classes may not require explicit imports for VolumeSnapshotGroupVO references in APIParam annotations or for the uuid() helper method used in __example__() methods, even when these classes/methods are defined in other packages. The build system or framework appears to handle these references automatically.
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-04T03:35:51.225Z
Learnt from: zstack-robot-2
Repo: MatheMatrix/zstack PR: 2360
File: compute/src/main/java/org/zstack/compute/vm/VmNicParamBuilder.java:27-28
Timestamp: 2025-08-04T03:35:51.225Z
Learning: 在 VmNicParamBuilder.buildByVmUuid 方法中,上层调用保证传入的 VM UUID 对应的实例一定存在,因此使用 Q.New(VmInstanceVO.class).eq(VmInstanceVO_.uuid, vmInstanceUuid).find() 查询后不需要进行 null 检查。
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
📚 Learning: 2025-08-10T13:42:01.027Z
Learnt from: MatheMatrix
Repo: MatheMatrix/zstack PR: 2410
File: compute/src/main/java/org/zstack/compute/vm/VmInstanceHelper.java:334-356
Timestamp: 2025-08-10T13:42:01.027Z
Learning: 在 ZStack 的 `VmInstanceHelper.validateVmNicParams` 方法中调用 `VmNicParamValidator` 时,不需要对 msg.getType() 返回 null 的情况进行兼容处理,因为 vmType 为 null 的情况已在内部(VmNicParamValidator 或其他地方)得到处理。
Applied to files:
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java
🔇 Additional comments (2)
storage/src/main/java/org/zstack/storage/snapshot/group/VolumeSnapshotGroupBase.java (2)
18-19: 导入语句正确支持新的 Flow 架构新增的
ShareFlow、ShareFlowChain以及VmInstanceVO相关导入与下方的流程重构逻辑匹配,用于支持新的基于 Flow 的删除流程。Also applies to: 36-37
300-309: 辅助方法封装良好
buildDeleteVolumeSnapshotMsg方法将消息构建逻辑封装在 ShareFlow 内部,避免了重复代码,且作用域限制在当前流程中,符合最小可见性原则。
Resolves: ZSV-9792
Change-Id: I6b65736e646e7163777a7872667077756771726d
sync from gitlab !8786