mirror of https://github.com/apache/cloudstack.git
bug 9658: added missing indexes to 2.1.x-2.2.x upgrade files
status 9658: resolved fixed
This commit is contained in:
parent
36e4c8625e
commit
d8a4a5be52
|
|
@ -24,6 +24,7 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ public class Upgrade222to224 implements DbUpgrade {
|
|||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
try {
|
||||
checkForDuplicatePublicNetworks(conn);
|
||||
checkForDuplicatePublicNetworks(conn);
|
||||
fixRelatedFkeyOnNetworksTable(conn);
|
||||
updateClusterIdInOpHostCapacity(conn);
|
||||
updateGuestOsType(conn);
|
||||
|
|
@ -87,10 +88,11 @@ public class Upgrade222to224 implements DbUpgrade {
|
|||
updateTotalCPUInOpHostCapacity(conn);
|
||||
upgradeGuestOs(conn);
|
||||
fixRecreatableVolumesProblem(conn);
|
||||
updateFkeysAndIndexes(conn);
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to perform data migration", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getCleanupScripts() {
|
||||
|
|
@ -101,38 +103,38 @@ public class Upgrade222to224 implements DbUpgrade {
|
|||
|
||||
return new File[] { new File(file) };
|
||||
}
|
||||
|
||||
|
||||
private void checkForDuplicatePublicNetworks(Connection conn) {
|
||||
try {
|
||||
// There should be one public network per zone
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`data_center`");
|
||||
ResultSet zones = pstmt.executeQuery();
|
||||
ArrayList<Long> zonesWithDuplicateNetworks = new ArrayList<Long>();
|
||||
String errorMsg = "Found zones with duplicate public networks during 222 to 224 upgrade. Zone IDs: ";
|
||||
long zoneId;
|
||||
|
||||
while (zones.next()) {
|
||||
zoneId = zones.getLong(1);
|
||||
pstmt = conn.prepareStatement("SELECT count(*) FROM `cloud`.`networks` WHERE `networks`.`traffic_type`='Public' AND `data_center_id`=?");
|
||||
pstmt.setLong(1, zoneId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
long numNetworks = rs.getLong(1);
|
||||
if (numNetworks > 1) {
|
||||
zonesWithDuplicateNetworks.add(zoneId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zonesWithDuplicateNetworks.size() > 0) {
|
||||
s_logger.warn(errorMsg + zonesWithDuplicateNetworks);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
s_logger.warn(e);
|
||||
throw new CloudRuntimeException("Unable to check for duplicate public networks as part of 222 to 224 upgrade.");
|
||||
}
|
||||
try {
|
||||
// There should be one public network per zone
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`data_center`");
|
||||
ResultSet zones = pstmt.executeQuery();
|
||||
ArrayList<Long> zonesWithDuplicateNetworks = new ArrayList<Long>();
|
||||
String errorMsg = "Found zones with duplicate public networks during 222 to 224 upgrade. Zone IDs: ";
|
||||
long zoneId;
|
||||
|
||||
while (zones.next()) {
|
||||
zoneId = zones.getLong(1);
|
||||
pstmt = conn.prepareStatement("SELECT count(*) FROM `cloud`.`networks` WHERE `networks`.`traffic_type`='Public' AND `data_center_id`=?");
|
||||
pstmt.setLong(1, zoneId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
long numNetworks = rs.getLong(1);
|
||||
if (numNetworks > 1) {
|
||||
zonesWithDuplicateNetworks.add(zoneId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zonesWithDuplicateNetworks.size() > 0) {
|
||||
s_logger.warn(errorMsg + zonesWithDuplicateNetworks);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
s_logger.warn(e);
|
||||
throw new CloudRuntimeException("Unable to check for duplicate public networks as part of 222 to 224 upgrade.");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateGuestOsType(Connection conn) {
|
||||
|
|
@ -425,4 +427,77 @@ public class Upgrade222to224 implements DbUpgrade {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateFkeysAndIndexes(Connection conn) throws SQLException {
|
||||
List<String> keysToAdd = new ArrayList<String>();
|
||||
List<String> indexesToAdd = new ArrayList<String>();
|
||||
List<String> keysToDrop = new ArrayList<String>();
|
||||
List<String> indexesToDrop = new ArrayList<String>();
|
||||
|
||||
// populate indexes/keys to drop
|
||||
keysToDrop.add("ALTER TABLE `cloud`.`data_center` DROP FOREIGN KEY `fk_data_center__domain_id`");
|
||||
indexesToDrop.add("ALTER TABLE `cloud`.`data_center` DROP KEY `i_data_center__domain_id`");
|
||||
|
||||
keysToDrop.add("ALTER TABLE `cloud`.`vlan` DROP FOREIGN KEY `fk_vlan__data_center_id`");
|
||||
keysToDrop.add("ALTER TABLE `cloud`.`op_dc_ip_address_alloc` DROP FOREIGN KEY `fk_op_dc_ip_address_alloc__data_center_id`");
|
||||
|
||||
indexesToDrop.add("ALTER TABLE `cloud`.`networks` DROP FOREIGN KEY `fk_networks__network_offering_id`");
|
||||
indexesToDrop.add("ALTER TABLE `cloud`.`networks` DROP FOREIGN KEY `fk_networks__data_center_id`");
|
||||
indexesToDrop.add("ALTER TABLE `cloud`.`networks` DROP FOREIGN KEY `fk_networks__account_id`");
|
||||
indexesToDrop.add("ALTER TABLE `cloud`.`networks` DROP FOREIGN KEY `fk_networks__domain_id`");
|
||||
keysToDrop.add("ALTER TABLE `cloud`.`networks` DROP KEY `i_networks__removed`");
|
||||
|
||||
// populate indexes/keys to add
|
||||
keysToAdd.add("ALTER TABLE `cloud`.`data_center` ADD CONSTRAINT `fk_data_center__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`)");
|
||||
indexesToAdd.add("ALTER TABLE `cloud`.`data_center` ADD INDEX `i_data_center__domain_id`(`domain_id`)");
|
||||
|
||||
keysToAdd.add("ALTER TABLE `cloud`.`vlan` ADD CONSTRAINT `fk_vlan__data_center_id` FOREIGN KEY `fk_vlan__data_center_id`(`data_center_id`) REFERENCES `data_center`(`id`)");
|
||||
keysToAdd
|
||||
.add("ALTER TABLE `cloud`.`op_dc_ip_address_alloc` ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE");
|
||||
|
||||
keysToAdd.add("ALTER TABLE `cloud`.`networks` ADD INDEX `i_networks__removed` (`removed`)");
|
||||
|
||||
indexesToAdd.add("ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__network_offering_id` FOREIGN KEY (`network_offering_id`) REFERENCES `network_offerings`(`id`)");
|
||||
indexesToAdd.add("ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center` (`id`)");
|
||||
indexesToAdd.add("ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`)");
|
||||
indexesToAdd.add("ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain` (`id`)");
|
||||
|
||||
// drop keys
|
||||
for (String key : keysToDrop) {
|
||||
PreparedStatement pstmt = conn.prepareStatement(key);
|
||||
try {
|
||||
pstmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
s_logger.debug("Ignore if the key is not there.");
|
||||
}
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
// drop indexes
|
||||
for (String index : indexesToDrop) {
|
||||
PreparedStatement pstmt = conn.prepareStatement(index);
|
||||
try {
|
||||
pstmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
s_logger.debug("Ignore if the index is not there.");
|
||||
}
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
// update indexes
|
||||
for (String index : indexesToAdd) {
|
||||
PreparedStatement pstmt = conn.prepareStatement(index);
|
||||
s_logger.debug("Query is " + pstmt);
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
// update keys
|
||||
for (String key : keysToAdd) {
|
||||
PreparedStatement pstmt = conn.prepareStatement(key);
|
||||
s_logger.debug("Query is " + pstmt);
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ CREATE TABLE IF NOT EXISTS `cloud`.`version` (
|
|||
INDEX `i_version__version`(`version`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
ALTER TABLE `cloud`.`mshost` DROP KEY `msid`;
|
||||
ALTER TABLE `cloud`.`mshost` MODIFY COLUMN `msid` bigint unsigned NOT NULL UNiQUE;
|
||||
|
||||
CREATE TABLE `cloud`.`op_it_work` (
|
||||
|
|
@ -430,6 +431,8 @@ ALTER TABLE `cloud`.`security_ingress_rule` ADD CONSTRAINT `fk_security_ingress_
|
|||
ALTER TABLE `cloud`.`security_ingress_rule` ADD INDEX `i_security_ingress_rule_network_id`(`security_group_id`);
|
||||
ALTER TABLE `cloud`.`security_ingress_rule` ADD INDEX `i_security_ingress_rule_allowed_network`(`allowed_network_id`);
|
||||
|
||||
ALTER TABLE `cloud`.`security_group_vm_map` DROP KEY `fk_network_group_vm_map___network_group_id`;
|
||||
ALTER TABLE `cloud`.`security_group_vm_map` DROP KEY `fk_network_group_vm_map___instance_id`;
|
||||
ALTER TABLE `cloud`.`security_group_vm_map` ADD CONSTRAINT `fk_security_group_vm_map___security_group_id` FOREIGN KEY `fk_security_group_vm_map___security_group_id` (`security_group_id`) REFERENCES `security_group` (`id`) ON DELETE CASCADE;
|
||||
ALTER TABLE `cloud`.`security_group_vm_map` ADD CONSTRAINT `fk_security_group_vm_map___instance_id` FOREIGN KEY `fk_security_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE;
|
||||
--n/w to sec grps ends --;
|
||||
|
|
@ -974,3 +977,23 @@ UPDATE vm_instance SET instance_name=concat("r-", concat(cast(id as CHAR), conca
|
|||
UPDATE vm_instance SET instance_name=concat("s-", concat(cast(id as CHAR), concat("-", (SELECT value FROM configuration WHERE name='instance.name')))) WHERE type='SecondaryStorageVm';
|
||||
UPDATE vm_instance SET instance_name=concat("v-", concat(cast(id as CHAR), concat("-", (SELECT value FROM configuration WHERE name='instance.name')))) WHERE type='ConsoleProxy';
|
||||
UPDATE vm_instance SET instance_name=concat("i-", concat(cast(account_id as CHAR), concat("-", concat(cast(id as CHAR), concat("-", (SELECT value FROM configuration WHERE name='instance.name')))))) WHERE type='User';
|
||||
|
||||
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;
|
||||
|
||||
ALTER TABLE `cloud`.`snapshots` MODIFY COLUMN `id` bigint unsigned UNIQUE NOT NULL AUTO_INCREMENT COMMENT 'Primary Key';
|
||||
|
||||
ALTER TABLE `cloud`.`storage_pool` DROP KEY `uuid`;
|
||||
|
||||
ALTER TABLE `cloud`.`template_host_ref` DROP FOREIGN KEY `fk_template_host_ref__template_id`;
|
||||
ALTER TABLE `cloud`.`template_host_ref` ADD CONSTRAINT `fk_template_host_ref__template_id` FOREIGN KEY `fk_template_host_ref__template_id` (`template_id`) REFERENCES `vm_template` (`id`);
|
||||
|
||||
ALTER TABLE `cloud`.`user_ip_address` ADD CONSTRAINT `fk_user_ip_address__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__last_host_id` FOREIGN KEY `fk_vm_instance__last_host_id` (`last_host_id`) REFERENCES `host`(`id`);
|
||||
|
||||
|
|
|
|||
|
|
@ -37,20 +37,3 @@ CREATE TABLE IF NOT EXISTS `cloud`.`version` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
ALTER TABLE `cloud`.`data_center` ADD CONSTRAINT `fk_data_center__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`);
|
||||
ALTER TABLE `cloud`.`data_center` ADD INDEX `i_data_center__domain_id`(`domain_id`);
|
||||
|
||||
ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center` (`id`);
|
||||
ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__related` FOREIGN KEY (`related`) REFERENCES `networks` (`id`) ON DELETE CASCADE;
|
||||
ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`);
|
||||
ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `fk_networks__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain` (`id`);
|
||||
|
||||
ALTER TABLE `cloud`.`networks` ADD INDEX `fk_networks__network_offering_id` (`network_offering_id`);
|
||||
ALTER TABLE `cloud`.`networks` ADD INDEX `fk_networks__data_center_id` (`data_center_id`);
|
||||
ALTER TABLE `cloud`.`networks` ADD INDEX `fk_networks__account_id` (`account_id`);
|
||||
ALTER TABLE `cloud`.`networks` ADD INDEX `fk_networks__domain_id` (`domain_id`);
|
||||
ALTER TABLE `cloud`.`networks` ADD INDEX `i_networks__removed` (`removed`);
|
||||
|
||||
ALTER TABLE `cloud`.`op_dc_ip_address_alloc` ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE `cloud`.`vlan` ADD CONSTRAINT `fk_vlan__data_center_id` FOREIGN KEY `fk_vlan__data_center_id`(`data_center_id`) REFERENCES `data_center`(`id`);
|
||||
|
|
|
|||
|
|
@ -160,3 +160,6 @@ UPDATE `cloud`.`vm_instance` SET ha_enabled=0 WHERE type='ConsoleProxy';
|
|||
|
||||
UPDATE service_offering SET ha_enabled=0 WHERE id=(SELECT id FROM disk_offering WHERE name LIKE '%console proxy%' AND system_use=1);
|
||||
|
||||
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));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue