-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[storage]: Initialize controller in activeIscsiVolume when null #2623
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: 5.4.0
Are you sure you want to change the base?
Conversation
Walkthrough调整 Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml) Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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: 1
🧹 Nitpick comments (2)
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java (2)
14-14
: 参数命名避免缩写,提升可读性与一致性。
vo
建议命名为primaryStorage
或primaryStorageVO
,符合“命名缩写不应不必要使用”的规范。示例:
- void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo); + void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO primaryStorage);
14-14
: 补充 Javadoc,明确 null 约束与行为。接口方法要求配有效 Javadoc;同时需要说明
primaryStorage
是否允许为 null,以及“当 controller 为 null 时初始化”的具体语义。可参考上条 diff 中的注释块。
📜 Review details
Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.*
⚙️ CodeRabbit configuration file
**/*.*
: - 代码里不应当有有中文,包括报错、注释等都应当使用正确的、无拼写错误的英文来写
Files:
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java
**/*.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()
),或使用枚举表达操作类型。- 命名应尽量用完整的单词组合表达意图,并在名称中体现数据类型或用途(例如在常量与变量名称中,将类型词放在末尾)。
- 避免使用魔法值(Magic Value):
直接使用未经定义的数值或字符串(如 if (status == 5))应替换为枚举或常量。
示例:
// 错误示例:魔法值
if (user.getStatus() == 5) { ... }
// 正确示例:常量或枚举
public static final int STATUS_ACTIVE = 5;
if (user.getStatus() == STATUS_ACTIVE) { ... }
// 或使用枚举
enum UserStatus { ACTIVE, INACTIVE }
注释:
- 代码应尽量做到自解释,对少于两行的说明可以直接写在代码中。
- 对于较长的注释,需要仔细校对并随代码更新,确保内容正确。
- 接口方法不应有多余的修饰符(例如
public
),且必须配有有效的 Javadoc 注释。
4. 流程控制和结构优化
if...else 的使用:
- 应尽量减少 if...else 结构的使用,建议:
- 限制嵌套层级最多为两层,且内层不应再出现
else
分支。- 尽早返回(Early Return),将条件判断中的处理逻辑提前结束或抽成独立方法。
- 使用 Java Stream 或 Lambda 表达式代替冗长的循环与条件判断。
条件判断:
- if 条件表达不宜过长或过于复杂,必要时可以将条件抽成 boolean 变量描述。
代码块长度:
...
Files:
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java
🔇 Additional comments (1)
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java (1)
14-14
: 确认:所有实现类与调用点已迁移到 activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo)仓库搜索未返回匹配(先前脚本输出为空),无法确认是否存在残留的旧三参调用或未更新的实现。请在仓库根目录运行并回传输出:
rg -n --hidden -S --type=java 'BlockExternalPrimaryStorageFactory|activeIscsiVolume' -C2 || true rg -nP --type=java -U 'activeIscsiVolume\s*\([^)]{0,400}\)' -C2 || true
BlockExternalPrimaryStorageBackend getBlockExternalPrimaryStorageBackend(PrimaryStorageVO vo); | ||
|
||
void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable); | ||
void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo); |
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.
🛠️ Refactor suggestion
这是破坏性接口变更;请改为真正“重载”,并保持二进制兼容。
PR 说明称“新增重载方法”,但当前是直接替换签名,这会破坏所有实现类与三方插件(运行期易触发 NoSuchMethodError)。根据“向后兼容原则”,保留旧签名,并以 default 方式新增重载。
建议修改:
- void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo);
+ // Keep the original abstract method for ABI compatibility
+ void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable);
+
+ /**
+ * Activate an iSCSI volume so the host can access it.
+ *
+ * @param clientIqn initiator IQN of the client host
+ * @param vol volume to be activated
+ * @param shareable whether the volume is shareable
+ * @param primaryStorage PrimaryStorageVO of the target primary storage; may be null
+ */
+ default void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO primaryStorage) {
+ // Default to legacy behavior to avoid breaking existing implementors.
+ activeIscsiVolume(clientIqn, vol, shareable);
+ }
📝 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.
void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO vo); | |
// Keep the original abstract method for ABI compatibility | |
void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable); | |
/** | |
* Activate an iSCSI volume so the host can access it. | |
* | |
* @param clientIqn initiator IQN of the client host | |
* @param vol volume to be activated | |
* @param shareable whether the volume is shareable | |
* @param primaryStorage PrimaryStorageVO of the target primary storage; may be null | |
*/ | |
default void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable, PrimaryStorageVO primaryStorage) { | |
// Default to legacy behavior to avoid breaking existing implementors. | |
activeIscsiVolume(clientIqn, vol, shareable); | |
} |
🤖 Prompt for AI Agents
In
storage/src/main/java/org/zstack/storage/addon/primary/BlockExternalPrimaryStorageFactory.java
around line 14, the interface method signature was changed which breaks binary
compatibility; restore the original abstract method signature void
activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean shareable,
PrimaryStorageVO vo); and add the new overloaded method as a default method
(e.g., void activeIscsiVolume(String clientIqn, BaseVolumeInfo vol, boolean
shareable, PrimaryStorageVO vo, /*new params*/)) that delegates to the original
method (or vice versa depending on parameter direction) so existing implementors
keep working and new callers can use the overload without breaking runtime
compatibility.
Add overloaded method with PrimaryStorageVO parameter Initialize controller in activeIscsiVolume when null Resolves: ZSTAC-77315 Change-Id: I75656f6178726675636f6d63656b666873786d62
5ba0b45
to
bdffcb3
Compare
Add overloaded method with PrimaryStorageVO parameter
Initialize controller in activeIscsiVolume when null
Resolves: ZSTAC-77315
Change-Id: I75656f6178726675636f6d63656b666873786d62
sync from gitlab !8410