Skip to content

Conversation

@zstack-robot-1
Copy link
Collaborator

support thirdparty_ceph to bm root volume

Resolves: ZSTAC-73396

Change-Id: I6f6f616777677a6f74696c6c736c737a626f7863
(cherry picked from commit 827e880)

sync from gitlab !9046

@coderabbitai
Copy link

coderabbitai bot commented Jan 21, 2026

功能概述

本次变更在数据库升级脚本中新增存储过程以支持裸金属实例配置网卡的数据迁移,在Ceph主存储响应类中扩展卷相关字段,并新增对应的错误代码常量。

变更内容

代码群组 / 文件 变更描述
数据库架构升级
conf/db/upgrade/V5.5.6__schema.sql
新增 UpdateBareMetal2InstanceProvisionNicVO 存储过程,实现事务化升级流程:条件性添加 instanceUuid、isPrimaryProvisionNic 列,迁移现有数据,调整外键约束,确保幂等性
Ceph存储响应扩展
plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java
在 CloneRsp 嵌套类中添加 volumeId 和 volumeStatus 公开字段及其访问器方法,新增 SystemTagVO、VmInstanceVO 等相关类型导入
错误代码常量
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
扩展 CloudOperationsErrorCode 类,新增两个 Ceph 主存储资源错误代码常量(10053、10054)

代码审查工作量估算

🎯 3 (中等复杂度) | ⏱️ ~20 分钟

庆祝诗

🐰 数据库迁移新程序,
卷ID字段已备好,
错误代码齐整齐,
Ceph存储更完善,
兔子欢呼蹦蹦跳!🎉

🚥 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 标题格式遵循[scope]: ,长度54个字符(≤72字符),准确概括了主要更改:为裸机根卷添加第三方Ceph支持。
Description check ✅ Passed 描述与变更集相关,明确指出支持第三方Ceph用于裸机根卷,并包含JIRA问题编号和变更来源信息。

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

✨ Finishing touches
  • 📝 Generate docstrings

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.40.5)
plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

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

Copy link

@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: 2

🤖 Fix all issues with AI agents
In `@conf/db/upgrade/V5.5.6__schema.sql`:
- Around line 10-83: Add a guard to avoid re-creating the stored procedure and
to avoid dropping a non-existent FK: insert DROP PROCEDURE IF EXISTS
UpdateBareMetal2InstanceProvisionNicVO; before CREATE PROCEDURE
UpdateBareMetal2InstanceProvisionNicVO(), and replace the unconditional ALTER
TABLE ... DROP FOREIGN KEY `fkBareMetal2InstanceProvisionNicVOInstanceVO` on
table `BareMetal2InstanceProvisionNicVO` with a check against
INFORMATION_SCHEMA.TABLE_CONSTRAINTS (or KEY_COLUMN_USAGE) for constraint_name =
'fkBareMetal2InstanceProvisionNicVOInstanceVO' and only execute the DROP FOREIGN
KEY when that check shows the constraint exists; keep all work inside the same
transaction and leave the final DROP PROCEDURE IF EXISTS
UpdateBareMetal2InstanceProvisionNicVO as-is.

In
`@plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageCheckInstanceTypeExtensionPoint.java`:
- Around line 1-13: 为 CephPrimaryStorageCheckInstanceTypeExtensionPoint
接口的四个方法添加完整的 Javadoc 注释:为 isSupportCloneByThirdParty(String
uuid)、convertToBlockVolume(VolumeVO vo)、isBlockVolume(String uuid) 和
populateBlockVolumeDetails(String uuid, String volumeId, String volumeStatus)
分别说明方法用途、每个参数含义、返回值语义(明确 Boolean 返回值是否可以为 null,以及 true/false 含义)、可能的异常或副作用,并在
convertToBlockVolume 说明对传入 VolumeVO 的修改行为;确保注释简洁并遵循项目 Javadoc 风格。

Comment on lines +10 to +92
DELIMITER $$

CREATE PROCEDURE UpdateBareMetal2InstanceProvisionNicVO()
BEGIN
DECLARE instanceUuid_exists INT;
DECLARE isPrimaryProvisionNic_exists_in_ProvisionNicVO INT;
DECLARE isPrimaryProvisionNic_exists_in_ChassisNicVO INT;

DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'An error occurred during the update process.';
END;

START TRANSACTION;

SELECT COUNT(*)
INTO instanceUuid_exists
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'zstack'
AND TABLE_NAME = 'BareMetal2InstanceProvisionNicVO'
AND COLUMN_NAME = 'instanceUuid';

IF instanceUuid_exists = 0 THEN
CALL ADD_COLUMN('BareMetal2InstanceProvisionNicVO', 'instanceUuid', 'VARCHAR(32)', FALSE, '');

UPDATE `zstack`.`BareMetal2InstanceProvisionNicVO`
SET `instanceUuid` = `uuid`;

ALTER TABLE `zstack`.`BareMetal2InstanceProvisionNicVO`
DROP FOREIGN KEY `fkBareMetal2InstanceProvisionNicVOInstanceVO`;

CALL ADD_CONSTRAINT('BareMetal2InstanceProvisionNicVO', 'fkBareMetal2InstanceProvisionNicVOInstanceVO',
'instanceUuid', 'BareMetal2InstanceVO', 'uuid', 'CASCADE');

UPDATE `zstack`.`BareMetal2InstanceProvisionNicVO`
SET `uuid` = REPLACE(UUID(), '-', '');
END IF;

SELECT COUNT(*)
INTO isPrimaryProvisionNic_exists_in_ProvisionNicVO
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'zstack'
AND TABLE_NAME = 'BareMetal2InstanceProvisionNicVO'
AND COLUMN_NAME = 'isPrimaryProvisionNic';

IF isPrimaryProvisionNic_exists_in_ProvisionNicVO = 0 THEN
CALL ADD_COLUMN('BareMetal2InstanceProvisionNicVO', 'isPrimaryProvisionNic', 'BOOLEAN', FALSE, FALSE);

UPDATE `zstack`.`BareMetal2InstanceProvisionNicVO`
SET `isPrimaryProvisionNic` = TRUE;
END IF;

SELECT COUNT(*)
INTO isPrimaryProvisionNic_exists_in_ChassisNicVO
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'zstack'
AND TABLE_NAME = 'BareMetal2ChassisNicVO'
AND COLUMN_NAME = 'isPrimaryProvisionNic';

IF isPrimaryProvisionNic_exists_in_ChassisNicVO = 0 THEN
CALL ADD_COLUMN('BareMetal2ChassisNicVO', 'isPrimaryProvisionNic', 'BOOLEAN', FALSE, FALSE);

UPDATE `zstack`.`BareMetal2ChassisNicVO`
SET `isPrimaryProvisionNic` = TRUE
WHERE `isProvisionNic` = TRUE;
END IF;

COMMIT;
END$$

DELIMITER ;
CALL UpdateBareMetal2InstanceProvisionNicVO();
DROP PROCEDURE IF EXISTS UpdateBareMetal2InstanceProvisionNicVO;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -name "V5.5.6__schema.sql" -type f

Repository: MatheMatrix/zstack

Length of output: 98


🏁 Script executed:

find . -path "*/db/upgrade/*.sql" -type f | head -20

Repository: MatheMatrix/zstack

Length of output: 777


🏁 Script executed:

rg -l "ADD_COLUMN|ADD_CONSTRAINT" --type sql

Repository: MatheMatrix/zstack

Length of output: 662


🏁 Script executed:

cat -n ./conf/db/upgrade/V5.5.6__schema.sql | head -100

Repository: MatheMatrix/zstack

Length of output: 3734


🏁 Script executed:

rg -A 20 "CREATE PROCEDURE ADD_COLUMN" --type sql

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

rg -A 20 "CREATE PROCEDURE ADD_CONSTRAINT" --type sql

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

rg "CREATE PROCEDURE \`?ADD_COLUMN\`?" --type sql -A 5

Repository: MatheMatrix/zstack

Length of output: 445


🏁 Script executed:

rg "DROP PROCEDURE IF EXISTS" ./conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 126


🏁 Script executed:

rg -B 5 -A 5 "DROP FOREIGN KEY" ./conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 565


🏁 Script executed:

rg -B 5 -A 10 "DROP FOREIGN KEY" ./conf/db/upgrade/*.sql | head -100

Repository: MatheMatrix/zstack

Length of output: 9340


升级脚本需添加过程防护与外键删除存在性检查

过程的创建前缺少 DROP PROCEDURE IF EXISTS。若升级过程中抛错未执行到末尾的 DROP PROCEDURE,二次执行会因为同名存储过程已存在而失败。同时第39-40行 DROP FOREIGN KEY 在约束不存在时会直接报错中断升级。建议在 CREATE PROCEDURE 前添加 DROP PROCEDURE IF EXISTS,并在删外键前通过 INFORMATION_SCHEMA.TABLE_CONSTRAINTS 判断约束存在性。

建议修改
-DELIMITER $$
+DELIMITER $$
+DROP PROCEDURE IF EXISTS UpdateBareMetal2InstanceProvisionNicVO$$
 CREATE PROCEDURE UpdateBareMetal2InstanceProvisionNicVO()
 BEGIN
     DECLARE instanceUuid_exists INT;
+    DECLARE fk_bm2_provisionnic_instancevo_exists INT;
     DECLARE isPrimaryProvisionNic_exists_in_ProvisionNicVO INT;
     DECLARE isPrimaryProvisionNic_exists_in_ChassisNicVO INT;
-        ALTER TABLE `zstack`.`BareMetal2InstanceProvisionNicVO`
-        DROP FOREIGN KEY `fkBareMetal2InstanceProvisionNicVOInstanceVO`;
+        SELECT COUNT(*)
+            INTO fk_bm2_provisionnic_instancevo_exists
+            FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
+            WHERE TABLE_SCHEMA = 'zstack'
+              AND TABLE_NAME = 'BareMetal2InstanceProvisionNicVO'
+              AND CONSTRAINT_NAME = 'fkBareMetal2InstanceProvisionNicVOInstanceVO'
+              AND CONSTRAINT_TYPE = 'FOREIGN KEY';
+
+        IF fk_bm2_provisionnic_instancevo_exists > 0 THEN
+            ALTER TABLE `zstack`.`BareMetal2InstanceProvisionNicVO`
+            DROP FOREIGN KEY `fkBareMetal2InstanceProvisionNicVOInstanceVO`;
+        END IF;
🤖 Prompt for AI Agents
In `@conf/db/upgrade/V5.5.6__schema.sql` around lines 10 - 83, Add a guard to
avoid re-creating the stored procedure and to avoid dropping a non-existent FK:
insert DROP PROCEDURE IF EXISTS UpdateBareMetal2InstanceProvisionNicVO; before
CREATE PROCEDURE UpdateBareMetal2InstanceProvisionNicVO(), and replace the
unconditional ALTER TABLE ... DROP FOREIGN KEY
`fkBareMetal2InstanceProvisionNicVOInstanceVO` on table
`BareMetal2InstanceProvisionNicVO` with a check against
INFORMATION_SCHEMA.TABLE_CONSTRAINTS (or KEY_COLUMN_USAGE) for constraint_name =
'fkBareMetal2InstanceProvisionNicVOInstanceVO' and only execute the DROP FOREIGN
KEY when that check shows the constraint exists; keep all work inside the same
transaction and leave the final DROP PROCEDURE IF EXISTS
UpdateBareMetal2InstanceProvisionNicVO as-is.

Comment on lines 1 to 13
package org.zstack.storage.ceph.primary;

import org.zstack.header.volume.VolumeVO;

public interface CephPrimaryStorageCheckInstanceTypeExtensionPoint {
Boolean isSupportCloneByThirdParty(String uuid);

void convertToBlockVolume(VolumeVO vo);

Boolean isBlockVolume(String uuid);

void populateBlockVolumeDetails(String uuid, String volumeId, String volumeStatus);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

接口方法必须配有 Javadoc 注释

编码规范明确要求:接口方法必须配有有效的 Javadoc 注释。当前接口的所有 4 个方法均缺少 Javadoc,需要补齐每个方法的用途、参数含义与返回值约定,特别是明确 Boolean 返回类型是否允许为 null

💡 建议补充注释示例
 public interface CephPrimaryStorageCheckInstanceTypeExtensionPoint {
+    /**
+     * 检查是否支持通过第三方进行克隆操作
+     * `@param` uuid 卷 UUID
+     * `@return` true 表示支持,false 表示不支持
+     */
     Boolean isSupportCloneByThirdParty(String uuid);
 
+    /**
+     * 将卷转换为块卷语义
+     * `@param` vo 卷对象
+     */
     void convertToBlockVolume(VolumeVO vo);
 
+    /**
+     * 检查卷是否为块卷
+     * `@param` uuid 卷 UUID
+     * `@return` true 表示为块卷,false 表示不是块卷
+     */
     Boolean isBlockVolume(String uuid);
 
+    /**
+     * 填充第三方块卷的详细信息
+     * `@param` uuid 卷 UUID
+     * `@param` volumeId 卷 ID
+     * `@param` volumeStatus 卷状态
+     */
     void populateBlockVolumeDetails(String uuid, String volumeId, String volumeStatus);
 }
🤖 Prompt for AI Agents
In
`@plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageCheckInstanceTypeExtensionPoint.java`
around lines 1 - 13, 为 CephPrimaryStorageCheckInstanceTypeExtensionPoint
接口的四个方法添加完整的 Javadoc 注释:为 isSupportCloneByThirdParty(String
uuid)、convertToBlockVolume(VolumeVO vo)、isBlockVolume(String uuid) 和
populateBlockVolumeDetails(String uuid, String volumeId, String volumeStatus)
分别说明方法用途、每个参数含义、返回值语义(明确 Boolean 返回值是否可以为 null,以及 true/false 含义)、可能的异常或副作用,并在
convertToBlockVolume 说明对传入 VolumeVO 的修改行为;确保注释简洁并遵循项目 Javadoc 风格。

@MatheMatrix MatheMatrix force-pushed the sync/jin.shen/feature-81282@@3 branch 2 times, most recently from 70f7555 to 7a04482 Compare January 22, 2026 09:46
support thirdparty_ceph to bm root volume

Resolves: ZSTAC-73396

Change-Id: I6f6f616777677a6f74696c6c736c737a626f7863
(cherry picked from commit 827e880)
@MatheMatrix MatheMatrix force-pushed the sync/jin.shen/feature-81282@@3 branch from 7a04482 to 571dfb1 Compare January 22, 2026 15:22
Copy link

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java (1)

488-517: CloneRsp 新增字段 volumeIdvolumeStatus 未被实际使用,需补齐实现或移除

新增的字段已定义 getter/setter,但存在不完整的实现问题:

  • CephPrimaryStorageSimulator 创建响应时未填充这两个字段
  • 所有 5 处 success(CloneRsp) 回调均未访问这两个字段,仅使用 sizeactualSizeinstallPath

需要明确:这些字段是否在 ceph-agent 侧的实现中被填充?如果需要使用,请确保:

  1. 模拟器和实际 agent 都正确填充这两个字段
  2. 消费端回调实际处理这两个字段
    否则应移除这些未使用的字段,避免代码冗余。
🤖 Fix all issues with AI agents
In `@conf/db/upgrade/V5.5.6__schema.sql`:
- Around line 54-56: Before changing BareMetal2InstanceProvisionNicVO.uuid,
update the referencing column BareMetal2BondingNicRefVO.provisionNicUuid to the
new UUIDs to preserve FK consistency: for each row being modified in
BareMetal2InstanceProvisionNicVO (uuid), perform an UPDATE of
BareMetal2BondingNicRefVO using an INNER JOIN to match the old uuid and set
provisionNicUuid to the new generated uuid; do this inside the same transaction
and alongside the UPDATE of BareMetal2InstanceProvisionNicVO.uuid to ensure
atomicity and avoid FK breakage (refer to BareMetal2InstanceProvisionNicVO.uuid,
BareMetal2BondingNicRefVO.provisionNicUuid and the
fkBareMetal2BondingNicRefVOProvisionNicVO constraint).
♻️ Duplicate comments (1)
conf/db/upgrade/V5.5.6__schema.sql (1)

19-53: 升级脚本仍缺少过程创建与外键删除的幂等保护
二次执行时可能因已存在的存储过程或外键而失败。建议在创建前先 DROP PROCEDURE IF EXISTS,并在 DROP FOREIGN KEY 前做存在性检查。

🛠️ 建议修改
 DELIMITER $$
+DROP PROCEDURE IF EXISTS UpdateBareMetal2InstanceProvisionNicVO$$
 CREATE PROCEDURE UpdateBareMetal2InstanceProvisionNicVO()
 BEGIN
     DECLARE instanceUuid_exists INT;
+    DECLARE fk_bm2_provisionnic_instancevo_exists INT;
     DECLARE isPrimaryProvisionNic_exists_in_ProvisionNicVO INT;
     DECLARE isPrimaryProvisionNic_exists_in_ChassisNicVO INT;
@@
-        ALTER TABLE `zstack`.`BareMetal2InstanceProvisionNicVO`
-        DROP FOREIGN KEY `fkBareMetal2InstanceProvisionNicVOInstanceVO`;
+        SELECT COUNT(*)
+            INTO fk_bm2_provisionnic_instancevo_exists
+            FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
+            WHERE TABLE_SCHEMA = 'zstack'
+              AND TABLE_NAME = 'BareMetal2InstanceProvisionNicVO'
+              AND CONSTRAINT_NAME = 'fkBareMetal2InstanceProvisionNicVOInstanceVO'
+              AND CONSTRAINT_TYPE = 'FOREIGN KEY';
+
+        IF fk_bm2_provisionnic_instancevo_exists > 0 THEN
+            ALTER TABLE `zstack`.`BareMetal2InstanceProvisionNicVO`
+            DROP FOREIGN KEY `fkBareMetal2InstanceProvisionNicVOInstanceVO`;
+        END IF;

Comment on lines +54 to +56
UPDATE `zstack`.`BareMetal2InstanceProvisionNicVO`
SET `uuid` = REPLACE(UUID(), '-', '');
END IF;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Search for references to BareMetal2InstanceProvisionNicVO in SQL files
rg -n "BareMetal2InstanceProvisionNicVO" -g '*.sql' conf/db

Repository: MatheMatrix/zstack

Length of output: 2303


🏁 Script executed:

# Search for foreign key references to this table
rg -n "REFERENCES\s+\`?BareMetal2InstanceProvisionNicVO\`?" -g '*.sql' conf/db

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Also search in Java files for references to this VO class
rg -n "BareMetal2InstanceProvisionNicVO" -g '*.java' --type java

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Check the full context of the V5.5.6__schema.sql file to understand the migration purpose
cat -n conf/db/upgrade/V5.5.6__schema.sql | head -80

Repository: MatheMatrix/zstack

Length of output: 3833


🏁 Script executed:

