mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-9466: Fix fk constraint failure in upgrade path
In the 4.1.0-4.2.0 db upgrade path, it creates new tables to store secondary (nfs) storage in image_store table and volumes in volume_store_ref table. In the upgrade path, it first tries to migrate NFS storage pool where it excludes storage pools which have been removed, but it migrates all the volumes without checking if their storage pools have been removed. This causes fk constraint failure as the volume/row being inserted refers to a storage pool which does not exist in the image_store table. The fix migrates all the nfs storage pools to image_store including removed storage pools and in doing so migrates with the 'removed' field. This fixes db upgrade for old pre-4.0 and 4.0/4.1 CloudStack clouds. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
740bd45be6
commit
7530f4b6dd
|
|
@ -1759,9 +1759,9 @@ public class Upgrade410to420 implements DbUpgrade {
|
|||
PreparedStatement pstmtSelectSwiftCount = conn.prepareStatement(sqlSelectSwiftCount);
|
||||
PreparedStatement storeDetailInsert = conn.prepareStatement(sqlInsertStoreDetail);
|
||||
PreparedStatement storeInsert =
|
||||
conn.prepareStatement("INSERT INTO `cloud`.`image_store` (id, uuid, name, image_provider_name, protocol, url, data_center_id, scope, role, parent, total_size, created) values(?, ?, ?, 'NFS', 'nfs', ?, ?, 'ZONE', ?, ?, ?, ?)");
|
||||
conn.prepareStatement("INSERT INTO `cloud`.`image_store` (id, uuid, name, image_provider_name, protocol, url, data_center_id, scope, role, parent, total_size, created, removed) values(?, ?, ?, 'NFS', 'nfs', ?, ?, 'ZONE', ?, ?, ?, ?, ?)");
|
||||
PreparedStatement nfsQuery =
|
||||
conn.prepareStatement("select id, uuid, url, data_center_id, parent, total_size, created from `cloud`.`host` where type = 'SecondaryStorage' and removed is null");
|
||||
conn.prepareStatement("select id, uuid, url, data_center_id, parent, total_size, created, removed from `cloud`.`host` where type = 'SecondaryStorage'");
|
||||
PreparedStatement pstmtUpdateHostAsRemoved = conn.prepareStatement(sqlUpdateHostAsRemoved);
|
||||
ResultSet rsSelectS3Count = pstmtSelectS3Count.executeQuery();
|
||||
ResultSet rsSelectSwiftCount = pstmtSelectSwiftCount.executeQuery();
|
||||
|
|
@ -1796,6 +1796,7 @@ public class Upgrade410to420 implements DbUpgrade {
|
|||
int nfs_dcid = rsNfs.getInt("data_center_id");
|
||||
Long nfs_totalsize = rsNfs.getObject("total_size") != null ? rsNfs.getLong("total_size") : null;
|
||||
Date nfs_created = rsNfs.getDate("created");
|
||||
Date nfs_removed = rsNfs.getDate("removed");
|
||||
|
||||
// insert entry in image_store table and image_store_details
|
||||
// table and store host_id and store_id mapping
|
||||
|
|
@ -1812,6 +1813,7 @@ public class Upgrade410to420 implements DbUpgrade {
|
|||
storeInsert.setNull(8, Types.BIGINT);
|
||||
}
|
||||
storeInsert.setDate(9, nfs_created);
|
||||
storeInsert.setDate(10, nfs_removed);
|
||||
storeInsert.executeUpdate();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue