Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1F43310655 for ; Tue, 3 Jun 2014 15:20:49 +0000 (UTC) Received: (qmail 59272 invoked by uid 500); 3 Jun 2014 15:20:49 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 59240 invoked by uid 500); 3 Jun 2014 15:20:49 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 59229 invoked by uid 99); 3 Jun 2014 15:20:49 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jun 2014 15:20:49 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BBA4894243E; Tue, 3 Jun 2014 15:20:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hugo@apache.org To: commits@cloudstack.apache.org Date: Tue, 03 Jun 2014 15:20:48 -0000 Message-Id: <64bff4946f8d436dae350fa23d632a81@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: updated refs/heads/master to 703febc Repository: cloudstack Updated Branches: refs/heads/master a59db987f -> 703febc64 Fix CID-1212194 Resource like dues to left-open statements and resultsets Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d21a15be Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d21a15be Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d21a15be Branch: refs/heads/master Commit: d21a15beb264e6628773902b3f664e3710385e06 Parents: a59db98 Author: Hugo Trippaers Authored: Tue Jun 3 16:52:58 2014 +0200 Committer: Hugo Trippaers Committed: Tue Jun 3 16:52:58 2014 +0200 ---------------------------------------------------------------------- .../com/cloud/upgrade/dao/Upgrade420to421.java | 65 ++++++++++++++------ 1 file changed, 45 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d21a15be/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 a0093f8..2f0ae29 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java @@ -23,9 +23,9 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import com.cloud.hypervisor.Hypervisor; import org.apache.log4j.Logger; +import com.cloud.hypervisor.Hypervisor; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; @@ -86,12 +86,17 @@ public class Upgrade420to421 implements DbUpgrade { if(result1.next()){ cpuoverprov = result1.getString(1); } + result1.close(); + pstmt1.close(); + pstmt1 = conn.prepareStatement("select value from `cloud`.`configuration` where name='mem.overprovisioning.factor'"); result1 = pstmt1.executeQuery(); String memoverprov = "1"; if(result1.next()){ memoverprov = result1.getString(1); } + result1.close(); + pstmt1.close(); // Need to populate only when overprovisioning factor doesn't pre exist. s_logger.debug("Starting updating user_vm_details with cpu/memory overprovisioning factors"); @@ -135,17 +140,29 @@ public class Upgrade420to421 implements DbUpgrade { if (pstmt1 != null && !pstmt1.isClosed()) { pstmt1.close(); } + } catch (SQLException e) { + } + try { if (pstmt2 != null && !pstmt2.isClosed()) { pstmt2.close(); } + } catch (SQLException e) { + } + try { if (pstmt3 != null && !pstmt3.isClosed()) { pstmt3.close(); } + } catch (SQLException e) { + } + try { if (result1 != null) { result1.close(); } + } catch (SQLException e) { + } + try { if (result2 != null) { - result2.close(); + result2.close(); } }catch (SQLException e){ @@ -161,7 +178,6 @@ public class Upgrade420to421 implements DbUpgrade { PreparedStatement pstmt3 = null; PreparedStatement pstmt4 = null; PreparedStatement pstmt5 = null; - ResultSet rs = null; ResultSet rsAccount = null; ResultSet rsCount = null; try { @@ -172,9 +188,9 @@ public class Upgrade420to421 implements DbUpgrade { long domain_id = rsAccount.getLong(2); // 1. update cpu,memory for all accounts pstmt2 = - conn.prepareStatement("SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)" + " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" - + " WHERE vm_instance.service_offering_id = service_offering.id AND vm_instance.account_id = ?" + " AND vm_instance.removed is NULL" - + " AND vm_instance.vm_type='User' AND state not in ('Destroyed', 'Error', 'Expunging')"); + conn.prepareStatement("SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)" + " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" + + " WHERE vm_instance.service_offering_id = service_offering.id AND vm_instance.account_id = ?" + " AND vm_instance.removed is NULL" + + " AND vm_instance.vm_type='User' AND state not in ('Destroyed', 'Error', 'Expunging')"); pstmt2.setLong(1, account_id); rsCount = pstmt2.executeQuery(); if (rsCount.next()) { @@ -184,11 +200,13 @@ public class Upgrade420to421 implements DbUpgrade { upgradeResourceCountforAccount(conn, account_id, domain_id, "cpu", 0L); upgradeResourceCountforAccount(conn, account_id, domain_id, "memory", 0L); } + rsCount.close(); + // 2. update primary_storage for all accounts pstmt3 = - conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE account_id= ?" - + " AND (path is not NULL OR state in ('Allocated')) AND removed is NULL" - + " AND instance_id IN (SELECT id FROM `cloud`.`vm_instance` WHERE vm_type='User')"); + conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE account_id= ?" + + " AND (path is not NULL OR state in ('Allocated')) AND removed is NULL" + + " AND instance_id IN (SELECT id FROM `cloud`.`vm_instance` WHERE vm_type='User')"); pstmt3.setLong(1, account_id); rsCount = pstmt3.executeQuery(); if (rsCount.next()) { @@ -196,27 +214,35 @@ public class Upgrade420to421 implements DbUpgrade { } else { upgradeResourceCountforAccount(conn, account_id, domain_id, "primary_storage", 0L); } + rsCount.close(); + // 3. update secondary_storage for all accounts long totalVolumesSize = 0; long totalSnapshotsSize = 0; long totalTemplatesSize = 0; pstmt4 = - conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE account_id= ?" - + " AND path is NULL AND state not in ('Allocated') AND removed is NULL"); + conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE account_id= ?" + + " AND path is NULL AND state not in ('Allocated') AND removed is NULL"); pstmt4.setLong(1, account_id); rsCount = pstmt4.executeQuery(); if (rsCount.next()) { totalVolumesSize = rsCount.getLong(1); } + rsCount.close(); + pstmt4.close(); + pstmt4 = conn.prepareStatement("SELECT sum(size) FROM `cloud`.`snapshots` WHERE account_id= ? AND removed is NULL"); pstmt4.setLong(1, account_id); rsCount = pstmt4.executeQuery(); if (rsCount.next()) { totalSnapshotsSize = rsCount.getLong(1); } + rsCount.close(); + pstmt4.close(); + pstmt4 = - conn.prepareStatement("SELECT sum(template_store_ref.size) FROM `cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?" - + " AND template_store_ref.template_id = vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND removed is NULL"); + conn.prepareStatement("SELECT sum(template_store_ref.size) FROM `cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?" + + " AND template_store_ref.template_id = vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND removed is NULL"); pstmt4.setLong(1, account_id); rsCount = pstmt4.executeQuery(); if (rsCount.next()) { @@ -224,6 +250,8 @@ public class Upgrade420to421 implements DbUpgrade { } upgradeResourceCountforAccount(conn, account_id, domain_id, "secondary_storage", totalVolumesSize + totalSnapshotsSize + totalTemplatesSize); } + rsAccount.close(); + // 4. upgrade cpu,memory,primary_storage,secondary_storage for domains String resource_types[] = {"cpu", "memory", "primary_storage", "secondary_storage"}; pstmt5 = conn.prepareStatement("select id FROM `cloud`.`domain`"); @@ -238,8 +266,8 @@ public class Upgrade420to421 implements DbUpgrade { for (int count = 0; count < resource_types.length; count++) { String resource_type = resource_types[count]; pstmt5 = - conn.prepareStatement("select account.domain_id,sum(resource_count.count) from `cloud`.`account` left join `cloud`.`resource_count` on account.id=resource_count.account_id " - + "where resource_count.type=? group by account.domain_id;"); + conn.prepareStatement("select account.domain_id,sum(resource_count.count) from `cloud`.`account` left join `cloud`.`resource_count` on account.id=resource_count.account_id " + + "where resource_count.type=? group by account.domain_id;"); pstmt5.setString(1, resource_type); rsCount = pstmt5.executeQuery(); while (rsCount.next()) { @@ -253,9 +281,6 @@ public class Upgrade420to421 implements DbUpgrade { throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage) ", e); } finally { try { - if (rs != null) { - rs.close(); - } if (rsAccount != null) { rsAccount.close(); } @@ -286,7 +311,7 @@ public class Upgrade420to421 implements DbUpgrade { //update or insert into resource_count table. PreparedStatement pstmt = null; pstmt = - conn.prepareStatement("INSERT INTO `cloud`.`resource_count` (account_id, type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), count=?"); + conn.prepareStatement("INSERT INTO `cloud`.`resource_count` (account_id, type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), count=?"); pstmt.setLong(1, accountId); pstmt.setString(2, type); pstmt.setLong(3, resourceCount); @@ -299,7 +324,7 @@ public class Upgrade420to421 implements DbUpgrade { //update or insert into resource_count table. PreparedStatement pstmt = null; pstmt = - conn.prepareStatement("INSERT INTO `cloud`.`resource_count` (domain_id, type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), count=?"); + conn.prepareStatement("INSERT INTO `cloud`.`resource_count` (domain_id, type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), count=?"); pstmt.setLong(1, domainId); pstmt.setString(2, type); pstmt.setLong(3, resourceCount);