# Search for handling of BareMetal2BondingNicRefVO in the migration script
rg -n "BareMetal2BondingNicRefVO" conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Check if there's any CASCADE DELETE or UPDATE handling in the script
rg -n "CASCADE|UPDATE.*provisionNicUuid" conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 160


🏁 Script executed:

# Get the full migration script to see all procedures and logic
wc -l conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 99


🏁 Script executed:

# Get the complete migration script to see all content
cat -n conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 4205


🏁 Script executed:

# Check what the original FK constraint definition looks like
rg -B2 -A2 "fkBareMetal2BondingNicRefVOProvisionNicVO" conf/db/upgrade/V4.7.13__schema.sql

Repository: MatheMatrix/zstack

Length of output: 418


🏁 Script executed:

# Check if BareMetal2BondingNicRefVO.fkBareMetal2BondingNicRefVOProvisionNicVO is modified or dropped before/after the uuid update
rg -B5 -A5 "BareMetal2BondingNicRefVO" conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Check the full definition of ADD_CONSTRAINT to understand what CASCADE means
rg -B3 -A10 "PROCEDURE ADD_CONSTRAINT" conf/db/

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Check if there's any logic in beforeMigrate or related files that might handle cascade updates
find conf/db/upgrade -name "*.sql" | head -20

Repository: MatheMatrix/zstack

Length of output: 737


🏁 Script executed:

# Search for any UPDATE statements that might update provisionNicUuid
rg -n "provisionNicUuid" conf/db/upgrade/

Repository: MatheMatrix/zstack

Length of output: 399


🏁 Script executed:

# Check the detailed FK constraint configuration in the database schema files
rg -B2 -A2 "ON DELETE CASCADE|ON UPDATE CASCADE" conf/db/upgrade/V4.7.13__schema.sql

Repository: MatheMatrix/zstack

Length of output: 519


🏁 Script executed:

# Search for any Java code that references BareMetal2BondingNicRefVO to understand business logic
find . -name "*.java" -type f | xargs grep -l "BareMetal2BondingNicRefVO" 2>/dev/null | head -5

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Check if the ADD_CONSTRAINT procedure call shows ON UPDATE CASCADE or ON UPDATE RESTRICT
rg -B5 -A5 "fkBareMetal2BondingNicRefVOProvisionNicVO" conf/db/upgrade/V4.7.13__schema.sql

Repository: MatheMatrix/zstack

Length of output: 593


🏁 Script executed:

# Check procedure definition for ADD_CONSTRAINT to see default behavior
find conf/db -name "*.sql" | xargs grep -l "PROCEDURE ADD_CONSTRAINT" 2>/dev/null

Repository: MatheMatrix/zstack

Length of output: 46


🏁 Script executed:

# Check if there's a beforeMigrate.sql or similar that might have the ADD_CONSTRAINT procedure definition
find conf/db -name "beforeMigrate.sql" -o -name "*.sql" | xargs grep -l "PROCEDURE ADD_CONSTRAINT" 2>/dev/null | head -3

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Look for the ADD_CONSTRAINT procedure definition more carefully
find conf -name "*.sql" -type f -exec grep -l "CREATE PROCEDURE ADD_CONSTRAINT" {} \;

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Check if there are any statements that drop or disable constraints before the uuid update in V5.5.6
sed -n '40,60p' conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 929


🏁 Script executed:

# Check if there's any migration that explicitly updates BareMetal2BondingNicRefVO.provisionNicUuid after V4.7.13
rg -A10 "UpdateBareMetal2InstanceProvisionNicVO" conf/db/upgrade/V5.5.6__schema.sql | head -50

Repository: MatheMatrix/zstack

Length of output: 582


🏁 Script executed:

