Updated Branches: refs/heads/4.2 648f10401 -> 544d1594f
CLOUDSTACK-5038: used cpu is getting bumped up when the over provisioning factor > 1. This was because we didnt record the overprovisioning factors of the vms which got deployed pre 4.2 Upgrade path will fix that by populating the cpu/mem overprovisioning factors for each of the vms in user_vm_details table using the global overprovisioning factor. Reviewed by : bharat kumar <[email protected]> Signed off by : nitin mehta<[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/544d1594 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/544d1594 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/544d1594 Branch: refs/heads/4.2 Commit: 544d1594f0e65365daa5390688b2e126750ea4f5 Parents: 648f104 Author: Nitin Mehta <[email protected]> Authored: Tue Nov 5 16:35:07 2013 -0800 Committer: Nitin Mehta <[email protected]> Committed: Tue Nov 5 16:35:07 2013 -0800 ---------------------------------------------------------------------- .../com/cloud/upgrade/dao/Upgrade420to421.java | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/544d1594/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java index 27704e8..d37c0a1 100755 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java @@ -65,6 +65,52 @@ public class Upgrade420to421 implements DbUpgrade { @Override public void performDataMigration(Connection conn) { upgradeResourceCount(conn); + updateCpuOverprovisioning(conn); + } + + private void updateCpuOverprovisioning(Connection conn) { + PreparedStatement pstmt1 = null; + PreparedStatement pstmt2 = null; + PreparedStatement pstmt3 = null; + ResultSet result1 = null; + ResultSet result2 = null; + + // Get cpu overprovisioning factor from global setting and update user vm details table for all the vms if factor > 1 + + try { + pstmt1 = conn.prepareStatement("select value from `cloud`.`configuration` where name='cpu.overprovisioning.factor'"); + result1 = pstmt1.executeQuery(); + String overprov = "1"; + if(result1.next()){ + overprov = result1.getString(1); + } + // Need to populate only when overprovisioning factor doesn't pre exist. + s_logger.debug("Starting updating user_vm_details with cpu/memory overprovisioning factors"); + pstmt2 = conn.prepareStatement("select id from `cloud`.`vm_instance` where removed is null and id not in (select vm_id from `cloud`.`user_vm_details` where name='cpuOvercommitRatio')"); + pstmt3 = conn.prepareStatement("INSERT IGNORE INTO cloud.user_vm_details (vm_id, name, value) VALUES (?, ?, ?)"); + result2 = pstmt2.executeQuery(); + while (result2.next()) { + //For cpu + pstmt3.setLong(1, result2.getLong(1)); + pstmt3.setString(2, "cpuOvercommitRatio"); + pstmt3.setString(3, overprov); + pstmt3.executeUpdate(); + + // For memory + pstmt3.setLong(1, result2.getLong(1)); + pstmt3.setString(2, "memoryOvercommitRatio"); + pstmt3.setString(3, "1"); // memory overprovisioning didn't exist earlier. + pstmt3.executeUpdate(); + } + s_logger.debug("Done updating user_vm_details with cpu/memory overprovisioning factors"); + + + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to update cpu/memory overprovisioning factors", e); + } finally { + + } + } private void upgradeResourceCount(Connection conn) {
