mirror of https://github.com/apache/cloudstack.git
CS-12510: Deleting the host_details and inserting them back causes deadlocks.
Changes: - 3.0.4 release has a patch where a unique key is added on host_details. - But this key is not present in 3.0.4 GA - So 3.0.5 upgrade has to consider both cases and add the key only if it does not exist in the 3.0.4 version.
This commit is contained in:
parent
b526affe01
commit
102a563cdd
|
|
@ -53,6 +53,7 @@ public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
|
|||
|
||||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
addHostDetailsUniqueKey(conn);
|
||||
addVpcProvider(conn);
|
||||
updateRouterNetworkRef(conn);
|
||||
}
|
||||
|
|
@ -171,4 +172,36 @@ public class Upgrade304to305 extends Upgrade30xBase implements DbUpgrade {
|
|||
}
|
||||
s_logger.debug("Done updating router/network references");
|
||||
}
|
||||
|
||||
private void addHostDetailsUniqueKey(Connection conn) {
|
||||
s_logger.debug("Checking if host_details unique key exists, if not we will add it");
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` WHERE KEY_NAME = 'uk_host_id_name'");
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
s_logger.debug("Unique key already exists on host_details - not adding new one");
|
||||
}else{
|
||||
//add the key
|
||||
PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER TABLE `cloud`.`host_details` ADD CONSTRAINT UNIQUE KEY `uk_host_id_name` (`host_id`, `name`)");
|
||||
pstmtUpdate.executeUpdate();
|
||||
s_logger.debug("Unique key did not exist on host_details - added new one");
|
||||
pstmtUpdate.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Failed to check/update the host_details unique key ", e);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
|
||||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -833,7 +833,7 @@ CREATE TABLE `cloud`.`host_details` (
|
|||
`value` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `fk_host_details__host_id` FOREIGN KEY (`host_id`) REFERENCES `host`(`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT UNIQUE KEY (`host_id`, `name`)
|
||||
CONSTRAINT UNIQUE KEY `uk_host_id_name` (`host_id`, `name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `cloud`.`mshost` (
|
||||
|
|
|
|||
|
|
@ -350,7 +350,5 @@ UPDATE `cloud`.`hypervisor_capabilities` SET `max_data_volumes_limit`=13 WHERE `
|
|||
SET SQL_SAFE_UPDATES=1;
|
||||
UPDATE `cloud`.`configuration` SET description='In second, timeout for creating volume from snapshot' WHERE name='create.volume.from.snapshot.wait';
|
||||
|
||||
ALTER TABLE `cloud`.`host_details` ADD CONSTRAINT UNIQUE KEY (`host_id`, `name`);
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Account Defaults', 'DEFAULT', 'management-server', 'max.account.vpcs', '20', 'The default maximum number of vpcs that can be created for an account');
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.vpcs', '20', 'The default maximum number of vpcs that can be created for a project');
|
||||
|
|
|
|||
Loading…
Reference in New Issue