# Search for any Java migration or liquibase handlers that might update BareMetal2BondingNicRefVO
find . -name "*.java" -type f | xargs grep -l "BareMetal2BondingNicRefVO\|BareMetal2InstanceProvisionNicVO" 2>/dev/null | grep -i migrat | head -5

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Double-check if BareMetal2BondingNicRefVO exists and has data
rg -n "BareMetal2BondingNicRefVO" conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Check the ADD_CONSTRAINT procedure to understand what 'CASCADE' parameter means
find conf/db -name "*.sql" -type f | xargs grep -B5 -A15 "procedure.*ADD_CONSTRAINT" -i 2>/dev/null | head -60

Repository: MatheMatrix/zstack

Length of output: 1630


🏁 Script executed:

# Look for beforeMigrate.sql which likely has the procedure definitions
cat conf/db/upgrade/beforeMigrate.sql 2>/dev/null | grep -A20 "ADD_CONSTRAINT"

Repository: MatheMatrix/zstack

Length of output: 1067


🏁 Script executed:

# Check if the migration has disabled foreign key checks
grep -n "FOREIGN_KEY_CHECKS\|DISABLE\|ENABLE" conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Get the complete beforeMigrate.sql to check if it disables foreign key checks
cat conf/db/upgrade/beforeMigrate.sql | grep -i "FOREIGN_KEY_CHECKS\|SET SESSION"

Repository: MatheMatrix/zstack

Length of output: 89


🏁 Script executed:

# Look for any migration script wrapper or main migration runner that might disable FK checks
find conf/db -name "*.sql" -type f | xargs grep -l "FOREIGN_KEY_CHECKS" 2>/dev/null

Repository: MatheMatrix/zstack

Length of output: 557


🏁 Script executed:

# Check if there's a CREATE TABLE or ALTER TABLE for BareMetal2BondingNicRefVO that might indicate if this table has data
rg -B2 -A10 "CREATE TABLE.*BareMetal2BondingNicRefVO" conf/db/upgrade/

Repository: MatheMatrix/zstack

Length of output: 1073


🏁 Script executed:

# Check if there's logic to update BareMetal2BondingNicRefVO.provisionNicUuid somewhere
# Search in the procedure for any UPDATE that handles the cascading change
sed -n '21,90p' conf/db/upgrade/V5.5.6__schema.sql | grep -i "UPDATE\|provisionNicUuid"

Repository: MatheMatrix/zstack

Length of output: 444


🏁 Script executed:

# Check the structure of BareMetal2BondingNicRefVO to see if it will have data
cat conf/db/upgrade/V4.4.24__schema.sql | grep -A20 "CREATE TABLE.*BareMetal2BondingNicRefVO"

Repository: MatheMatrix/zstack

Length of output: 1325


🏁 Script executed:

# Check if there's any post-migration script or idempotent check that fixes referential integrity
find conf/db -name "*.sql" | xargs grep -l "provisionNicUuid\|BareMetal2BondingNicRefVO" | xargs grep -l "UPDATE" | head -5

Repository: MatheMatrix/zstack

Length of output: 133


🏁 Script executed:

# Verify the exact FK constraint definition created in V4.7.13 to see if it has ON UPDATE CASCADE
cat conf/db/upgrade/V4.7.13__schema.sql | grep -B5 -A5 "fkBareMetal2BondingNicRefVOProvisionNicVO"

Repository: MatheMatrix/zstack

Length of output: 593


🏁 Script executed:

# Check if the migration re-enables FOREIGN_KEY_CHECKS after the procedure
tail -20 conf/db/upgrade/beforeMigrate.sql

Repository: MatheMatrix/zstack

Length of output: 602


🏁 Script executed:

# Check the exact FK constraint that was created - does it have ON UPDATE CASCADE?
# Let's see what the ADD_CONSTRAINT procedure actually creates in SQL
cat conf/db/upgrade/beforeMigrate.sql | sed -n '/CREATE PROCEDURE.*ADD_CONSTRAINT/,/END\$\$/p' | head -30

Repository: MatheMatrix/zstack

Length of output: 1088


🏁 Script executed:

# Verify if there's any UPDATE statement that handles the propagation to BareMetal2BondingNicRefVO
grep -n "provisionNicUuid\|UPDATE.*BareMetal2BondingNicRefVO" conf/db/upgrade/V5.5.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Check what happens after the procedure - is there any update to BareMetal2BondingNicRefVO?
cat conf/db/upgrade/V5.5.6__schema.sql | tail -20

Repository: MatheMatrix/zstack

Length of output: 753


🏁 Script executed:

# Check if afterMigrate.sql re-enables FOREIGN_KEY_CHECKS and if there's any cleanup
cat conf/db/upgrade/afterMigrate.sql 2>/dev/null | head -20

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Verify: does the ADD_CONSTRAINT with 'CASCADE' parameter only handle ON DELETE or also ON UPDATE?
# The procedure we saw only uses ON DELETE, so CASCADE means ON DELETE CASCADE, not ON UPDATE CASCADE
# Let's confirm by checking the exact SQL it generates
grep -A5 "ON DELETE" conf/db/upgrade/beforeMigrate.sql | head -10

Repository: MatheMatrix/zstack

Length of output: 277


🏁 Script executed:

# Let's create a summary by checking: does the migration explicitly handle the cascade update?
# Check the entire V5.5.6 migration to see if there's any update to BareMetal2BondingNicRefVO
cat conf/db/upgrade/V5.5.6__schema.sql | grep -i "BareMetal2Bonding"

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Verify the FK constraint definition one more time - confirm it's only ON DELETE CASCADE
cat conf/db/upgrade/V4.7.13__schema.sql | tail -10

Repository: MatheMatrix/zstack

Length of output: 715


🏁 Script executed:

# Check if afterMigrate.sql re-enables FOREIGN_KEY_CHECKS
cat conf/db/upgrade/afterMigrate.sql 2>/dev/null

Repository: MatheMatrix/zstack

Length of output: 44


在 UUID 全量更新前,必须同步更新 BareMetal2BondingNicRefVO.provisionNicUuid

BareMetal2InstanceProvisionNicVO.uuid 被外表 BareMetal2BondingNicRefVO 的外键约束 fkBareMetal2BondingNicRefVOProvisionNicVO 引用。当直接更新 uuid 为新值时,该外键约束(ON DELETE CASCADE,不包含 ON UPDATE CASCADE)不会自动更新关联的 provisionNicUuid,导致 FK 完整性失效。

需要在 UPDATE uuid 语句(第 54-55 行)之前或之后,显式添加逻辑更新 BareMetal2BondingNicRefVO.provisionNicUuid 中的对应值,以维持引用一致性。例如:

UPDATE `zstack`.`BareMetal2BondingNicRefVO` as ref
INNER JOIN `zstack`.`BareMetal2InstanceProvisionNicVO` as prov
SET ref.provisionNicUuid = prov.uuid
WHERE ref.provisionNicUuid = prov.<old_uuid_value>
🤖 Prompt for AI Agents
In `@conf/db/upgrade/V5.5.6__schema.sql` around lines 54 - 56, Before changing
BareMetal2InstanceProvisionNicVO.uuid, update the referencing column
BareMetal2BondingNicRefVO.provisionNicUuid to the new UUIDs to preserve FK
consistency: for each row being modified in BareMetal2InstanceProvisionNicVO
(uuid), perform an UPDATE of BareMetal2BondingNicRefVO using an INNER JOIN to
match the old uuid and set provisionNicUuid to the new generated uuid; do this
inside the same transaction and alongside the UPDATE of
BareMetal2InstanceProvisionNicVO.uuid to ensure atomicity and avoid FK breakage
(refer to BareMetal2InstanceProvisionNicVO.uuid,
BareMetal2BondingNicRefVO.provisionNicUuid and the
fkBareMetal2BondingNicRefVOProvisionNicVO constraint).

@ZStack-Robot ZStack-Robot deleted the sync/jin.shen/feature-81282@@3 branch January 25, 2026 08:02
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