bug 9688: remove orphaned lb/vm mappings as a part of db upgrade (there was a bug in 2.1.x when the LB rule was removed, but mapping was left in the DB)

status 9688: resolved fixed

To verify that the rule was removed:
* make sure that there is no record with lb id in load_balancer table
* verify that lb.delete event was generated for this rule
This commit is contained in:
alena 2011-05-02 18:52:50 -07:00
parent 824f0586f7
commit 5d332f0f30
3 changed files with 42 additions and 14 deletions

View File

@ -1972,6 +1972,10 @@ public class Upgrade218to22 implements DbUpgrade {
// modify network_group indexes
modifyIndexes(conn);
// cleanup lb - vm maps for load balancers that are already removed (there was a bug in 2.1.x when the mappings were
// left around)
cleanupLbVmMaps(conn);
} catch (SQLException e) {
s_logger.error("Can't perform data migration ", e);
throw new CloudRuntimeException("Can't perform data migration ", e);
@ -2125,4 +2129,41 @@ public class Upgrade218to22 implements DbUpgrade {
throw new CloudRuntimeException("Unable to drop indexes for 'security_group' table due to:", e);
}
}
// There was a bug in 2.1.x when LB rule mapping wasn't removed along with lb rule removal
// Do cleanup after making sure that the rule was removed
private void cleanupLbVmMaps(Connection conn) {
try {
PreparedStatement pstmt = conn.prepareStatement("SELECT DISTINCT load_balancer_id FROM load_balancer_vm_map");
s_logger.debug("query is " + pstmt);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
long lbId = rs.getLong(1);
PreparedStatement pstmt1 = conn.prepareStatement("SELECT * FROM load_balancer where id=?");
pstmt1.setLong(1, lbId);
ResultSet rs1 = pstmt1.executeQuery();
PreparedStatement pstmt2 = conn.prepareStatement("SELECT * from event where type like '%lb.delete%' and parameters like '%id=" + lbId + "%'");
ResultSet rs2 = pstmt2.executeQuery();
if (!rs1.next() && rs2.next()) {
s_logger.debug("Removing load balancer vm mappings for lb id=" + lbId + " as a part of cleanup");
pstmt = conn.prepareStatement("DELETE FROM load_balancer_vm_map where load_balancer_id=?");
pstmt.setLong(1, lbId);
pstmt.executeUpdate();
}
rs1.close();
rs2.close();
pstmt1.close();
pstmt2.close();
}
rs.close();
pstmt.close();
} catch (SQLException e) {
throw new CloudRuntimeException("Failed to cleanup orpahned lb-vm mappings due to:", e);
}
}
}

View File

@ -62,7 +62,6 @@ DROP TABLE IF EXISTS `cloud`.`sync_queue`;
DROP TABLE IF EXISTS `cloud`.`sync_queue_item`;
DROP TABLE IF EXISTS `cloud`.`security_group_vm_map`;
DROP TABLE IF EXISTS `cloud`.`load_balancer_vm_map`;
DROP TABLE IF EXISTS `cloud`.`load_balancer`;
DROP TABLE IF EXISTS `cloud`.`storage_pool`;
DROP TABLE IF EXISTS `cloud`.`storage_pool_host_ref`;
DROP TABLE IF EXISTS `cloud`.`template_spool_ref`;
@ -1132,18 +1131,6 @@ CREATE TABLE `cloud`.`network_rule_config` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`load_balancer` (
`id` bigint unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`description` varchar(4096) NULL,
`account_id` bigint unsigned NOT NULL,
`ip_address` char(40) NOT NULL,
`public_port` varchar(10) NOT NULL,
`private_port` varchar(10) NOT NULL,
`algorithm` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`remote_access_vpn` (
`vpn_server_addr_id` bigint unsigned UNIQUE NOT NULL,
`account_id` bigint unsigned NOT NULL,

View File

@ -32,7 +32,6 @@ ALTER TABLE `cloud`.`domain_router` MODIFY `public_ip_address` char(40);
ALTER TABLE `cloud`.`domain_router` MODIFY `guest_ip_address` char(40);
ALTER TABLE `cloud`.`console_proxy` MODIFY `public_ip_address` char(40) UNIQUE;
ALTER TABLE `cloud`.`secondary_storage_vm` MODIFY `public_ip_address` char(40) UNIQUE;
ALTER TABLE `cloud`.`load_balancer` MODIFY `ip_address` char(40) NOT NULL;
ALTER TABLE `cloud`.`remote_access_vpn` MODIFY `local_ip` char(40) NOT NULL;
ALTER TABLE `cloud`.`storage_pool` MODIFY `host_address` char(40) NOT NULL;
ALTER TABLE `cloud`.`user_ip_address` MODIFY `public_ip_address` char(40) NOT NULL;
@ -164,3 +163,4 @@ UPDATE service_offering SET ha_enabled=0 WHERE id=(SELECT id FROM disk_offering
ALTER TABLE `cloud`.`storage_pool_details` DROP KEY `i_storage_pool_details__name__value`;
ALTER TABLE `cloud`.`storage_pool_details` ADD INDEX `i_storage_pool_details__name__value`(`name`(128), `value`(128));
DROP TABLE `cloud`.`load_balancer`;