mirror of https://github.com/apache/cloudstack.git
bug 9483: delete records from template_spool_ref if corresponding storage pool doesn't exist any more
status 9483: resolved fixed
This commit is contained in:
parent
a32e9027eb
commit
a43a7993cb
|
|
@ -1078,6 +1078,9 @@ public class Upgrade218to22 implements DbUpgrade {
|
|||
// Update user statistics
|
||||
upadteUserStats(conn);
|
||||
|
||||
// delete orphaned (storage pool no longer exists) template_spool_ref(s)
|
||||
deleteOrphanedTemplateRef(conn);
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Can't update data center ", e);
|
||||
}
|
||||
|
|
@ -1300,7 +1303,8 @@ public class Upgrade218to22 implements DbUpgrade {
|
|||
rs = pstmt.executeQuery();
|
||||
|
||||
if (!rs.next()) {
|
||||
throw new CloudRuntimeException("Unable to find public IP address " + publicIp);
|
||||
s_logger.warn("Unable to find public IP address " + publicIp + "; skipping lb rule id=" + originalLbId + " from update");
|
||||
continue;
|
||||
}
|
||||
|
||||
int ipAddressId = rs.getInt(1);
|
||||
|
|
@ -1749,4 +1753,39 @@ public class Upgrade218to22 implements DbUpgrade {
|
|||
public boolean supportsRollingUpgrade() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void deleteOrphanedTemplateRef(Connection conn) {
|
||||
try {
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT id, pool_id from template_spool_ref");
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (!rs.next()) {
|
||||
s_logger.debug("No records in template_spool_ref, skipping this upgrade part");
|
||||
return;
|
||||
}
|
||||
|
||||
while (rs.next()) {
|
||||
Long id = rs.getLong(1);
|
||||
Long poolId = rs.getLong(2);
|
||||
|
||||
pstmt = conn.prepareStatement("SELECT * from storage_pool where id=?");
|
||||
pstmt.setLong(1, poolId);
|
||||
ResultSet rs1 = pstmt.executeQuery();
|
||||
|
||||
if (!rs1.next()) {
|
||||
s_logger.debug("Orphaned template_spool_ref record is found (storage pool doesn't exist any more0) id=" + id + "; so removing the record");
|
||||
pstmt = conn.prepareStatement("DELETE FROM template_spool_ref where id=?");
|
||||
pstmt.setLong(1, id);
|
||||
pstmt.executeUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
s_logger.debug("Finished deleting orphaned template_spool_ref(s)");
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Failed to delete orphaned template_spool_ref(s): ", e);
|
||||
throw new CloudRuntimeException("Failed to delete orphaned template_spool_ref(s): ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,3 +117,5 @@ ALTER TABLE `cloud`.`user_ip_address` ADD CONSTRAINT `fk_user_ip_address__networ
|
|||
ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__account_id` FOREIGN KEY `fk_vm_instance__account_id` (`account_id`) REFERENCES `account` (`id`);
|
||||
ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__service_offering_id` FOREIGN KEY `fk_vm_instance__service_offering_id` (`service_offering_id`) REFERENCES `service_offering` (`id`);
|
||||
|
||||
ALTER TABLE `cloud`.`template_spool_ref` ADD CONSTRAINT `fk_template_spool_ref__pool_id` FOREIGN KEY (`pool_id`) REFERENCES `storage_pool`(`id`) ON DELETE CASCADE;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ ALTER TABLE `cloud`.`cluster` ADD COLUMN `cluster_type` varchar(64) DEFAULT 'Clo
|
|||
ALTER TABLE `cloud`.`vm_template` ADD COLUMN `hypervisor_type` varchar(32) COMMENT 'hypervisor that the template is belonged to';
|
||||
ALTER TABLE `cloud`.`vm_template` ADD COLUMN `extractable` int(1) unsigned NOT NULL default 0 COMMENT 'Is this template extractable';
|
||||
ALTER TABLE `cloud`.`template_spool_ref` ADD CONSTRAINT `fk_template_spool_ref__template_id` FOREIGN KEY (`template_id`) REFERENCES `vm_template`(`id`);
|
||||
ALTER TABLE `cloud`.`template_spool_ref` ADD CONSTRAINT `fk_template_spool_ref__pool_id` FOREIGN KEY (`pool_id`) REFERENCES `storage_pool`(`id`) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE `cloud`.`guest_os` modify `name` varchar(255) ;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue