From 40bd77525f408cea85fffec036a5a8bf9bca48bf Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 4 May 2011 15:34:50 -0700 Subject: [PATCH] bug 9734: update op_ha_work table in mysql file instead of java code status 9734: resolved fixed --- .../com/cloud/upgrade/dao/Upgrade218to22.java | 38 ------------------- setup/db/db/schema-21to22-cleanup.sql | 4 ++ setup/db/db/schema-21to22.sql | 1 - 3 files changed, 4 insertions(+), 39 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index e6ed9a7446b..133bd647307 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -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); - } - } } diff --git a/setup/db/db/schema-21to22-cleanup.sql b/setup/db/db/schema-21to22-cleanup.sql index 03612136adf..2e35ce46786 100644 --- a/setup/db/db/schema-21to22-cleanup.sql +++ b/setup/db/db/schema-21to22-cleanup.sql @@ -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`); + diff --git a/setup/db/db/schema-21to22.sql b/setup/db/db/schema-21to22.sql index 6be69ed762e..bc1d3551b14 100755 --- a/setup/db/db/schema-21to22.sql +++ b/setup/db/db/schema-21to22.sql @@ -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;