bug 9734: update op_ha_work table in mysql file instead of java code

status 9734: resolved fixed
This commit is contained in:
alena 2011-05-04 15:34:50 -07:00
parent 3732f9db12
commit 40bd77525f
3 changed files with 4 additions and 39 deletions

View File

@ -2090,8 +2090,6 @@ public class Upgrade218to22 implements DbUpgrade {
// left around)
cleanupLbVmMaps(conn);
//cleanup all records from op_ha_work table
cleanupOpHaWork(conn);
} catch (SQLException e) {
s_logger.error("Can't perform data migration ", e);
throw new CloudRuntimeException("Can't perform data migration ", e);
@ -2401,40 +2399,4 @@ public class Upgrade218to22 implements DbUpgrade {
}
}
// Delete records from op_ha_work table
private void cleanupOpHaWork(Connection conn){
try {
//delete taken ha records
PreparedStatement pstmt = conn.prepareStatement("DELETE from op_ha_work WHERE taken IS NOT NULL");
pstmt.executeUpdate();
pstmt.close();
//delete records associated with removed hosts
pstmt = conn.prepareStatement("SELECT DISTINCT host_id from op_ha_work");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Long hostId = rs.getLong(1);
pstmt = conn.prepareStatement("SELECT * from host where id=?");
pstmt.setLong(1, hostId);
ResultSet hostSet = pstmt.executeQuery();
if (!hostSet.next()) {
pstmt = conn.prepareStatement("DELETE from op_ha_work where host_id=?");
pstmt.setLong(1, hostId);
pstmt.executeUpdate();
s_logger.debug("Removed records from op_ha_work having hostId=" + hostId + " as the host no longer exists");
}
hostSet.close();
}
rs.close();
pstmt.close();
s_logger.debug("Completed cleaning up op_ha_work table");
} catch (SQLException e) {
throw new CloudRuntimeException("Failed to cleanup op_ha_work table due to:", e);
}
}
}

View File

@ -115,3 +115,7 @@ ALTER TABLE `cloud`.`volumes` MODIFY COLUMN `state` VARCHAR(32) NOT NULL;
ALTER TABLE `cloud`.`snapshot_policy` ADD KEY `volume_id` (`volume_id`);
DELETE FROM op_ha_work WHERE taken IS NOT NULL;
DELETE FROM op_ha_work WHERE host_id NOT IN (SELECT DISTINCT id FROM host);
ALTER TABLE `cloud`.`op_ha_work` ADD CONSTRAINT `fk_op_ha_work__host_id` FOREIGN KEY `fk_op_ha_work__host_id` (`host_id`) REFERENCES `host` (`id`);

View File

@ -981,7 +981,6 @@ ALTER TABLE `cloud`.`user_statistics` ADD UNIQUE KEY `account_id` (`account_id`,
ALTER TABLE `cloud`.`data_center` MODIFY COLUMN `guest_network_cidr` varchar(18);
ALTER TABLE `cloud`.`op_ha_work` ADD CONSTRAINT `fk_op_ha_work__instance_id` FOREIGN KEY `fk_op_ha_work__instance_id` (`instance_id`) REFERENCES `vm_instance` (`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`op_ha_work` ADD CONSTRAINT `fk_op_ha_work__host_id` FOREIGN KEY `fk_op_ha_work__host_id` (`host_id`) REFERENCES `host` (`id`);
ALTER TABLE `cloud`.`op_ha_work` ADD CONSTRAINT `fk_op_ha_work__mgmt_server_id` FOREIGN KEY `fk_op_ha_work__mgmt_server_id`(`mgmt_server_id`) REFERENCES `mshost`(`msid`);
ALTER TABLE `cloud`.`secondary_storage_vm` ADD CONSTRAINT `fk_secondary_storage_vm__id` FOREIGN KEY `fk_secondary_storage_vm__id`(`id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE;