From ad112c82540d3f6b85e1328b3bef702ccb220805 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 18 Jul 2013 15:12:40 -0700 Subject: [PATCH] CLOUDSTACK-3612: fixed missing indexes in some cloud tables. In the bug those tables are addressed as table #4, table #5, and table #6 --- .../cloud/upgrade/dao/Upgrade410to420.java | 52 +++++++++++++++++++ setup/db/db/schema-410to420.sql | 4 ++ 2 files changed, 56 insertions(+) diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index f89c86269ee..f3170e2f56e 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -92,6 +92,8 @@ public class Upgrade410to420 implements DbUpgrade { migrateVolumeHostRef(conn); migrateTemplateHostRef(conn); migrateSnapshotStoreRef(conn); + fixNiciraKeys(conn); + fixRouterKeys(conn); } private void fixBaremetalForeignKeys(Connection conn) { @@ -1960,4 +1962,54 @@ public class Upgrade410to420 implements DbUpgrade { } } } + + private void fixNiciraKeys(Connection conn) { + //First drop the key if it exists. + List keys = new ArrayList(); + s_logger.debug("Dropping foreign key fk_nicira_nvp_nic_map__nic from the table nicira_nvp_nic_map if it exists"); + keys.add("fk_nicira_nvp_nic_map__nic"); + DbUpgradeUtils.dropKeysIfExist(conn, "nicira_nvp_nic_map", keys, true); + + //Now add foreign key. + PreparedStatement pstmt = null; + try { + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`nicira_nvp_nic_map` ADD CONSTRAINT `fk_nicira_nvp_nic_map__nic` FOREIGN KEY (`nic`) REFERENCES `nics` (`uuid`) ON DELETE CASCADE"); + pstmt.executeUpdate(); + s_logger.debug("Added foreign key fk_nicira_nvp_nic_map__nic to the table nicira_nvp_nic_map"); + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to add foreign key fk_nicira_nvp_nic_map__nic to the table nicira_nvp_nic_map", e); + } finally { + try { + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } + + private void fixRouterKeys(Connection conn) { + //First drop the key if it exists. + List keys = new ArrayList(); + s_logger.debug("Dropping foreign key fk_router_network_ref__router_id from the table router_network_ref if it exists"); + keys.add("fk_router_network_ref__router_id"); + DbUpgradeUtils.dropKeysIfExist(conn, "router_network_ref", keys, true); + + //Now add foreign key. + PreparedStatement pstmt = null; + try { + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`router_network_ref` ADD CONSTRAINT `fk_router_network_ref__router_id` FOREIGN KEY (`router_id`) REFERENCES `domain_router` (`id`) ON DELETE CASCADE"); + pstmt.executeUpdate(); + s_logger.debug("Added foreign key fk_router_network_ref__router_id to the table router_network_ref"); + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to add foreign key fk_router_network_ref__router_id to the table router_network_ref", e); + } finally { + try { + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } } diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index 705d6301992..4086f2f6326 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -2240,3 +2240,7 @@ CREATE VIEW `cloud`.`project_view` AS and resource_tags.resource_type = 'Project' left join `cloud`.`project_account` pacct ON projects.id = pacct.project_id; + + +ALTER TABLE `cloud`.`sync_queue` MODIFY `queue_size` smallint(6) NOT NULL DEFAULT '0' COMMENT 'number of items being processed by the queue'; +ALTER TABLE `cloud`.`sync_queue` MODIFY `queue_size_limit` smallint(6) NOT NULL DEFAULT '1' COMMENT 'max number of items the queue can process concurrently'; \ No newline at end of file